如何获取发送soap请求的客户端计算机的源IP,用户名,密码等?是否存在可以用于记录目的的任何这些细节?
我正在使用Java来处理传入的SOAP请求。该服务只添加2个号码并且正在运行,但我只需要获取一些客户端详细信息。
谢谢Lavanya
答案 0 :(得分:17)
如果您正在使用JAX-WS,请注入WebServiceContext,如下所示:
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();
}
}
会返回类似的内容:
IP: 127.0.0.1, Port: 2636, Host: localhost
查看其余方法的API。基本上,一旦你拥有了HttpServletRequest
对象,剩下的就很容易了。
答案 1 :(得分:0)
我不熟悉我完全理解你获取客户端机器的用户名和密码的想法。 一般情况下,Soap看看Soap Header,它们应该带有身份验证信息(可以是用户名,密码或某种安全性toke)。 对于IP,你的Soap来自Http,因此当你收到你的请求时,你可以尝试查看你的Http标题,看看它给你的信息。虽然我从未试图从中获取客户端的IP,但它可能在HTTP标头中
答案 2 :(得分:0)
你使用什么肥皂堆。如果您使用轴将其部署为war文件,则很容易实现。你需要掌握httprequestobject并在其上调用HTTPServletRequest.getRemoteAddr()方法。
答案 3 :(得分:0)
我已经找到了如下解决方案 -
@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();
}
}
通过使用以下方法,我可以直接访问HttpServletRequest。然后我可以访问我需要的所有数据。
我希望它会在这种情况下帮助某人。