3

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
}

Thanks!

Hectoret
  • 3,553
  • 13
  • 49
  • 56
  • I would like to point out that this question is different from: http://stackoverflow.com/questions/3346365/how-to-log-ip-address-on-jboss I tried but don't know how to get the request object MDC.put("RemoteAddress", request.getRemoteAddr()) – Hectoret Sep 15 '11 at 11:13

1 Answers1

3

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();
Hectoret
  • 3,553
  • 13
  • 49
  • 56