uCosminexus Application Server, Web Service Development Guide

[Contents][Glossary][Index][Back][Next]

36.9.2 Setting the handler chain in the Web Service client

To set the handler chain in the Web Services client, use the JAX-WS API. For the details on the available JAX-WS APIs, see 19.2 Support Range of API.

Organization of this subsection
(1) Add Code that sets the handler chain
(2) SOAP role and actor settings
(3) soap:mustUnderstand attribute settings

(1) Add Code that sets the handler chain

The following methods are used to set a handler chain on a Web Services Client:

This section describes the methods of setting the handler chain.

(a) Setting the handler chain to a service class

The following example describes the code added to the Web Services Client to set the handler chain to a service class by using an API:

package com.example.sample.client;
 
import com.example.sample.TestJaxWs;
import com.example.sample.TestJaxWsService;
import com.example.sample.UserDefinedException;
 
public class TestClient {
 public static void main( String[] args ) {
 try {
  TestJaxWsService service = new TestJaxWsService();
  // Handler-resolver-is-generated-and-set-in-the-service-class
  SampleHandlerResolver handlerResolver = new SampleHandlerResolver();
  service.setHandlerResolver( handlerResolver );
  TestJaxWs port = service.getTestJaxWs();
  
  String returnValue = port.jaxWsTest1( "Invocation test.", 1003 );
  
  System.out.println( "[RESULT] " + returnValue );
 }
 catch( UserDefinedException e ){
  e.printStackTrace();
 }
 }
}

The following is an example of a handler resolver:

package com.example.sample.client;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.xml.ws.handler.HandlerResolver;
import javax.xml.ws.handler.PortInfo;
import javax.xml.ws.soap.SOAPBinding;
 
public class SampleHandlerResolver implements HandlerResolver{
 //Handler-chain-stored-by-this-handler-resolver
 private List<Handler> handlerChain = new ArrayList<Handler>();
 
 //Use-a-convenient-method-to-add-the-handler-to-the-handler-chain-in-advance
 //The-constructor-is-used-to-add-the-handler-here
 public SampleHandlerResolver(){
 this.handlerChain.add( new SomeHandler() );
 }
 
 //Returns-the-handler-chain
 public List<Handler> getHandlerChain( PortInfo portInfo ){
 //Check-the-contents-of-the-portInfo-object
 //If-the-portInfo-object-can-be-processed-by-this-handler-resolver-the-handler-chain-is-returned
 if( portInfo.getBindingID().equals( SOAPBinding.SOAP11HTTP_BINDING )
  && portInfo.getPortName().equals( ... )
  && portInfo.getServiceName().equals( ... ) ){
  return this.handlerChain;
 }
 else{
  ...
 }
 }
}

The changes in the handler resolver set up using the javax.xml.ws.Service#setHandlerResolver method do not affect the handler chains of ports previously acquired from the same Service object.

(b) Setting the handler chain to a port

The following example shows a Web Services client to which a code is added to set the handler chain to a port by using an API:

package com.example.sample.client;
 
import java.util.ArrayList;
import java.util.List;
 
import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
 
import com.example.sample.TestJaxWs;
import com.example.sample.TestJaxWsService;
import com.example.sample.UserDefinedException;
 
public class TestClient {
    public static void main( String[] args ) {
        try {
            TestJaxWsService service = new TestJaxWsService();
            TestJaxWs port = service.getTestJaxWs();
 
// Generate a handler chain to be set to a port
            List<Handler> handlerChain = new ArrayList<Handler>();
            //Add a handler to the handler chain
            handlerChain.add( new SomeHandler() );
 
            //Acquire javax.xml.ws.Binding
            Binding binding = ( ( BindingProvider )port ).getBinding();
 
// Set the handler chain to a port by using javax.xml.ws.Binding
 
            binding.setHandlerChain(handlerChain);
 
            String returnValue = port.jaxWsTest1( "Invocation test.", 1003 );
            System.out.println( "[RESULT] " + returnValue );
        }
        catch( UserDefinedException e ){
            e.printStackTrace();
        }
    }
}

If you set the handler chain in both the service classes and ports acquired from the service classes, the handler chain set in the ports is used. Also, the handler chain set by the javax.xml.ws.Binding#setHandlerChain method does not affect the handler chain of the Service object from which the ports are to be acquired.

(2) SOAP role and actor settings

If the SOAP role and actor settings are omitted or if null is specified, the default value is set up. The default value is http://schemas.xmlsoap.org/soap/actor/next for a SOAP Message in the SOAP 1.1 specification and http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver for a SOAP Message in the SOAP 1.2 specification.

(3) soap:mustUnderstand attribute settings

Set up 0, 1, true, or false in the soap:mustUnderstand attribute. If another value is specified, 0 or false is assumed.