You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Mohamed Chaouchi <Mo...@noaa.gov> on 2006/07/03 17:47:02 UTC

How to retrieve the client IP address when Apache acts as a proxy for Tomcat?

Hello,

I am trying to retrieve the client IP address accessing the web 
services. Because Apache is our proxy for all requests, when I try to 
retrieve the client IP I always get the localhost IP: 127.0.0.1

The following code returns the localhost IP:

MessageContext msgContext = MessageContext.getCurrentContext();     
if(msgContext != null) {
      return msgContext.getProperty(Constants.MC_REMOTE_ADDR).toString();
}
return "Unknown";

 From a servlet, obtaining the client IP address can be achieved using 
this code.

   String ipAddress = request.getHeader("x-forwarded-for");            
     if (ipAddress  == null) {
           ipAddress  = request.getHeader("X_FORWARDED_FOR");
           if (ipAddress == null){
               ipAddress  = request.getRemoteAddr();
           }
       }           
  return IPaddress ; 

Any help is greatly appreciated.

Thank you very much

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org