When the message flow needs to be routed through a proxy, you need to add following parameters to transportSender configuration in axis2.xml.
http.proxyHost - proxy server's host name
http.proxyPort - port number of the proxy server
http.nonProxyHosts - any host that need to by pass above proxy
Else you can set Java networking properties.
-Dhttp.proxyHost=example.org -Dhttp.proxyPort=5678 -Dhttp.nonProxyHosts=localhost|127.0.0.1|foo.com
Sample:
This scenario illustrates how a routing via proxy and nonproxy happens. I have echo service in an AppServer which is fronted by stockquaote.org HTTP proxy. I also have SimpleStockQuoteService in localhost which is set as a nonProxyHost.
I have my transport sender in axis2.xml configured as below:
<transportSender name="http" class="org.apache.synapse.transport.passthru.PassThroughHttpSender"> <parameter name="non-blocking" locked="false">true</parameter> <parameter name="http.proxyHost" locked="false">stockquote.org</parameter> <parameter name="http.proxyPort" locked="false">8080</parameter> <parameter name="http.nonProxyHosts" locked="false">localhost</parameter> </transportSender>
Proxy rout:
<proxy name="Echo_viaProxy" transports="https http" startOnLoad="true" trace="disable"> <description/> <target> <endpoint> <address uri="http://xx.xx.xx.xxx:9765/services/Echo"/> </endpoint> <outSequence> <send/> </outSequence> </target> </proxy>
When you send a request to above SimpleStckQ_viaProxy, the request will be direct to stockquaote.org which will route to BE (http://localhost:9000/services/SimpleStockQuoteService).
nonProxy:
<proxy name="StockQuote_direct" transports="https http" startOnLoad="true" trace="disable"> <description/> <target> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> <outSequence> <send/> </outSequence> </target> </proxy>When you send a request to above StockQuote_direct, the request will be directly served by SimpleStockService in localhost.
known issue and fix:
https://wso2.org/jira/browse/ESBJAVA-3165 is fixed in 4.9.0 M4.
This is complete code and it is working for me. Great help and great tips. I try many code which i was found on internet but no one is working for me. It force me to write comment here because it is working fine after searching a lot on internet. You same my some extra days, Actually i want to set it for my project which is based on dedicated proxy service and your code is working on it. Great keep sharing and keep updating.
ReplyDelete