How to get the remote IP in a ContainerRequestFilter
java, jersey, rest
Solution
Try this:
public class RequestFilter implements ContainerRequestFilter {
private static final Logger LOG = LoggerFactory.getLogger(RequestFilter.class);
@Context
private HttpServletRequest request;
// rest of your stuff here
Problem
I have this class and wants to log the rest-requests: ``` public class RequestFilter implements ContainerRequestFilter { private static final Logger LOG = LoggerFactory.getLogger(RequestFilter.class); @Override public void filter(ContainerRequestContext requestContext) throws IOException { LOG.info("REST-Request from '{}' for '{}'", "XXX", requestContext.getUriInfo().getPath()); // ... and do some auth stuff (not relevant for this question) } } ``` How do do I get the remote IP of the request? TIA!