繁体   English   中英

启用S​​pring的JAX-WS Web服务如何获取客户端ip

[英]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_REQUESTHttpExchange不起作用。 您可以使用j2e过滤器或RequestListener

参见https://stackoverflow.com/a/139169/2257772

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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