我有一个Apache Axis2 Web服务,我试图记录客户端IP地址和端口号。我可以使用以下方式获取IP地址:
MessageContext inMessageContext = MessageContext.getCurrentMessageContext();
String ip = (String)inMessageContext.getProperty("REMOTE_ADDR");
我如何获得它来自的端口号?
答案 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" );