Skip to main content

Retrieving request ip from SOAP Message

3 replies [Last post]
giordano48
Offline
Joined: 2007-02-14

Dear all,

I have developed a simple web service with an handler that intercepts the SOAP request. I would like to know if exists a way to retrieve the ip address of the web service client analysing the SOAP message or in other way.

Thank you very much in advance and bye,
Giordano

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jitu
Offline
Joined: 2003-06-14

@WebService
public class HelloService {
@Resource
WebServiceContext wsCtxt;

public void method() {
MessageCtxt msgCtxt = wsCtxt.getMessageContext();
HttpServletRequest req = (HttpServletRequest)msgCtxt.get(MessageContext.SERVLET_REQUEST)
// using req you can get all the information, req.getRemoteAddr()
}
}

Jitu

pohl
Offline
Joined: 2006-10-27

I'm using glassfish v2b43, and I have essentially tried this exact technique.

It appears to work...at first, it appears so. The IP address of the first client to hit the service is correctly logged.

If I then hit the service from a different machine, however, the IP address of the first machine is still logged.

My code is essentially the same as jitu has given here.

FWIW, glassfish v1 UR1 P01 also exhibits the same failure to correctly display the client's IP address.

pohl
Offline
Joined: 2006-10-27

Ok, scratch that. I'm an idiot.

I was using the service tester page, so obviously the client's IP address is always going to be the same. Lol.

*slinks away quietly*