Search code examples
javaweb-servicesipsoap-clientjax-rpc

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


Solution

  • 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);