本文介绍了在 JBoss Web 服务中获取 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发了一个带有唯一方法的 java 类,并使用 JBossWS 变成了 Web 服务 (JBOSS).我想获取发起请求的客户端的 IP 地址.(我没有使用jsp)
I developed a java class with an only method and turned into web service (JBOSS) using JBossWS. I would like to get the IP address of the client who started the request. (I'm not using jsp)
public String getMyIP() {
//get IP from client from current request
// return IP as String
}
谢谢!
推荐答案
已解决!
首先在类中设置这个资源:
First set this resource in the class:
@Resource
WebServiceContext wsContext;
然后在您的课程中使用此代码:
Then use this code on your class:
SOAPMessageContext jaxwsContext = (SOAPMessageContext)wsContext.getMessageContext();
HttpServletRequest request = HttpServletRequest)jaxwsContext.get(SOAPMessageContext.SERVLET_REQUEST);
String ipAddress = request.getRemoteAddr();
这篇关于在 JBoss Web 服务中获取 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!