FileDocCategorySizeDatePackage
EjbContainerPreHandler.javaAPI DocGlassfish v2 API4865Fri May 04 22:36:10 BST 2007com.sun.enterprise.webservice

EjbContainerPreHandler

public class EjbContainerPreHandler extends javax.xml.rpc.handler.GenericHandler
This handler is inserted first in the handler chain for an ejb web service endpoint. It performs security authorization before any of the application handlers are invoked, as required by JSR 109.
author
Kenneth Saks

Fields Summary
private static Logger
logger
private WsUtil
wsUtil
Constructors Summary
public EjbContainerPreHandler()


      
Methods Summary
public javax.xml.namespace.QName[]getHeaders()

        return new QName[0];
    
public booleanhandleRequest(javax.xml.rpc.handler.MessageContext context)

        Invocation inv = null;
        Container container = null;

        try {

            Switch theSwitch = Switch.getSwitch();
            InvocationManager invManager = theSwitch.getInvocationManager();
            inv = (Invocation) invManager.getCurrentInvocation();
            container = (Container) inv.container;

            inv.method = wsUtil.getInvMethod(inv.getWebServiceTie(), context);

            // Result can be null for some error cases.  This will be
            // handled by jaxrpc runtime so we don't treat it as an exception.
            if( inv.method != null ) {
                inv.setWebServiceMethod(inv.method);
               
                if ( !container.authorize(inv) ) {
                    inv.exception = new Exception
                        ("Client not authorized for invocation of " 
                         + inv.method);
                }
            } else {
                inv.setWebServiceMethod(null);
            }
        } catch(Exception e) {
            String errorMsg = "Error unmarshalling method " + 
                ( (container != null ) ?
                  "for ejb " + container.getEjbDescriptor().getName() : 
                  "" );
	    //issue 2422 -- UnmarshalException.initCause always
            //throws IllegalStateException.  Need to use 2-arg ctor.
            inv.exception = new UnmarshalException(errorMsg, e);
        }
        
        if( inv.exception != null ) {
            logger.log(Level.WARNING, "preEjbHandlerError", inv.exception);
            wsUtil.throwSOAPFaultException(inv.exception.getMessage(),
                                           context);
        }

        return true;