views:

517

answers:

1

Hi,

I am implementing web service on java 6 weight light (embbeded) HTTP server jax-ws-web-services-without-java-ee-containers - for testing purposes -

I want to get the client IP for each request.

I tried to declare web service context in my web service class:

@Resource
WebServiceContext wsContext;

then use its message context in web method:

MessageContext msgx = wsContext.getMessageContext();
HttpServletRequest request = (HttpServletRequest)msgx.get(MessageContext.SERVLET_REQUEST);
System.out.println(request.getRemoteAddr());   ---->>> NULLPointerException

but, it give me Null HTTP request.

I used the same way but with SOAP Handler, but the same problem :((

Is there a way to get it, please??

thanks in advance,,,

A: 

I used the same idea, but with little change:

MessageContext msgx = wsContext.getMessageContext();
    HttpExchange exchange = (HttpExchange)msgx.get("com.sun.xml.internal.ws.http.exchange");
    System.out.println(exchange.getRemoteAddress().getAddress());

thanks,,,

Moro