Skip to main content

Get client IP address with Java 6 server

3 replies [Last post]
Joined: 2008-06-10


I created a web service server implementation from WSDL with JAX-WS 2.1.1 that comes with java 6u6. Now I need the requesting client IP address for processing.

I tried to get the IP address from the message context but context.get(MessageContext.SERVLET_REQUEST) always returns null, so I can't get the IP address out of the HttpServletRequest object :-(

I tried using the newest implementation (JAX-WS 2.1.3) but the HttpServletRequest object is still null.

Is there a another way to get the client IP address ?

Help is very appreciated


Message was edited by: hochi

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-14

SERVLET_REQUEST is available only when it is deployed in a servlet container. Endpoint.publish() api uses a light weight http server. If you are using jax-ws runtime in JDK, we don't provide any extensions.

But if you use 2.1.3 in the classpath, you should see HttpExchange object of light weight http serve r in the MessageContext. The property is JAXWSProperties.HTTP_EXCHANGE. You could use this object to get client's IP address.

Joined: 2008-06-10

Hi jitu

Thank you very much for the helpful information.

I successfully got the client IP address from HttpExchange.

Joined: 2011-04-07

I need to obtain IP address in server side I am using metro 1.5 and java 1.6 but I dont know how to access to context from server side

@javax.jws.WebService (endpointInterface="ws.server.WsConsultaOnlinePortType",serviceName="WsConsultaOnlineService" )
public class wsConsultaDirectaImpl extends WSCoreBase {

// @Resource
WebServiceContext wsctx;

/* Comprueba que servicio este levantado
* @return true
public boolean test() {
MessageContext msgContext = wsctx.getMessageContext();
Map requestHeaders = (Map) msgContext.get(MessageContext.HTTP_REQUEST_HEADERS) ;
if (requestHeaders!=null)
if (requestHeaders.isEmpty()) System.out.println("vacio");
System.out.println("no vacio");

return true;
MessageContext msgContext = wsctx.getMessageContext(); throw a null pointer exception
May i help me ¿