简体   繁体   English

如何从Java中的axis2 Web服务请求获取客户端的IP?

[英]How to get client's ip from axis2 webservice request in java?

I want to verify client connected to my web service server (I using jboss 7 to deploy my server). 我想验证连接到Web服务服务器的客户端(我使用jboss 7部署服务器)。 So I need to get client's ip from their request. 因此,我需要从他们的请求中获取客户的IP。 How can I do it in java? 如何在Java中执行此操作?

I've just started learning WebServices. 我刚刚开始学习WebServices。 Perhaps this line of code would help. 也许这行代码会有所帮助。 Not very much sure about Axis2 but using some older versions of Axis, you may do like this. 对于Axis2不太确定,但是使用一些较旧版本的Axis,您可能会这样做。

MessageContext messageContext = MessageContext.getCurrentContext(); 
String ipAddress = messageContext.getStrProp(Constants.MC_REMOTE_ADDR);

there're few more Constants used to get client specific properties. 很少有用于获取客户端特定属性的常量。 If necessary, you may wanna use some custom headers to fetch the properties. 如有必要,您可能想使用一些自定义标头来获取属性。

In Axis2, you get the remote (client) IP from the MessageContext : 在Axis2中,您可以从MessageContext获取远程(客户端)IP:

import org.apache.axis2.context.MessageContext;
MessageContext mc = MessageContext.getCurrentMessageContext();
String clientIP = (String) mc.getProperty(MessageContext.REMOTE_ADDR);

Reference: AXIS2-1610 : Need to get client IP address on server side 参考: AXIS2-1610 :需要在服务器端获取客户端IP地址

I'm using axis2 1.5.3 , I read property "MessageContext.REMOTE_ADDR" but it returns ip address of my Jboss application server where deployed my axis2.war. 我正在使用axis2 1.5.3,我读取了属性“ MessageContext.REMOTE_ADDR”,但它返回部署了axis2.war的Jboss应用服务器的IP地址。

I put the code java in my class "MessageReceiverInOut" ,how i can obtain ip address of client which execute my web service Axis2 ? 我将代码java放在类“ MessageReceiverInOut”中,如何获取执行我的Web服务Axis2的客户端的IP地址?

A client, web app or not, call my url https://myDomain/axis2/services/MyService 无论是客户端还是Web应用程序,请致电我的URL https:// myDomain / axis2 / services / MyService

MyService is an aar inside axis2.war MyService是axis2.war内部的aar

Thank a lots 非常感谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM