Search in sources :

Example 66 with BeanContext

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

the class StatelessInstanceManager method freeInstance.

@SuppressWarnings("unchecked")
private void freeInstance(final ThreadContext callContext, final Instance instance) {
    try {
        callContext.setCurrentOperation(Operation.PRE_DESTROY);
        final BeanContext beanContext = callContext.getBeanContext();
        final Method remove = instance.bean instanceof SessionBean ? removeSessionBeanMethod : null;
        final List<InterceptorData> callbackInterceptors = beanContext.getCallbackInterceptors();
        final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, remove, Operation.PRE_DESTROY, callbackInterceptors, instance.interceptors);
        final CdiEjbBean<Object> bean = beanContext.get(CdiEjbBean.class);
        if (bean != null) {
            // TODO: see if it should be called before or after next call
            bean.getInjectionTarget().preDestroy(instance.bean);
        }
        interceptorStack.invoke();
        if (instance.creationalContext != null) {
            instance.creationalContext.release();
        }
    } catch (final Throwable re) {
        logger.error("The bean instance " + instance + " threw a system exception:" + re, re);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData) InterceptorStack(org.apache.openejb.core.interceptor.InterceptorStack) Method(java.lang.reflect.Method) SessionBean(javax.ejb.SessionBean)

Example 67 with BeanContext

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

the class StatelessInstanceManager method poolInstance.

/**
 * All instances are removed from the pool in getInstance(...).  They are only
 * returned by the StatelessContainer via this method under two circumstances.
 *
 * 1.  The business method returns normally
 * 2.  The business method throws an application exception
 *
 * Instances are not returned to the pool if the business method threw a system
 * exception.
 *
 * @param callContext ThreadContext
 * @param bean        Object
 * @throws OpenEJBException
 */
public void poolInstance(final ThreadContext callContext, final Object bean) throws OpenEJBException {
    if (bean == null) {
        throw new SystemException("Invalid arguments");
    }
    final Instance instance = Instance.class.cast(bean);
    final BeanContext beanContext = callContext.getBeanContext();
    final Data data = (Data) beanContext.getContainerData();
    final Pool<Instance> pool = data.getPool();
    if (instance.getPoolEntry() != null) {
        pool.push(instance.getPoolEntry());
    } else {
        pool.push(instance);
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) SystemException(org.apache.openejb.SystemException) InterceptorInstance(org.apache.openejb.core.interceptor.InterceptorInstance) InterceptorData(org.apache.openejb.core.interceptor.InterceptorData)

Example 68 with BeanContext

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

the class ApplicationComposers method enrich.

public void enrich(final Object inputTestInstance) throws org.apache.openejb.OpenEJBException {
    final BeanContext context = SystemInstance.get().getComponent(ContainerSystem.class).getBeanContext(inputTestInstance.getClass());
    enrich(inputTestInstance, context);
}
Also used : ContainerSystem(org.apache.openejb.spi.ContainerSystem) BeanContext(org.apache.openejb.BeanContext)

Example 69 with BeanContext

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

the class JaxWsInvocationTest method testWsInvocations.

public void testWsInvocations() throws Exception {
    System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, InitContextFactory.class.getName());
    final ConfigurationFactory config = new ConfigurationFactory();
    final Assembler assembler = new Assembler();
    assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
    assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
    assembler.createSecurityService(config.configureService(SecurityServiceInfo.class, "PseudoSecurityService", null, "PseudoSecurityService", null));
    assembler.createContainer(config.configureService(StatelessSessionContainerInfo.class));
    final EjbJarInfo ejbJar = config.configureApplication(buildTestApp());
    assembler.createApplication(ejbJar);
    final ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class);
    final BeanContext beanContext = containerSystem.getBeanContext("EchoBean");
    assertNotNull(beanContext);
    assertEquals("ServiceEndpointInterface", EchoServiceEndpoint.class, beanContext.getServiceEndpointInterface());
    // OK, Now let's fake a web serivce invocation coming from any random
    // web service provider.  The web serivce provider needs supply
    // the MessageContext and an interceptor to do the marshalling as
    // the arguments of the standard container.invoke signature.
    // So let's create a fake message context.
    final MessageContext messageContext = new FakeMessageContext();
    // Now let's create a fake interceptor as would be supplied by the
    // web service provider.  Instead of writing "fake" marshalling
    // code that would pull the arguments from the soap message, we'll
    // just give it the argument values directly.
    final Object wsProviderInterceptor = new FakeWsProviderInterceptor("Hello world");
    // Ok, now we have the two arguments expected on a JAX-RPC Web Service
    // invocation as per the OpenEJB-specific agreement between OpenEJB
    // and the Web Service Provider
    final Object[] args = new Object[] { messageContext, wsProviderInterceptor };
    // Let's grab the container as the Web Service Provider would do and
    // perform an invocation
    final RpcContainer container = (RpcContainer) beanContext.getContainer();
    final Method echoMethod = EchoServiceEndpoint.class.getMethod("echo", String.class);
    final String value = (String) container.invoke("EchoBean", InterfaceType.SERVICE_ENDPOINT, echoMethod.getDeclaringClass(), echoMethod, args, null);
    assertCalls(Call.values());
    calls.clear();
    assertEquals("Hello world", value);
}
Also used : StatelessSessionContainerInfo(org.apache.openejb.assembler.classic.StatelessSessionContainerInfo) ContainerSystem(org.apache.openejb.spi.ContainerSystem) InitContextFactory(org.apache.openejb.core.ivm.naming.InitContextFactory) Method(java.lang.reflect.Method) ProxyFactoryInfo(org.apache.openejb.assembler.classic.ProxyFactoryInfo) BeanContext(org.apache.openejb.BeanContext) RpcContainer(org.apache.openejb.RpcContainer) TransactionServiceInfo(org.apache.openejb.assembler.classic.TransactionServiceInfo) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) Assembler(org.apache.openejb.assembler.classic.Assembler) MessageContext(javax.xml.ws.handler.MessageContext) SecurityServiceInfo(org.apache.openejb.assembler.classic.SecurityServiceInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 70 with BeanContext

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

the class TomcatWebAppBuilder method eagerInitOfLocalBeanProxies.

private static void eagerInitOfLocalBeanProxies(final Collection<BeanContext> beans, final ClassLoader classLoader) {
    for (final BeanContext deployment : beans) {
        if (deployment.isLocalbean() && !deployment.isDynamicallyImplemented()) {
            // init proxy eagerly otherwise deserialization of serialized object can't work
            final List<Class> interfaces = new ArrayList<>(2);
            interfaces.add(Serializable.class);
            interfaces.add(IntraVmProxy.class);
            final BeanType type = deployment.getComponentType();
            if (BeanType.STATEFUL.equals(type) || BeanType.MANAGED.equals(type)) {
                interfaces.add(BeanContext.Removable.class);
            }
            try {
                LocalBeanProxyFactory.createProxy(deployment.getBeanClass(), classLoader, interfaces.toArray(new Class<?>[interfaces.size()]));
            } catch (final Exception e) {
            // no-op: as before
            }
        }
    }
}
Also used : BeanContext(org.apache.openejb.BeanContext) BeanType(org.apache.openejb.BeanType) ArrayList(java.util.ArrayList) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException)

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