FileDocCategorySizeDatePackage
FaultableHandler.javaAPI DocApache Axis 1.45126Sat Apr 22 18:57:26 BST 2006org.apache.axis

FaultableHandler

public class FaultableHandler extends org.apache.axis.handlers.BasicHandler
A FaultableHandler is essentially a wrapper for any other Handler which provides flexible fault handling semantics.
author
Doug Davis (dug@us.ibm.com)
author
Glen Daniels (gdaniels@apache.org)

Fields Summary
protected static Log
log
The Log used to log all events that would be of general interest.
protected static Log
entLog
The Log used for enterprise-centric logging. The enterprise category is for stuff that an enterprise product might want to track, but in a simple environment (like the AXIS build) would be nothing more than a nuisance.
protected Handler
workHandler
The Handler that will do the actual work of handeling the fault.
Constructors Summary
public FaultableHandler(Handler workHandler)
Create a new FaultHandler.

param
workHandler the Handler we're going to wrap with Fault semantics.


                        
      
    
        this.workHandler = workHandler;
    
Methods Summary
public booleancanHandleBlock(javax.xml.namespace.QName qname)

        return( workHandler.canHandleBlock(qname) );
    
public voidcleanup()

        workHandler.cleanup();
    
public voidinit()

        workHandler.init();
    
public voidinvoke(MessageContext msgContext)
Invokes the specified handler. If there's a fault the appropriate key will be calculated and used to find the fault chain to be invoked. This assumes that the workHandler has caught the exception and already done its fault processing - as needed.

param
msgContext the MessageContext to process
throws
AxisFault if anything goes terminally wrong

        log.debug("Enter: FaultableHandler::invoke");
        try {
            workHandler.invoke( msgContext );
        }
        catch( Exception e ) {
            entLog.info(Messages.getMessage("toAxisFault00"), e );
            AxisFault fault = AxisFault.makeFault(e);

//            AxisEngine engine = msgContext.getAxisEngine();

            /** Index off fault code.
             *
             * !!! TODO: This needs to be able to handle searching by faultcode
             * hierarchy, i.e.  "Server.General.*" or "Server.*", with the
             * most specific match winning.
             */
            /*
            QFault   key          = fault.getFaultCode() ;
            Handler  faultHandler = (Handler) faultHandlers.get( key );
            */
            Handler faultHandler = null;

            Hashtable options = getOptions();
            if (options != null) {
                Enumeration enumeration = options.keys();
                while (enumeration.hasMoreElements()) {
                    String s = (String) enumeration.nextElement();
                    if (s.equals("fault-" + fault.getFaultCode().getLocalPart())) {
                        faultHandler = (Handler)options.get(s);
                    }
                }
            }

            if ( faultHandler != null ) {
                /** faultHandler will (re)throw if it's appropriate, but it
                 * might also eat the fault.  Which brings up another issue -
                 * should we have a way to pass the Fault directly to the
                 * faultHandler? Maybe another well-known MessageContext
                 * property?
                 */
                faultHandler.invoke( msgContext );
            } else {
                throw fault;
            }
        }
        log.debug("Exit: FaultableHandler::invoke");
    
public voidonFault(MessageContext msgContext)
Some handler later on has faulted so we need to process the fault.

param
msgContext the context to process

        log.debug("Enter: FaultableHandler::onFault");
        workHandler.onFault( msgContext );
        log.debug("Exit: FaultableHandler::onFault");