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