Implementing the Handler.init Method Implementing the Handler.destroy Method Implementing the Handler.getHeaders Method Implementing the Handler.handleRequest Method

Creating and Using SOAP Message Handlers 9-7 SOAPMessageContext messageContext = SOAPMessageContext context; System.out.println Request: +messageContext.getMessage.toString; log.infomessageContext.getMessage.toString; return true; } Specifies that the SOAP response message be logged to a log file before the message is sent back to the client application that invoked the Web service. public boolean handleResponseMessageContext context { SOAPMessageContext messageContext = SOAPMessageContext context; System.out.println Response: +messageContext.getMessage.toString; log.infomessageContext.getMessage.toString; return true; } Specifies that a message be logged to the log file if a SOAP fault is thrown by the Handler instance. public boolean handleFaultMessageContext context { SOAPMessageContext messageContext = SOAPMessageContext context; System.out.println Fault: +messageContext.getMessage.toString; log.infomessageContext.getMessage.toString; return true; } public QName[] getHeaders { return handlerInfo.getHeaders; } }

9.4.1 Implementing the Handler.init Method

The Handler.init method is called to create an instance of a Handler object and to enable the instance to initialize itself. Its signature is: public void initHandlerInfo config throws JAXRPCException {} The HandlerInfo object contains information about the SOAP message handler, in particular the initialization parameters. Use the HandlerInfo.getHandlerConfig method to get the parameters; the method returns a java.util.Map object that contains name-value pairs. 9-8 Programming Advanced Features of JAX-RPC Web Services for Oracle WebLogic Server Implement the init method if you need to process the initialization parameters or if you have other initialization tasks to perform. Sample uses of initialization parameters are to turn debugging on or off, specify the name of a log file to which to write messages or errors, and so on.

9.4.2 Implementing the Handler.destroy Method

The Handler.destroy method is called to destroy an instance of a Handler object. Its signature is: public void destroy throws JAXRPCException {} Implement the destroy method to release any resources acquired throughout the handlers life cycle.

9.4.3 Implementing the Handler.getHeaders Method

The Handler.getHeaders method gets the header blocks that can be processed by this Handler instance. Its signature is: public QName[] getHeaders {}

9.4.4 Implementing the Handler.handleRequest Method

The Handler.handleRequest method is called to intercept a SOAP message request before it is processed by the back-end component. Its signature is: public boolean handleRequestMessageContext mc throws JAXRPCException,SOAPFaultException {} Implement this method to perform such tasks as decrypting data in the SOAP message before it is processed by the back-end component, and so on. The MessageContext object abstracts the message context processed by the SOAP message handler. The MessageContext properties allow the handlers in a handler chain to share processing state. Use the SOAPMessageContext sub-interface of MessageContext to get at or update the contents of the SOAP message request. The SOAP message request itself is stored in a javax.xml.soap.SOAPMessage object. For detailed information on this object, see Section 9.4.7, Directly Manipulating the SOAP Request and Response Message Using SAAJ . The SOAPMessageContext class defines two methods for processing the SOAP request: ■ SOAPMessageContext.getMessage returns a javax.xml.soap.SOAPMessage object that contains the SOAP message request. ■ SOAPMessageContext.setMessagejavax.xml.soap.SOAPMessage updates the SOAP message request after you have made changes to it. After you code all the processing of the SOAP request, code one of the following scenarios: ■ Invoke the next handler on the handler request chain by returning true. The next handler on the request chain is specified as either the next handler subelement of the handler-chain element in the configuration file specified by the HandlerChain annotation, or the next SOAPMessageHandler in the Creating and Using SOAP Message Handlers 9-9 array specified by the SOAPMessageHandlers annotation. If there are no more handlers in the chain, the method either invokes the back-end component, passing it the final SOAP message request, or invokes the handleResponse method of the last handler, depending on how you have configured your Web service. ■ Block processing of the handler request chain by returning false. Blocking the handler request chain processing implies that the back-end component does not get executed for this invoke of the Web service. You might want to do this if you have cached the results of certain invokes of the Web service, and the current invoke is on the list. Although the handler request chain does not continue processing, WebLogic Server does invoke the handler response chain, starting at the current handler. For example, assume that a handler chain consists of two handlers: handlerA and handlerB, where the handleRequest method of handlerA is invoked before that of handlerB. If processing is blocked in handlerA and thus the handleRequest method of handlerB is not invoked, the handler response chain starts at handlerA and the handleRequest method of handlerB is not invoked either. ■ Throw the javax.xml.rpc.soap.SOAPFaultException to indicate a SOAP fault. If the handleRequest method throws a SOAPFaultException, WebLogic Server catches the exception, terminates further processing of the handler request chain, and invokes the handleFault method of this handler. ■ Throw a JAXRPCException for any handler-specific runtime errors. If the handleRequest method throws a JAXRPCException, WebLogic Server catches the exception, terminates further processing of the handler request chain, logs the exception to the WebLogic Server log file, and invokes the handleFault method of this handler.

9.4.5 Implementing the Handler.handleResponse Method