Skip to main content Skip to complementary content

Using java code

How to configure the HTTPConduit for the SOAP Client?

First you need get the http://tinyurl.com/285zllHTTPConduit from the Proxy object or Client, then you can set the HTTPClientPolicy , AuthorizationPolicy, ProxyAuthorizationPolicy, TLSClientParameters , and/or HttpBasicAuthSupplier .

import org.apache.cxf.endpoint.Client;
            import org.apache.cxf.frontend.ClientProxy;
            import org.apache.cxf.transport.http.HTTPConduit;
            import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
            ...
            
            URL wsdl = getClass().getResource("wsdl/greeting.wsdl");
            SOAPService service = new SOAPService(wsdl, serviceName);
            Greeter greeter = service.getPort(portName, Greeter.class);
            
            // Okay, are you sick of configuration files ?
            // This will show you how to configure the http conduit dynamically
            Client client = ClientProxy.getClient(greeter);
            HTTPConduit http = (HTTPConduit) client.getConduit();
            
            HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();
            
            httpClientPolicy.setConnectionTimeout(36000);
            httpClientPolicy.setAllowChunking(false);
            httpClientPolicy.setReceiveTimeout(32000);
            
            http.setClient(httpClientPolicy);
            
            ...
            greeter.sayHi("Hello");

How to override the service address ?

If you are using JAXWS API to create the proxy obejct, here is an example which is complete JAX-WS compliant code

URL wsdlURL = MyService.class.getClassLoader.getResource ("myService.wsdl");
            QName serviceName = new QName("urn:myService", "MyService");
            MyService service = new MyService(wsdlURL, serviceName);
            ServicePort client = service.getServicePort();
            BindingProvider provider = (BindingProvider)client;
            // You can set the address per request here
            provider.getRequestContext().put(
            BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
            "http://my/new/url/to/the/service");

If you are using CXF ProxyFactoryBean to create the proxy object , you can do like this

JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
            proxyFactory.setServiceClass(ServicePort.class);
            // you could set the service address with this method
            proxyFactory.setAddress("theUrlyouwant");
            ServicePort client = (ServicePort) proxyFactory.create();

Here is another way which takes advantage of JAXWS's Service.addPort() API

URL wsdlURL = MyService.class.getClassLoader.getResource(
            "service2.wsdl");
            QName serviceName = new QName("urn:service2", "MyService");
            QName portName = new QName("urn:service2", "ServicePort");
            MyService service = new MyService(wsdlURL, serviceName);
            // You can add whatever address as you want
            service.addPort(portName, "http://schemas.xmlsoap.org/soap/", 
            "http://the/new/url/myService");
            // Passing the SEI class that is generated by wsdl2java      
            ServicePort proxy = service.getPort(portName, SEI.class);

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!