开发者

Get IP address in JBoss Web Service

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜