Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the Source IP of a SOAP requesting client machine?

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

like image 724
user450937 Avatar asked Apr 15 '10 18:04

user450937


2 Answers

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.

like image 62
Catchwa Avatar answered Oct 04 '22 08:10

Catchwa


I have figured the solution like below -

@Endpoint 
public class DataEndpoints {
....
....
     private HttpServletRequest httpServletRequest;

     @Autowired
     public void setRequest(HttpServletRequest request) {
         this.httpServletRequest = request;
     }


     @PayloadRoot(namespace = employeeNS, localPart = "syncRelation")
     @ResponsePayload
     public SyncRelationResponse dataSync(@RequestPayload SyncOrderRelation request) {
            String incoming = "IP Address -> " + this.httpServletRequest.getRemoteAddr();
     }
}

By using the following method, I can directly access HttpServletRequest. And then I can access all data i need.

I hope it will help someone in this context.

like image 29
Saikat1529 Avatar answered Oct 04 '22 09:10

Saikat1529