Apache Axis2 Web服务 - 获取客户端的端口和IP地址

时间:2014-08-05 03:34:35

标签: apache web-services axis2 axis

我有一个Apache Axis2 Web服务,我试图记录客户端IP地址和端口号。我可以使用以下方式获取IP地址:

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

我如何获得它来自的端口号?

1 个答案:

答案 0 :(得分:0)

我是axis2的新手,我无法理解你的问题。您是否尝试访问请求者端口号或请求URL端口号...?

可能在您获取请求URL端口号的链接下方。请检查

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

当然,您必须将您的类名放在axis2 /.../ web.xml中并重新启动tomcat。然后,您可以检查任何axis2调用内的端口号:

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

来源:How to detect which transportReceiver is used in Axis2