Configuring the Client-side SOAP Message Handlers

15-14 Programming Advanced Features of JAX-WS Web Services for Oracle WebLogic Server ■ The jwsc Ant task compiles SOAP message handler Java files into handler classes and then packages them into the generated application if all the following conditions are true: – The handler classes are referenced in the HandlerChain annotation of the JWS file. – The Java files are located in the directory specified by the sourcepath attribute. – The classes are not currently in your CLASSPATH. If you want to compile the handler classes yourself, rather than let jwsc compile them automatically, ensure that the compiled classes are in your CLASSPATH before you run the jwsc Ant task. ■ You deploy and invoke a Web service that has a handler chain associated with it in the same way you deploy and invoke one that has no handler chain. The only difference is that when you invoke any operation of the Web service, the WebLogic Web services runtime executes the handlers in the handler chain both before and after the operation invoke.

15.9 Configuring the Client-side SOAP Message Handlers

You configure client-side SOAP message handlers in one of the following ways: ■ Set a handler chain directly on the javax.xml.ws.BindingProvider, such as a port proxy or javax.xml.ws.Dispatch object. For example: package examples.webservices.handler.client; import javax.xml.namespace.QName; import java.net.MalformedURLException; import java.net.URL; import javax.xml.ws.handler.Handler; import javax.xml.ws.Binding; import javax.xml.ws.BindingProvider; import java.util.List; import examples.webservices.handler.Handler1; import examples.webservices.handler.Handler2; public class Main { public static void mainString[] args { HandlerWS test; try { test = new HandlerWSnew URLargs[0] + ?WSDL, new QNamehttp:example.org, HandlerWS ; } catch MalformedURLException murl { throw new RuntimeExceptionmurl; } HandlerWSPortType port = test.getHandlerWSPortTypePort; Binding binding = BindingProviderport.getBinding; ListHandler handlerList = binding.getHandlerChain; handlerList.addnew Handler1; handlerList.addnew Handler2; binding.setHandlerChainhandlerList; String result = null; result = port.sayHellofoo bar; System.out.println Got result: + result ; Creating and Using SOAP Message Handlers 15-15 } } ■ Implement a javax.xml.ws.handler.HandlerResolver on a Service instance. For example: public static class MyHandlerResolver implements HandlerResolver { public ListHandler getHandlerChainPortInfo portInfo { ListHandler handlers = new ArrayListHandler; add handlers to list based on PortInfo information return handlers; } } Add a handler resolver to the Service instance using the setHandlerResolver method. In this case, the port proxy or Dispatch object created from the Service instance uses the HandlerResolver to determine the handler chain. For example: test.setHandlerResolvernew MyHandlerResolver; ■ Create a customization file that includes a binding element that contains a handler chain description. The schema for the handler-chains element is the same for both handler chain files on the server and customization files. For example: bindings xmlns:xsd=http:www.w3.org2001XMLSchema xmlns:wsdl=http:schemas.xmlsoap.orgwsdl wsdlLocation=http:localhost:7001handlerHandlerWS?WSDL xmlns=http:java.sun.comxmlnsjaxws bindings node=wsdl:definitions xmlns:jws=http:java.sun.comxmlnsjavaee handler-chains handler-chain handler handler-classexamples.webservices.handler.Handler1 handler-class handler handler-chain handler-chain handler handler-classexamples.webservices.handler.Handler2 handler-class handler handler-chain handler-chains bindings Use the binding child element of the clientgen command to pass the customization file. 15-16 Programming Advanced Features of JAX-WS Web Services for Oracle WebLogic Server 16 Operating at the XML Message Level 16-1 16 Operating at the XML Message Level The following sections describes how to develop Web service provider-based endpoints and dispatch clients to operate at the XML message level: ■ Section 16.1, Overview of Web Service Provider-based Endpoints and Dispatch Clients