Better support unhandled exception logging on websocket requests

This commit is contained in:
Chris Eager
2021-07-27 20:12:57 -05:00
committed by Chris Eager
parent f47fefb73e
commit 5400abb065
2 changed files with 108 additions and 26 deletions

View File

@@ -7,9 +7,9 @@ package org.whispersystems.textsecuregcm.util.logging;
import com.google.common.annotations.VisibleForTesting;
import io.dropwizard.jersey.errors.LoggingExceptionMapper;
import javax.servlet.http.HttpServletRequest;
import javax.inject.Provider;
import javax.ws.rs.core.Context;
import org.glassfish.jersey.server.ExtendedUriInfo;
import org.glassfish.jersey.server.ContainerRequest;
import org.slf4j.Logger;
import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException;
import org.whispersystems.textsecuregcm.util.ua.UserAgent;
@@ -18,10 +18,7 @@ import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
public class LoggingUnhandledExceptionMapper extends LoggingExceptionMapper<Throwable> {
@Context
private HttpServletRequest request;
@Context
private ExtendedUriInfo uriInfo;
private Provider<ContainerRequest> request;
public LoggingUnhandledExceptionMapper() {
super();
@@ -38,10 +35,10 @@ public class LoggingUnhandledExceptionMapper extends LoggingExceptionMapper<Thro
String userAgent = "missing";
String requestPath = "/{unknown path}";
try {
// request and uriInfo shouldnt be `null`, but it is technically possible
requestMethod = request.getMethod();
requestPath = UriInfoUtil.getPathTemplate(uriInfo);
userAgent = request.getHeader("user-agent");
// request shouldnt be `null`, but it is technically possible
requestMethod = request.get().getMethod();
requestPath = UriInfoUtil.getPathTemplate(request.get().getUriInfo());
userAgent = request.get().getHeaderString("user-agent");
// streamline the user-agent if it is recognized
final UserAgent ua = UserAgentUtil.parseUserAgentString(userAgent);