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);
}
}
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);
}
}
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);
}
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);
}
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
}
}
}
}
Aggregations