Apache Axis2/Java supports interfacing with proxies via HTTP Client 3.0.1. This configuration is achieved programmatically, or, by editing the axis2.xml file. In addition to this, you can also employ Java networking properties to configure proxy interfacing. Saminda Abeyruwan explains..
Applies To
| Project | Apache Axis2 / Java 1.3 upward |
| Environment | Any |
| JDK | 1.4 upward |
Configuration by Editing the axis2.xml File
In the axis2.xml configuration file, you need to provide a top-level parameter named "Proxy". The following displays a complete configuration of the proxy configuration:
<parameter name="Proxy">
<Configuration>
<ProxyHost>example.org</ProxyHost>
<ProxyPort>5678</ProxyPort>
<ProxyUser>EXAMPLE\guest</ProxyUser>
<ProxyPassword>guest</ProxyPassword>
</Configuration>
</parameter>
If an open proxy is used, you can drop the <ProxyUser/> and <ProxyPassword/> elements from the above configuration.
Programmatic Configuration
You have to add the following bit of code to your client or the stub:
HttpTransportProperties.ProxyProperties pp =
new HttpTransportProperties.ProxyProperties();
pp.setProxyName("example.org");
pp.setProxyPort(5678);
pp.setUserName("guest");
pp.setPassWord("guest");
options.setProperty(HTTPConstants.PROXY,pp);
The "options" object reference will be avaiable from the stub or the ServiceClient class.
Configuration Through Java Networking Properties
If you would prefer to connect to a proxy without even bothering to edit the axis2 configuration or writing additional code, you should then set Java networking properties. The most commonly used properties are "http.proxyHost", "http.proxyPort" and "http.nonProxyHosts".
e.g.
-Dhttp.proxyHost=example.org -Dhttp.proxyPort=5678 -Dhttp.nonProxyHosts=localhost|127.0.0.1|foo.com
References
[1]. http://ws.apache.org/axis2/1_3/http-transport.html [1]
[2]. http://wso2.org/library/161 [2]
Author
Saminda Abeyruwan, Software Engineer, WSO2 Inc. (saminda@wso2.com)