简体   繁体   中英

How to get client's IP in JAX RPC web services without Servlet Filter?

I have to log the client's IP address who is using my JAX RPC web service server.

IBM adviced to use servlet filters and get the IP using HTTP Request: http://www-01.ibm.com/support/docview.wss?uid=swg21304368

Is there a different way to get the request? I m using IBM WAS 8.5 and SOAP 1.2 for the server side. Thnx

This worked for me :)

import com.ibm.ws.webservices.engine.MessageContext;
import com.ibm.ws.webservices.engine.transport.http.HTTPConstants;

.....

HttpServletRequest request = (HttpServletRequest) MessageContext.getCurrentThreadsContext().getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);

String clientIpAddress = request.getHeader("X-FORWARDED-FOR");

if (clientIpAddress == null) {
    clientIpAddress = request.getRemoteAddr();
}

System.out.println(clientIpAddress);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM