开发者

Get IP address in JBoss Web Service

开发者 https://www.devze.com 2023-04-05 05:40 出处:网络
I developed a java class with an only method and turned int开发者_JAVA技巧o web service (JBOSS) using JBossWS. I would like to get the IP address of the client who started the request. (I\'m not using

I developed a java class with an only method and turned int开发者_JAVA技巧o 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
}

Thanks!


Solved!

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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号