use of org.apache.openejb.core.interceptor.InterceptorStack in project tomee by apache.
the class SingletonInstanceManager method createInstance.
private Instance createInstance(final ThreadContext callContext, final BeanContext beanContext) throws ApplicationException {
try {
initializeDependencies(beanContext);
final InstanceContext context = beanContext.newInstance();
if (context.getBean() instanceof SessionBean) {
final Operation originalOperation = callContext.getCurrentOperation();
try {
callContext.setCurrentOperation(Operation.CREATE);
final Method create = beanContext.getCreateMethod();
final InterceptorStack ejbCreate = new InterceptorStack(context.getBean(), create, Operation.CREATE, new ArrayList<InterceptorData>(), new HashMap());
ejbCreate.invoke();
} finally {
callContext.setCurrentOperation(originalOperation);
}
}
final ReadWriteLock lock;
if (beanContext.isBeanManagedConcurrency()) {
// Bean-Managed Concurrency
lock = new BeanManagedLock();
} else {
// Container-Managed Concurrency
lock = new ReentrantReadWriteLock();
}
return new Instance(context.getBean(), context.getInterceptors(), context.getCreationalContext(), lock);
} catch (Throwable e) {
if (e instanceof InvocationTargetException) {
e = ((InvocationTargetException) e).getTargetException();
}
final String t = "The bean instance " + beanContext.getDeploymentID() + " threw a system exception:" + e;
logger.error(t, e);
throw new ApplicationException(new NoSuchEJBException("Singleton failed to initialize").initCause(e));
}
}
use of org.apache.openejb.core.interceptor.InterceptorStack in project tomee by apache.
the class StatelessContainer method invokeWebService.
private Object invokeWebService(final Object[] args, final BeanContext beanContext, final Method runMethod, final Instance instance) throws Exception {
if (args.length < 2) {
throw new IllegalArgumentException("WebService calls must follow format {messageContext, interceptor, [arg...]}.");
}
final Object messageContext = args[0];
// This object will be used as an interceptor in the stack and will be responsible
// for unmarshalling the soap message parts into an argument list that will be
// used for the actual method invocation.
//
// We just need to make it an interceptor in the OpenEJB sense and tack it on the end
// of our stack.
final Object interceptor = args[1];
final Class<?> interceptorClass = interceptor.getClass();
// Add the webservice interceptor to the list of interceptor instances
final Map<String, Object> interceptors = new HashMap<String, Object>(instance.interceptors);
interceptors.put(interceptor.getClass().getName(), interceptor);
// Create an InterceptorData for the webservice interceptor to the list of interceptorDatas for this method
final List<InterceptorData> interceptorDatas = new ArrayList<InterceptorData>();
final InterceptorData providerData = new InterceptorData(interceptorClass);
providerData.getAroundInvoke().addAll(retrieveAroundInvokes(interceptorClass));
interceptorDatas.add(0, providerData);
interceptorDatas.addAll(beanContext.getMethodInterceptors(runMethod));
final InterceptorStack interceptorStack = new InterceptorStack(instance.bean, runMethod, Operation.BUSINESS_WS, interceptorDatas, interceptors);
final Object[] params = new Object[runMethod.getParameterTypes().length];
final ThreadContext threadContext = ThreadContext.getThreadContext();
Object returnValue = null;
if (messageContext instanceof javax.xml.rpc.handler.MessageContext) {
threadContext.set(javax.xml.rpc.handler.MessageContext.class, (javax.xml.rpc.handler.MessageContext) messageContext);
returnValue = interceptorStack.invoke((javax.xml.rpc.handler.MessageContext) messageContext, params);
} else if (messageContext instanceof javax.xml.ws.handler.MessageContext) {
AddressingSupport wsaSupport = NoAddressingSupport.INSTANCE;
for (int i = 2; i < args.length; i++) {
if (args[i] instanceof AddressingSupport) {
wsaSupport = (AddressingSupport) args[i];
}
}
threadContext.set(AddressingSupport.class, wsaSupport);
threadContext.set(javax.xml.ws.handler.MessageContext.class, (javax.xml.ws.handler.MessageContext) messageContext);
returnValue = interceptorStack.invoke((javax.xml.ws.handler.MessageContext) messageContext, params);
}
return returnValue;
}
Aggregations