views:

96

answers:

3

how do you get source ip, username, password, etc... of the client machine that sends a soap request? is there any of these details that one can pull for logging purposes?

I am using Java to handle the incoming SOAP requests. The service simply adds 2 numbers and is working, but I just need to get some client details.

Thanks, Lavanya

A: 

I am not surte I fully understand your idea of getting username and password of client machine. In general with Soap look at Soap Header, they are supposed to carry the authentication information (which could be username, password or some kind of security toke). For the IP, your Soap is coming over Http and therefore when you receive your request you can try and look at your Http headers to see what information it gives you. Though I have never tried to get the IP of the client from it, but it might be there in the HTTP header

Fazal
looks like I will have to try and use that HTTP header object. are there like metadata in the header that get passed by default or is it strictly what you put into the header?
A: 

What soap stack are u using. If u deployed it as a war file using axis it is pretty easy to do it. u need to get hold of the httprequestobject and call the HTTPServletRequest.getRemoteAddr() method on it.

anonymous
the service is running as a .jar file. Then I use my WSDL file to create and launch requests.
A: 

If you're using JAX-WS, inject a WebServiceContext like so:

import javax.annotation.Resource
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;


@WebService()
public class Test
{
  @Resource WebServiceContext context;

  @WebMethod(operationName = "getInfo")
  public String getInfo()
  {
    HttpServletRequest request = (HttpServletRequest)context.getMessageContext().get(MessageContext.SERVLET_REQUEST);
    return "IP: "+request.getRemoteAddr()+", Port: "+request.getRemotePort()+", Host: "+request.getRemoteHost();
  }
}

Will return something like:

IP: 127.0.0.1, Port: 2636, Host: localhost

Look at the API for the rest of the methods. Basically, once you have your HttpServletRequest object, the rest is pretty easy.

Catchwa