简体   繁体   中英

Apache Axis2 Webservice- getting port and ip address of client

I have a Apache Axis2 web service and Im trying to log client ip address and port number. Im able to get the ip address using:

MessageContext inMessageContext = MessageContext.getCurrentMessageContext();  
String ip = (String)inMessageContext.getProperty("REMOTE_ADDR");

How can i obtain the port number it came from?

I am newbie for axis2, I cant understand your question. Are you trying to access requester port number or requesting URL port number...?

May be below link useful for you to getting requesting URL port number. Please check

public class MyServlet extends AxisServlet
{   
    protected MessageContext createMessageContext( HttpServletRequest request, HttpServletResponse response, boolean invocationType ) throws IOException
    {
        MessageContext mc = super.createMessageContext( request, response, invocationType );
        URL url = new URL( request.getRequestURL().toString() );
        mc.setProperty( "myPort", url.getPort() );
        return mc;      
    }
}

Of course you must put your class name in axis2/.../web.xml and restart tomcat. Then you can check port number inside any axis2 invocation:

MessageContext mc = MessageContext.getCurrentMessageContext();
int port = ( Integer ) mc.getProperty( "myPort" );

source : How to detect which transportReceiver is used in Axis2

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