Search in sources :

Example 96 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class StatelessContainer method _invoke.

@SuppressWarnings("ThrowFromFinallyBlock")
private Object _invoke(final Method callMethod, final Method runMethod, final Object[] args, final Instance instance, final ThreadContext callContext, final InterfaceType type) throws OpenEJBException {
    final BeanContext beanContext = callContext.getBeanContext();
    final TransactionPolicy txPolicy = createTransactionPolicy(beanContext.getTransactionType(callMethod, type), callContext);
    Object returnValue = null;
    try {
        if (type == InterfaceType.SERVICE_ENDPOINT) {
            callContext.setCurrentOperation(Operation.BUSINESS_WS);
            returnValue = invokeWebService(args, beanContext, runMethod, instance);
        } else {
            final List<InterceptorData> interceptors = beanContext.getMethodInterceptors(runMethod);
            final Operation operation = type == InterfaceType.TIMEOUT ? Operation.TIMEOUT : Operation.BUSINESS;
            final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, operation, interceptors, instance.interceptors);
            returnValue = interceptorStack.invoke(args);
        }
    } catch (final Throwable re) {
        // handle reflection exception
        final ExceptionType exceptionType = beanContext.getExceptionType(re);
        if (exceptionType == ExceptionType.SYSTEM) {
            /* System Exception ****************************/
            // The bean instance is not put into the pool via instanceManager.poolInstance
            // and therefore the instance will be garbage collected and destroyed.
            // In case of StrictPooling flag being set to true we also release the semaphore
            // in the discardInstance method of the instanceManager.
            callContext.setDiscardInstance(true);
            handleSystemException(txPolicy, re, callContext);
        } else {
            /* Application Exception ***********************/
            handleApplicationException(txPolicy, re, exceptionType == ExceptionType.APPLICATION_ROLLBACK);
        }
    } finally {
        try {
            afterInvoke(txPolicy, callContext);
        } catch (final SystemException | RuntimeException e) {
            callContext.setDiscardInstance(true);
            throw e;
        }
    }
    return returnValue;
}
Also used : BeanContext(org.apache.openejb.BeanContext) ExceptionType(org.apache.openejb.core.ExceptionType) EjbTransactionUtil.handleSystemException(org.apache.openejb.core.transaction.EjbTransactionUtil.handleSystemException) SystemException(org.apache.openejb.SystemException) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) TransactionPolicy(org.apache.openejb.core.transaction.TransactionPolicy) EjbTransactionUtil.createTransactionPolicy(org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy) Operation(org.apache.openejb.core.Operation)

Example 97 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class AccessTimeoutTest method loadAttributes.

private void loadAttributes(final EjbJarInfo ejbJarInfo, final String deploymentId) {
    final ContainerSystem system = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = system.getBeanContext(deploymentId);
    final List<MethodConcurrencyInfo> lockInfos = new ArrayList<>();
    final List<MethodConcurrencyInfo> accessTimeoutInfos = new ArrayList<>();
    MethodConcurrencyBuilder.normalize(ejbJarInfo.methodConcurrency, lockInfos, accessTimeoutInfos);
    attributes = MethodInfoUtil.resolveAttributes(accessTimeoutInfos, beanContext);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) ArrayList(java.util.ArrayList)

Example 98 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class AppNamingReadOnlyTest method testReadOnlyAppNamingContext.

public void testReadOnlyAppNamingContext() throws SystemException, URISyntaxException {
    String originalValue = System.getProperty(Assembler.FORCE_READ_ONLY_APP_NAMING);
    System.setProperty(Assembler.FORCE_READ_ONLY_APP_NAMING, Boolean.TRUE.toString());
    try {
        List<BeanContext> mockBeanContextsList = getMockBeanContextsList();
        Assembler assembler = new Assembler();
        assembler.setAppNamingContextReadOnly(mockBeanContextsList);
        Context beanNamingContext = mockBeanContextsList.get(0).getJndiContext();
        // this test is not intended to test read-only behavior (null/exception); it should check whether naming context is marked as read only
        try {
            Context subContext = beanNamingContext.createSubcontext("sub");
            assertNull(subContext);
        } catch (OperationNotSupportedException e) {
        // ok
        } catch (NamingException e) {
            throw new AssertionError();
        }
    } finally {
        if (originalValue == null) {
            System.clearProperty(Assembler.FORCE_READ_ONLY_APP_NAMING);
        } else {
            System.setProperty(Assembler.FORCE_READ_ONLY_APP_NAMING, originalValue);
        }
        SystemInstance.reset();
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) ModuleContext(org.apache.openejb.ModuleContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) AppContext(org.apache.openejb.AppContext) Context(javax.naming.Context) OperationNotSupportedException(javax.naming.OperationNotSupportedException) BeanContext(org.apache.openejb.BeanContext) NamingException(javax.naming.NamingException)

Example 99 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class StatefulUserTransaction method begin.

public void begin() throws NotSupportedException, SystemException {
    userTransaction.begin();
    // get the callContext
    final ThreadContext callContext = ThreadContext.getThreadContext();
    if (callContext == null) {
        // someone is using the user transaction out side of the component
        return;
    }
    // get the deployment info
    final BeanContext beanContext = callContext.getBeanContext();
    if (beanContext.getComponentType() != BeanType.STATEFUL) {
        // some other non-stateful ejb is using our user transaction
        return;
    }
    // get the primary key
    final Object primaryKey = callContext.getPrimaryKey();
    if (primaryKey == null) {
        // is is not a bean method
        return;
    }
    jtaEntityManagerRegistry.transactionStarted((String) beanContext.getDeploymentID(), primaryKey);
}
Also used : BeanContext(org.apache.openejb.BeanContext) ThreadContext(org.apache.openejb.core.ThreadContext)

Example 100 with BeanContext

use of org.apache.openejb.BeanContext in project tomee by apache.

the class TimerData method doReadObject.

protected void doReadObject(final ObjectInputStream in) throws IOException {
    id = in.readLong();
    deploymentId = in.readUTF();
    persistent = in.readBoolean();
    autoScheduled = in.readBoolean();
    try {
        timer = (Timer) in.readObject();
        primaryKey = in.readObject();
        timerService = (EjbTimerServiceImpl) in.readObject();
        info = in.readObject();
        trigger = AbstractTrigger.class.cast(in.readObject());
    } catch (final ClassNotFoundException e) {
        throw new IOException(e);
    }
    final String mtd = in.readUTF();
    final BeanContext beanContext = SystemInstance.get().getComponent(ContainerSystem.class).getBeanContext(deploymentId);
    scheduler = timerService.getScheduler();
    for (final Iterator<Map.Entry<Method, MethodContext>> it = beanContext.iteratorMethodContext(); it.hasNext(); ) {
        final MethodContext methodContext = it.next().getValue();
        /* this doesn't work in all cases
            if (methodContext.getSchedules().isEmpty()) {
                continue;
            }
            */
        final Method method = methodContext.getBeanMethod();
        if (method != null && method.getName().equals(mtd)) {
            // maybe we should check parameters too
            setTimeoutMethod(method);
            break;
        }
    }
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext) AbstractTrigger(org.apache.openejb.quartz.impl.triggers.AbstractTrigger) MethodContext(org.apache.openejb.MethodContext) IOException(java.io.IOException) Method(java.lang.reflect.Method)

Aggregations

BeanContext (org.apache.openejb.BeanContext)198 OpenEJBException (org.apache.openejb.OpenEJBException)40 ThreadContext (org.apache.openejb.core.ThreadContext)40 Method (java.lang.reflect.Method)38 ContainerSystem (org.apache.openejb.spi.ContainerSystem)28 ArrayList (java.util.ArrayList)27 AppContext (org.apache.openejb.AppContext)26 TransactionPolicy (org.apache.openejb.core.transaction.TransactionPolicy)26 NamingException (javax.naming.NamingException)24 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)23 Context (javax.naming.Context)22 ApplicationException (org.apache.openejb.ApplicationException)20 HashMap (java.util.HashMap)19 EJBLocalObject (javax.ejb.EJBLocalObject)18 EJBObject (javax.ejb.EJBObject)18 SystemException (org.apache.openejb.SystemException)18 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)17 ModuleContext (org.apache.openejb.ModuleContext)16 EjbTransactionUtil.createTransactionPolicy (org.apache.openejb.core.transaction.EjbTransactionUtil.createTransactionPolicy)16 FinderException (javax.ejb.FinderException)14