简体   繁体   中英

get client IP for webservice on java 6 embbeded http server

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,,,

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,,,

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM