简体   繁体   中英

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). So I need to get client's ip from their request. How can I do it in java?

I've just started learning 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.

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 :

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

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.

I put the code java in my class "MessageReceiverInOut" ,how i can obtain ip address of client which execute my web service Axis2 ?

A client, web app or not, call my url https://myDomain/axis2/services/MyService

MyService is an aar inside axis2.war

Thank a lots

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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