Search in sources :

Example 26 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class AsynchronousTask method createBeanInstance.

/**
 * Create a new Session Bean and set Session Context.
 */
private SessionContextImpl createBeanInstance() throws Exception {
    EjbInvocation ejbInv = null;
    try {
        SessionContextImpl context = (SessionContextImpl) createEjbInstanceAndContext();
        Object ejb = context.getEJB();
        Object sessionKey = uuidGenerator.createSessionKey();
        createExtendedEMs(context, sessionKey);
        // Need to do preInvoke because setSessionContext can access JNDI
        ejbInv = super.createEjbInvocation(ejb, context);
        invocationManager.preInvoke(ejbInv);
        // the bean is not allowed to do EJBContext.getEJBObject here
        if (ejb instanceof SessionBean) {
            ((SessionBean) ejb).setSessionContext(context);
        }
        // Perform injection right after where setSessionContext
        // would be called.  This is important since injection methods
        // have the same "operations allowed" permissions as
        // setSessionContext.
        injectEjbInstance(context);
        // Set the timestamp before inserting into bean store, else
        // Recycler might go crazy and remove this bean!
        context.touch();
        // Add the EJB into the session store
        // and get the instanceKey for this EJB instance.
        // XXX The store operation could be avoided for local-only beans.
        sessionBeanCache.put(sessionKey, context);
        context.setInstanceKey(sessionKey);
        if (_logger.isLoggable(TRACE_LEVEL)) {
            _logger.log(TRACE_LEVEL, "[SFSBContainer] Created " + "session: " + sessionKey);
        }
        return context;
    } catch (Exception ex) {
        throw ex;
    } catch (Throwable t) {
        EJBException ejbEx = new EJBException();
        ejbEx.initCause(t);
        throw ejbEx;
    } finally {
        if (ejbInv != null) {
            invocationManager.postInvoke(ejbInv);
        }
    }
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EJBObject(javax.ejb.EJBObject) SessionBean(javax.ejb.SessionBean) EJBException(javax.ejb.EJBException) IllegalLoopbackException(javax.ejb.IllegalLoopbackException) ConcurrentAccessException(javax.ejb.ConcurrentAccessException) RemoveException(javax.ejb.RemoveException) ConcurrentAccessTimeoutException(javax.ejb.ConcurrentAccessTimeoutException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RemoteException(java.rmi.RemoteException) EJBException(javax.ejb.EJBException) BackingStoreException(org.glassfish.ha.store.api.BackingStoreException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(javax.transaction.SystemException) CreateException(javax.ejb.CreateException) NoSuchObjectLocalException(javax.ejb.NoSuchObjectLocalException)

Example 27 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class StatelessSessionContainer method userTransactionMethodsAllowed.

public boolean userTransactionMethodsAllowed(ComponentInvocation inv) {
    boolean utMethodsAllowed = false;
    if (isBeanManagedTran) {
        if (inv instanceof EjbInvocation) {
            EjbInvocation ejbInv = (EjbInvocation) inv;
            EJBContextImpl sc = (EJBContextImpl) ejbInv.context;
            // If Invocation, only ejbRemove not allowed.
            utMethodsAllowed = !sc.isInEjbRemove();
        } else {
            // This will prevent setSessionContext/ejbCreate access
            utMethodsAllowed = false;
        }
    }
    return utMethodsAllowed;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation)

Example 28 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class StatelessSessionContainer method createStatelessEJB.

/**
 * called when an invocation arrives and there are no instances
 * left to deliver the invocation to.
 * Called from SessionContextFactory.create() !
 */
private SessionContextImpl createStatelessEJB() throws CreateException {
    EjbInvocation ejbInv = null;
    SessionContextImpl context;
    try {
        context = (SessionContextImpl) createEjbInstanceAndContext();
        Object ejb = context.getEJB();
        // this allows JNDI lookups from setSessionContext, ejbCreate
        ejbInv = super.createEjbInvocation(ejb, context);
        invocationManager.preInvoke(ejbInv);
        // setSessionContext will be called without a Tx as required
        // by the spec, because the EJBHome.create would have been called
        // after the container suspended any client Tx.
        // setSessionContext is also called before context.setEJBStub
        // because the bean is not allowed to do EJBContext.getEJBObject
        setSessionContext(ejb, context);
        // Perform injection right after where setSessionContext
        // would be called.  This is important since injection methods
        // have the same "operations allowed" permissions as
        // setSessionContext.
        injectEjbInstance(context);
        if (isRemote) {
            if (hasRemoteHomeView) {
                context.setEJBObjectImpl(theEJBObjectImpl);
                context.setEJBStub(theEJBStub);
            }
            if (hasRemoteBusinessView) {
                context.setEJBRemoteBusinessObjectImpl(theRemoteBusinessObjectImpl);
            }
        }
        if (isLocal) {
            if (hasLocalHomeView) {
                context.setEJBLocalObjectImpl(theEJBLocalObjectImpl);
            }
            if (hasLocalBusinessView) {
                context.setEJBLocalBusinessObjectImpl(theEJBLocalBusinessObjectImpl);
            }
            if (hasOptionalLocalBusinessView) {
                context.setOptionalEJBLocalBusinessObjectImpl(theOptionalEJBLocalBusinessObjectImpl);
            }
        }
        // all stateless beans have the same id and same InstanceKey
        context.setInstanceKey(statelessInstanceKey);
        // Call ejbCreate() or @PostConstruct method
        intercept(CallbackType.POST_CONSTRUCT, context);
        // Set the state to POOLED after ejbCreate so that
        // EJBContext methods not allowed will throw exceptions
        context.setState(EJBContextImpl.BeanState.POOLED);
    } catch (Throwable th) {
        _logger.log(Level.SEVERE, "ejb.stateless_ejbcreate_exception", logParams);
        CreateException creEx = new CreateException("Could not create stateless EJB");
        creEx.initCause(th);
        throw creEx;
    } finally {
        if (ejbInv != null) {
            invocationManager.postInvoke(ejbInv);
        }
    }
    context.touch();
    return context;
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) EJBObject(javax.ejb.EJBObject) CreateException(javax.ejb.CreateException)

Example 29 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class WebServiceInvocationHandler method invoke.

public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    try {
        container.onEnteringContainer();
        // NOTE : be careful with "args" parameter.  It is null
        // if method signature has 0 arguments.
        Class methodClass = method.getDeclaringClass();
        if (methodClass == java.lang.Object.class) {
            return InvocationHandlerUtil.invokeJavaObjectMethod(this, method, args);
        }
        Object returnValue = null;
        // Invocation was created earlier in the web service dispatching
        EjbInvocation inv = (EjbInvocation) invManager_.getCurrentInvocation();
        try {
            inv.ejbObject = this;
            // find the right method object on the SIB.
            if (endpoint_.getServiceEndpointInterface().equals(ejbClass_.getName())) {
                // we need to substiture the method object
                method = ejbClass_.getMethod(method.getName(), method.getParameterTypes());
            }
            inv.method = method;
            inv.clientInterface = serviceEndpointIntfClass_;
            inv.invocationInfo = (InvocationInfo) invocationInfoMap_.get(inv.method);
            if (inv.invocationInfo == null) {
                throw new EJBException("Web service Invocation Info lookup failed for " + "method " + inv.method);
            }
            inv.transactionAttribute = inv.invocationInfo.txAttr;
            // special handling of jaxrpc endpoints (identfied by mapping file)
            if (endpoint_.getWebService().hasMappingFile()) {
                if (hasHandlers_) {
                // Handler performed method authorization already
                } else {
                    boolean authorized = container.authorize(inv);
                    if (!authorized) {
                        throw new AccessLocalException("Client not authorized to access " + inv.method);
                    }
                }
            } else if (hasHandlers_) {
                // jaxws enpoint
                // authorization was done in security pipe
                // Now that application handlers have run, do
                // another method lookup and compare the results
                // with the original one. This ensures that the
                // application handlers have not changed
                // which method is invoked.
                Method methodBefore = inv.getWebServiceMethod();
                if (methodBefore != null && !methodBefore.equals(inv.method)) {
                    inv.exception = new UnmarshalException(localStrings.getLocalString("enterprise.webservice.postHandlerMethodMismatch", "Original Method {0} does not match post-handler method {1}", new Object[] { methodBefore, inv.method }));
                    throw inv.exception;
                }
            }
            ComponentContext ctx = container.getContext(inv);
            inv.context = ctx;
            inv.ejb = ctx.getEJB();
            inv.instance = inv.ejb;
            container.preInvokeTx(inv);
            // Enterprise Bean class doesn't necessarily implement
            // web service endpoint interface, so we can't directly
            // dispatch through the given method object.
            Method beanClassMethod = ejbClass_.getMethod(method.getName(), method.getParameterTypes());
            inv.beanMethod = beanClassMethod;
            inv.methodParams = args;
            returnValue = container.intercept(inv);
        } catch (NoSuchMethodException nsme) {
            inv.exception = nsme;
        } catch (InvocationTargetException ite) {
            inv.exception = ite.getCause();
        } catch (Throwable c) {
            inv.exception = c;
        } finally {
            if (inv.ejb != null) {
                // Do post invoke tx processing so that a commit failure
                // will be visible to web service client.
                container.postInvokeTx(inv);
            }
        }
        if (inv.exception != null) {
            if (inv.exception instanceof java.lang.RuntimeException) {
                throw (java.lang.RuntimeException) inv.exception;
            } else if (inv.exception instanceof Exception) {
                throw inv.exception;
            } else {
                EJBException ejbEx = new EJBException();
                ejbEx.initCause(inv.exception);
                throw ejbEx;
            }
        }
        return returnValue;
    } finally {
        container.onLeavingContainer();
    }
}
Also used : ComponentContext(com.sun.ejb.ComponentContext) AccessLocalException(javax.ejb.AccessLocalException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) UnmarshalException(java.rmi.UnmarshalException) AccessLocalException(javax.ejb.AccessLocalException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EJBException(javax.ejb.EJBException) EjbInvocation(com.sun.ejb.EjbInvocation) UnmarshalException(java.rmi.UnmarshalException) EJBException(javax.ejb.EJBException)

Example 30 with EjbInvocation

use of com.sun.ejb.EjbInvocation in project Payara by payara.

the class AbstractSessionContextImpl method wasCancelCalled.

public boolean wasCancelCalled() {
    try {
        ComponentInvocation inv = EjbContainerUtilImpl.getInstance().getCurrentInvocation();
        if ((inv != null) && (inv instanceof EjbInvocation)) {
            EjbInvocation invocation = (EjbInvocation) inv;
            EjbFutureTask task = invocation.getEjbFutureTask();
            if (task == null) {
                throw new IllegalStateException("Must be invoked from an async method");
            }
            if ((invocation.method.getReturnType() == Void.TYPE)) {
                throw new IllegalStateException("Must be invoked from a method with a Future<V> " + "return type");
            }
            return invocation.getWasCancelCalled();
        }
    } catch (Exception e) {
        IllegalStateException ise = new IllegalStateException(e.getMessage());
        ise.initCause(e);
        throw ise;
    }
    throw new IllegalStateException("Attempt to invoke wasCancelCalled from " + "outside an ejb invocation");
}
Also used : EjbInvocation(com.sun.ejb.EjbInvocation) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) EJBException(javax.ejb.EJBException)

Aggregations

EjbInvocation (com.sun.ejb.EjbInvocation)44 EJBException (javax.ejb.EJBException)22 RemoteException (java.rmi.RemoteException)18 CreateException (javax.ejb.CreateException)18 InvocationTargetException (java.lang.reflect.InvocationTargetException)16 NoSuchObjectLocalException (javax.ejb.NoSuchObjectLocalException)16 RemoveException (javax.ejb.RemoveException)16 SystemException (javax.transaction.SystemException)15 EJBObject (javax.ejb.EJBObject)11 IOException (java.io.IOException)9 NotSerializableException (java.io.NotSerializableException)9 ConcurrentAccessException (javax.ejb.ConcurrentAccessException)9 ConcurrentAccessTimeoutException (javax.ejb.ConcurrentAccessTimeoutException)9 IllegalLoopbackException (javax.ejb.IllegalLoopbackException)9 BackingStoreException (org.glassfish.ha.store.api.BackingStoreException)9 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)7 EJBLocalRemoteObject (com.sun.ejb.containers.EJBLocalRemoteObject)6 FinderException (javax.ejb.FinderException)6 NoSuchEntityException (javax.ejb.NoSuchEntityException)6 InvocationInfo (com.sun.ejb.InvocationInfo)4