如何获取SOAP请求客户端计算机的源IP? [英] How do I get the Source IP of a SOAP requesting client machine?

查看:167
本文介绍了如何获取SOAP请求客户端计算机的源IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取发送soap请求的客户端计算机的源IP,用户名,密码等?是否存在可以用于记录目的的任何这些细节?

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?

我使用Java来处理传入的SOAP请求。该服务只添加2个号码并且正在运行,但我只需要获取一些客户详细信息。

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.

谢谢,Lavanya

Thanks, Lavanya

推荐答案

如果你正在使用JAX-WS,请注入一个WebServiceContext,如下所示:

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();
  }
}

将返回如下内容:

IP:127.0.0.1,端口:2636,主机:localhost

其余的请查看 API 的方法。基本上,一旦你有了 HttpServletRequest 对象,剩下的就很简单了。

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

这篇关于如何获取SOAP请求客户端计算机的源IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆