Spring -enabled JAX-WS Web Service, how to get client ip

I am using Spring 3.1 SimpleJaxWsServiceExporter to publish a web service as follows:

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter" > <property name="baseAddress" value="http://192.168.1.8:8888/" /></bean> <bean id="webServiceEndpoint" class="com.test.remoting.jaxws.WebServiceEndpoint"> </bean> 

then I will try to go get the client ip, but my request is zero, please tell me if there are any errors? Many thanks!

 @Resource WebServiceContext wsContext; @WebMethod public String Test(){ MessageContext mc = wsContext.getMessageContext(); HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST); //here is always null return "aa"; } 
+4
source share
2 answers
 private String getIP(){ MessageContext mc = wsContext.getMessageContext(); HttpExchange exchange = (HttpExchange)mc.get("com.sun.xml.internal.ws.http.exchange"); System.out.print(exchange.getRemoteAddress().getAddress().getHostAddress()); return exchange.getRemoteAddress().getAddress().getHostAddress(); } 
+2
source

If MessageContext.SERVLET_REQUEST or HttpExchange do not work. You can use j2e filter or RequestListener

See fooobar.com/questions/387820 / ...

0
source

Source: https://habr.com/ru/post/1396038/


All Articles