use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class SessionContextImpl method getMessageContext.
public MessageContext getMessageContext() throws IllegalStateException {
final InterceptorContext invocation = CurrentInvocationContext.get();
final MessageContext context = invocation.getPrivateData(MessageContext.class);
if (context == null) {
throw EjbLogger.ROOT_LOGGER.cannotCall("getMessageContext()", "MessageContext");
}
return context;
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class SessionContextImpl method wasCancelCalled.
public boolean wasCancelCalled() throws IllegalStateException {
final InterceptorContext invocation = CurrentInvocationContext.get();
final CancellationFlag flag = invocation.getPrivateData(CancellationFlag.class);
if (flag == null) {
throw EjbLogger.ROOT_LOGGER.noAsynchronousInvocationInProgress();
}
return flag.isCancelFlagSet();
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class SessionContextImpl method getEJBLocalObject.
public EJBLocalObject getEJBLocalObject() throws IllegalStateException {
AllowedMethodsInformation.checkAllowed(MethodType.GET_EJB_LOCAL_OBJECT);
// to allow override per invocation
final InterceptorContext invocation = CurrentInvocationContext.get();
return getComponent().getEJBLocalObject(invocation);
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class StatefulSessionSynchronizationInterceptorTestCase method testDifferentTx.
/**
* After the bean is accessed within a tx and the tx has committed, the
* association should be gone (and thus it is ready for another tx).
*/
@Test
public void testDifferentTx() throws Exception {
final Interceptor interceptor = new StatefulSessionSynchronizationInterceptor(true);
final InterceptorContext context = new InterceptorContext();
context.setInterceptors(Arrays.asList(noop()));
final StatefulSessionComponent component = mock(StatefulSessionComponent.class);
context.putPrivateData(Component.class, component);
when(component.getAccessTimeout(null)).thenReturn(defaultAccessTimeout());
Cache<SessionID, StatefulSessionComponentInstance> cache = mock(Cache.class);
when(component.getCache()).thenReturn(cache);
final TransactionSynchronizationRegistry transactionSynchronizationRegistry = mock(TransactionSynchronizationRegistry.class);
when(component.getTransactionSynchronizationRegistry()).thenReturn(transactionSynchronizationRegistry);
when(transactionSynchronizationRegistry.getTransactionKey()).thenReturn("TX1");
final List<Synchronization> synchronizations = new LinkedList<Synchronization>();
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Synchronization synchronization = (Synchronization) invocation.getArguments()[0];
synchronizations.add(synchronization);
return null;
}
}).when(transactionSynchronizationRegistry).registerInterposedSynchronization((Synchronization) any());
final StatefulSessionComponentInstance instance = new StatefulSessionComponentInstance(component, org.jboss.invocation.Interceptors.getTerminalInterceptor(), Collections.EMPTY_MAP, Collections.emptyMap());
context.putPrivateData(ComponentInstance.class, instance);
interceptor.processInvocation(context);
// commit
for (Synchronization synchronization : synchronizations) {
synchronization.beforeCompletion();
}
for (Synchronization synchronization : synchronizations) {
synchronization.afterCompletion(Status.STATUS_COMMITTED);
}
synchronizations.clear();
when(transactionSynchronizationRegistry.getTransactionKey()).thenReturn("TX2");
interceptor.processInvocation(context);
}
use of org.jboss.invocation.InterceptorContext in project wildfly by wildfly.
the class BasicComponent method constructComponentInstance.
/**
* Construct the component instance. Upon return, the object instance should have injections and lifecycle
* invocations completed already.
*
*
* @param instance An instance to be wrapped, or null if a new instance should be created
* @return the component instance
*/
protected BasicComponentInstance constructComponentInstance(ManagedReference instance, boolean invokePostConstruct, final Map<Object, Object> context) {
waitForComponentStart();
// create the component instance
final BasicComponentInstance basicComponentInstance = this.instantiateComponentInstance(preDestroyInterceptor, interceptorInstanceMap, context);
if (instance != null) {
basicComponentInstance.setInstanceData(BasicComponentInstance.INSTANCE_KEY, instance);
}
if (invokePostConstruct) {
// now invoke the postconstruct interceptors
final InterceptorContext interceptorContext = new InterceptorContext();
interceptorContext.putPrivateData(Component.class, this);
interceptorContext.putPrivateData(ComponentInstance.class, basicComponentInstance);
interceptorContext.putPrivateData(InvocationType.class, InvocationType.POST_CONSTRUCT);
interceptorContext.setContextData(new HashMap<String, Object>());
try {
postConstructInterceptor.processInvocation(interceptorContext);
} catch (Exception e) {
throw EeLogger.ROOT_LOGGER.componentConstructionFailure(e);
}
}
componentInstanceCreated(basicComponentInstance);
// return the component instance
return basicComponentInstance;
}
Aggregations