我使用下面的代码获取客户端IP地址为JAX-WS单向方法调用:
protected HttpServletRequest getServletRequest() {
MessageContext ctx = wsContext.getMessageContext();
return (HttpServletRequest) ctx.get( MessageContext.SERVLET_REQUEST );
}
protected synchronized String getClientIp() {
String clientIp = "";
HttpServletRequest request = getServletRequest();
if ( request != null ) {
clientIp = request.getRemoteAddr();
// Handle proxy
String header = request.getHeader( "x-forwarded-for" );
if( header != null && !header.isEmpty() ) {
clientIp = header.split( "," )[0];
}
}
return clientIp;
}
当多个客户端连接中,对于请求检索的IP地址是偶尔从早期的请求不正确的缓存值。 什么是可靠的方式来获得单向呼叫发起的IP地址?