开发者

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

开发者 https://www.devze.com 2022-12-26 19:23 出处:网络
how do you get source ip, username, password, etc... of the client machine that 开发者_StackOverflow中文版sends a soap request? is there any of these details that one can pull for logging purposes?

how do you get source ip, username, password, etc... of the client machine that 开发者_StackOverflow中文版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


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.


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.


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


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.

0

精彩评论

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