The problem of wrong endpoint address when Axis2 behind the reserve proxy
This problem was found when I set up Apache ODE server. We know ODE integrated Axis2 as it web service part. I had googled and found some people had met the same problem. Most answers were proposed to config axis.xml file to let Axis2 can generated correct endpoint address. But they are not working. So I got ODE(1.3.5) and Axis2's(1.3) source code and try to understand how Axis2 generated WSDL file from deployed web service. I found axis.xml configuration file would not affect WSDL's endpoint address. It depend on client's request url. Thus, to fix this problem can be achieved by modify reserve proxy's setting. We just need to let reserve proxy rewrite request url as we expected. I use nginx to demonstrate the example.
One reserve proxy server and one Axis2 server for example:
Reserve proxy 192.168.1.1
Axis2 server 192.168.2.1 ws.axis.com
Axis2's domain name is ws.axis.com and bound to reserve proxy. Nginx's setting would be:
upstream ws.axis.com { server 192.168.2.1; } server { server_name ws.axis.com; listen 80; location / { proxy_pass http://ws.axis.com; } }
The request url that Axis2 server received would be start with http://ws.axis.com/. So, the generated endpoint address would be correctly.
I also point out the code you can modify in source code if you need it. Most of http request was responsible by AxisServlet (org.apache.axis2.transport.http.AxisServlet). If path of request url is /services/helloworld?wsdl , AxisServlet would invoke ListAgent's (org.apache.axis2.transport.http.ListAgent) processListService method and passed request and response instance in. In processListService method, you can found the fragment like this:
Above is part of Axis2. Apache ODE's web UI console has the same problem in "Deployment Browser" page. This page will list WSDL link and endpoint address of all processes you made and other process management API. And it depend on request URL too. This can be modified in DeploymentBrowser class (org.apache.ode.axis2.service.DeploymentBrowser). You can find this line in doFilter method:
I also point out the code you can modify in source code if you need it. Most of http request was responsible by AxisServlet (org.apache.axis2.transport.http.AxisServlet). If path of request url is /services/helloworld?wsdl , AxisServlet would invoke ListAgent's (org.apache.axis2.transport.http.ListAgent) processListService method and passed request and response instance in. In processListService method, you can found the fragment like this:
String ip = extractHostAndPort(url, isHttp);Thus, you can modify this line. I recommend not to set a fixed value here, you can get value from axis2.xml's setting. ListAgent instance was initialized together when AxisServlet initialized by container. ListAgent has config context variable (org.apache.axis2.context.ConfigurationContext) come from AxisServlet. Thus, you can get axis configuration (getAxisConfiguration method) instance through config context variable.
Above is part of Axis2. Apache ODE's web UI console has the same problem in "Deployment Browser" page. This page will list WSDL link and endpoint address of all processes you made and other process management API. And it depend on request URL too. This can be modified in DeploymentBrowser class (org.apache.ode.axis2.service.DeploymentBrowser). You can find this line in doFilter method:
final String root = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + requestURI.substring(0, deplUri);DeploymentBrowser class also can access AxisConfiguration come from ODEAxisServlet (org.apache.ode.axis2.hooks.ODEAxisServlet).
留言