gpt4 book ai didi

java - 启用 Spring 的 JAX-WS Web 服务如何获取客户端 ip

转载 作者:搜寻专家 更新时间:2023-11-01 03:27:40 25 4
gpt4 key购买 nike

我使用 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();
}

关于java - 启用 Spring 的 JAX-WS Web 服务如何获取客户端 ip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9249095/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com