7/28/2009

Apache CXF Proxy Setting for Client with httpConduit

Many times its required to run the webservice clients from within the company firewall. This require to go through a proxy, in Apache CXF webservice framework you can specify the Proxy setting for client code in cxf.xml file. You will need to place this file in the class path of your client application. Here is the setting one will require put



<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
xmlns:conf-sec="http://cxf.apache.org/configuration/security"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/transports/http/configuration http://cxf.apache.org/schemas/configuration/http-conf.xsd">

<http-conf:conduit name="*.http-conduit">
<http-conf:client ProxyServer="http://www-url-to-my-proxy.com" ProxyServerPort="80" />
<http-conf:proxyAuthorization>
<conf-sec:UserName>username</conf-sec:UserName>
<conf-sec:Password>password</conf-sec:Password>
</http-conf:proxyAuthorization>
</http-conf:conduit>

</beans>

2 comments:

jeff.hasenauer said...

Is there any way to set a proxy server and port attribute via the CXF Java API?

jeff.hasenauer said...

Nevermind, I actually figured it out:

HTTPClientPolicy policy = new HTTPClientPolicy();
policy.setProxyServer(System.getProperty("http.proxyHost"));
policy.setProxyServerPort(Integer.valueOf(System.getProperty("http.proxyPort")).intValue());

httpConduit.setClient(policy);