[英]Spring-enabled JAX-WS Web Service how to get client ip
我使用Spring 3.1 SimpleJaxWsServiceExporter发布这样的Web服务:
<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>
然后我尝试去获取客户端IP,但是我的请求为空,请告诉我有什么问题吗? 非常感谢!!
@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";
}
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();
}
如果MessageContext.SERVLET_REQUEST或HttpExchange不起作用。 您可以使用j2e过滤器或RequestListener
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.