Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added the code examples to show how to override the service address in wsdl

...

Code Block
xml
xml
titleWSDL to Configure an HTTP Consumer Endpoint
<service ...>
  <port ...>
    <soap:address ... />
    <http-conf:client CacheControl="no-cache" />
  </port>
</service>

Using java code

How to configure the HTTPConduit ?

First you need get the HTTPConduit from the Proxy object or Client, then you can set the HTTPClientPolicy , AuthorizationPolicy, ProxyAuthorizationPolicy  , TSLClientParameters, HttpBasicAuthSupplier.

Code Block
java
java
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(poltim);
  HTTPConduit http = (HTTPConduit) client.getConduit();

  HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

  httpClientPolicy.setConnectionTimeout(36000);
  httpClientPolicy.setAllowChunking(false);
  httpClientPolicy.setReadTimeout(32000);

  http.setClient(httpClientPolicy);

  ...
  greeter.sayHi("Hello");

How to override the endpoint's address ?

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

Code Block
java
java

   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 use CXF ProxyFactoryBean to create the proxy object , you can do like this

Code Block
java
java
   
   JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
   poxyFactory.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

Code Block
java
java

   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);

Client Cache Control Directives

...