Friday, November 11, 2011

Enabling Proxy server for CXF Client

If you ever have the need to enable proxy server for a CXF based webservice client, this is the way to go about it:

Assuming a Spring based application, add this new namespace to the Spring configuration file:

 xmlns:http-conf="http://cxf.apache.org/transports/http/configuration"
....
 xsi:schemaLocation="...
    http://cxf.apache.org/transports/http/configuration
    http://cxf.apache.org/schemas/configuration/http-conf.xsd">
...



Now, if all outbound requests are via a proxy server then make the following entry in your Spring configuration:

 <http-conf:conduit name="*.http-conduit">
  <http-conf:client ProxyServer="${proxy.server}" ProxyServerPort="${proxy.port}" />  
 </http-conf:conduit>

If you need to disable the proxy server, just provide an empty proxy.server parameter.

If you need to enable it only for specific WS requests, then the conduit name has to be modified to the specific services portType:
http-conf:conduit name="{http://apache.org/hello_world_soap_http}SoapPort.http-conduit"

More information here.