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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With