HttpServletAdapter extends HttpServerAdapter<HttpServletRequest, HttpServletResponse> { @Override public boolean parseClientIpAndPort(HttpServletRequest req, Span span) { if (parseClientIpFromXForwardedFor(req, span)) return true; return span.remoteIpAndPort(req.getRemoteAddr(), req.getRemotePort()); }  HttpServletResponse adaptResponse(HttpServletRequest req, HttpServletResponse resp); @Override boolean parseClientIpAndPort(HttpServletRequest req, Span span); @Override String method(HttpServletRequest request); @Override String path(HttpServletRequest request); @Override String url(HttpServletRequest request); @Override String requestHeader(HttpServletRequest request, String name); @Override String methodFromResponse(HttpServletResponse response); @Override String route(HttpServletResponse response); @Override @Nullable Integer statusCode(HttpServletResponse response); @Override int statusCodeAsInt(HttpServletResponse response);  }
@Test public void parseClientIpAndPort_skipsRemotePortOnXForwardedFor() { when(request.getHeader("X-Forwarded-For")).thenReturn("1.2.3.4"); when(span.remoteIpAndPort("1.2.3.4", 0)).thenReturn(true); adapter.parseClientIpAndPort(request, span); verify(span).remoteIpAndPort("1.2.3.4", 0); verifyNoMoreInteractions(span); }
@Test public void parseClientIpAndPort_acceptsRemoteAddr() { when(request.getRemoteAddr()).thenReturn("1.2.3.4"); when(request.getRemotePort()).thenReturn(61687); adapter.parseClientIpAndPort(request, span); verify(span).remoteIpAndPort("1.2.3.4", 61687); verifyNoMoreInteractions(span); }