WSO2Con 2013 CFP Banner

Accessing Client IP and Transport Session Related Data from MessageContext

Discuss this article on Stack Overflow
By Deepal Jayasingha
  • 8 Jan, 2007
  • Level: 
  • Reads: 12358
Under some scenarios, example, when writing a session aware Web service, you may need to access ServletContext or HttpServletRequest. You may also need to know the IP address of the client, so you can treat each client differently.
Deepal Jayasingha

WSO2 Inc.
If you are using Axis2 Web Archive (WAR) distribution, then you can easily get these information from the messagecontext.Accessing Remote IP address from the message context: You can get the remote IP address of the client corresponding to the current message as follows; String remoteAddress = (String)msgCtx.getProperty("REMOTE_ADDR"): Accessing ServletContext from the message context: You can obtain the ServletContext from message context as follows; ServletContext servletContext = (ServletContext)msgCtx.getProperty("transport.http.servletContext"): Accessing HttpServletRequest from the message context: You can obtain the HttpServletRequest from message context as follows; HttpServletRequest httpServletRequest = (HttpServletRequest)msgCtx.getProperty("transport.http.servletRequest"): Applies To: Apache Axis2/Java, any version