How do I setup handlers in Axis clients?

When instantiating a Service-object, you can provide your own  EngineConfiguration . There are several ways to build a configuration of your desire:

This example configures the  SimpleSessionHandler  in the request- and response-flow of a HTTP-transport-chain:

     <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="..." > 
       <handler type="java:org.apache.axis.handlers.SimpleSessionHandler" 
                name="SimpleSessionHandler"/> 
       <transport name="http" 
                  pivot="java:org.apache.axis.transport.http.HTTPSender"> 
         <requestFlow><handler type="SimpleSessionHandler"/></requestFlow> 
         <responseFlow><handler type="SimpleSessionHandler"/></responseFlow> 
       </transport>" 
     </deployment> 

The code to get an  EngineConfiguration  from this given as a String:

     EngineConfiguration clientConfig = (EngineConfiguration) new ["XMLStringProvider"](WSDDString); 

The  SimpleProvider , for example, allows deployment of Transport chains The following example does about the same as the WSDD above:

     import org.apache.axis.configuration.SimpleProvider; 
     import org.apache.axis.EngineConfiguration; 
     import org.apache.axis.Handler; 
     import org.apache.axis.SimpleChain; 
     import org.apache.axis.SimpleTargetedChain; 
     import org.apache.axis.handlers.SimpleSessionHandler; 
     import org.apache.axis.transport.http.HTTPSender; 
     import org.apache.axis.transport.http.HTTPTransport; 

     EngineConfiguration createClientConfig() 
     { 
       SimpleProvider clientConfig=new SimpleProvider(); 
       Handler sessionHandler=(Handler)new SimpleSessionHandler(); 
       SimpleChain reqHandler=new SimpleChain(); 
       SimpleChain respHandler=new SimpleChain(); 
       reqHandler.addHandler(sessionHandler); 
       respHandler.addHandler(sessionHandler); 
       Handler pivot=(Handler)new HTTPSender(); 
       Handler transport=new SimpleTargetedChain(reqHandler, pivot, respHandler); 
       clientConfig.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME,transport); 

       return clientConfig;    
     } 

When using WSDL2Java-generated code, the  XYServiceLocator  (that extends Service) does not provide a constructor to give the configuration. If you do not want to modify generated code, you can work around this the following way:

       EngineConfiguration clientConfig=getClientConfig(); 
       ["XYServiceLocator"] service=new ["XYServiceLocator"](); 
       service.setEngineConfiguration(clientConfig); 
       service.setEngine(new AxisClient(clientConfig)); 
       XY myservice=service.getmyservice(); 

FrontPage/Axis/AxisClientConfiguration (last edited 2009-09-20 22:48:03 by localhost)