如何在ContainerRequestFilter中获取远程IP [英] How to get the remote IP in a ContainerRequestFilter
本文介绍了如何在ContainerRequestFilter中获取远程IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个课程,想记录其余的请求:
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)
}
}
如何获取请求的远程IP? TIA!
How do do I get the remote IP of the request? TIA!
推荐答案
尝试一下:
public class RequestFilter implements ContainerRequestFilter {
private static final Logger LOG = LoggerFactory.getLogger(RequestFilter.class);
@Context
private HttpServletRequest request;
// rest of your stuff here
这篇关于如何在ContainerRequestFilter中获取远程IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文