use of org.jboss.as.ee.component.Component in project wildfly by wildfly.
the class EjbIIOPTransactionInterceptor method processInvocation.
@Override
public Object processInvocation(final InterceptorContext invocation) throws Exception {
// Do we have a foreign transaction context?
Transaction tx = TxServerInterceptor.getCurrentTransaction();
if (tx instanceof ForeignTransaction) {
final EJBComponent component = (EJBComponent) invocation.getPrivateData(Component.class);
//for timer invocations there is no view, so the methodInf is attached directly
//to the context. Otherwise we retrieve it from the invoked view
MethodIntf methodIntf = invocation.getPrivateData(MethodIntf.class);
if (methodIntf == null) {
final ComponentView componentView = invocation.getPrivateData(ComponentView.class);
if (componentView != null) {
methodIntf = componentView.getPrivateData(MethodIntf.class);
} else {
methodIntf = MethodIntf.BEAN;
}
}
final TransactionAttributeType attr = component.getTransactionAttributeType(methodIntf, invocation.getMethod());
if (attr != TransactionAttributeType.NOT_SUPPORTED && attr != TransactionAttributeType.REQUIRES_NEW) {
throw EjbLogger.ROOT_LOGGER.transactionPropagationNotSupported();
}
}
return invocation.proceed();
}
use of org.jboss.as.ee.component.Component in project wildfly by wildfly.
the class StatefulRemoveInterceptor method processInvocation.
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
final Component component = context.getPrivateData(Component.class);
//if a session bean is participating in a transaction, it
//is an error for a client to invoke the remove method
//on the session object's home or component interface.
final ComponentView view = context.getPrivateData(ComponentView.class);
if (view != null) {
Ejb2xViewType viewType = view.getPrivateData(Ejb2xViewType.class);
if (viewType != null) {
//this means it is an EJB 2.x view
//which is not allowed to remove while enrolled in a TX
final StatefulTransactionMarker marker = context.getPrivateData(StatefulTransactionMarker.class);
if (marker != null && !marker.isFirstInvocation()) {
throw EjbLogger.ROOT_LOGGER.cannotRemoveWhileParticipatingInTransaction();
}
}
}
// just log a WARN and throw back the original exception
if (component instanceof StatefulSessionComponent == false) {
throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, StatefulSessionComponent.class);
}
final StatefulSessionComponent statefulComponent = (StatefulSessionComponent) component;
Object invocationResult = null;
try {
// proceed
invocationResult = context.proceed();
} catch (Exception e) {
// then just throw back the exception and don't remove the session instance.
if (this.isApplicationException(statefulComponent, e.getClass(), context.getMethod()) && this.retainIfException) {
throw e;
}
// otherwise, just remove it and throw back the original exception
final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
final SessionID sessionId = statefulComponentInstance.getId();
statefulComponent.removeSession(sessionId);
throw e;
}
final StatefulSessionComponentInstance statefulComponentInstance = (StatefulSessionComponentInstance) context.getPrivateData(ComponentInstance.class);
final SessionID sessionId = statefulComponentInstance.getId();
// just remove the session because of a call to @Remove method
statefulComponent.removeSession(sessionId);
// return the invocation result
return invocationResult;
}
use of org.jboss.as.ee.component.Component in project wildfly by wildfly.
the class NonFunctionalTimerService method assertInvocationAllowed.
private void assertInvocationAllowed() {
AllowedMethodsInformation.checkAllowed(MethodType.TIMER_SERVICE_METHOD);
final InterceptorContext currentInvocationContext = CurrentInvocationContext.get();
if (currentInvocationContext == null) {
return;
}
// If the method in current invocation context is null,
// then it represents a lifecycle callback invocation
Method invokedMethod = currentInvocationContext.getMethod();
if (invokedMethod == null) {
// it's a lifecycle callback
Component component = currentInvocationContext.getPrivateData(Component.class);
if (!(component instanceof SingletonComponent)) {
throw EjbLogger.EJB3_TIMER_LOGGER.failToInvokeTimerServiceDoLifecycle();
}
}
}
use of org.jboss.as.ee.component.Component in project wildfly by wildfly.
the class AssociationImpl method receiveSessionOpenRequest.
@Override
@NotNull
public CancelHandle receiveSessionOpenRequest(@NotNull final SessionOpenRequest sessionOpenRequest) {
final EJBIdentifier ejbIdentifier = sessionOpenRequest.getEJBIdentifier();
final String appName = ejbIdentifier.getAppName();
final String moduleName = ejbIdentifier.getModuleName();
final String beanName = ejbIdentifier.getBeanName();
final String distinctName = ejbIdentifier.getDistinctName();
final EjbDeploymentInformation ejbDeploymentInformation = findEJB(appName, moduleName, distinctName, beanName);
if (ejbDeploymentInformation == null) {
sessionOpenRequest.writeNoSuchEJB();
return CancelHandle.NULL;
}
final Component component = ejbDeploymentInformation.getEjbComponent();
if (!(component instanceof StatefulSessionComponent)) {
sessionOpenRequest.writeNotStateful();
return CancelHandle.NULL;
}
final StatefulSessionComponent statefulSessionComponent = (StatefulSessionComponent) component;
// generate the session id and write out the response, possibly on a separate thread
final AtomicBoolean cancelled = new AtomicBoolean();
Runnable runnable = () -> {
if (cancelled.get()) {
sessionOpenRequest.writeCancelResponse();
return;
}
final SessionID sessionID;
try {
sessionID = statefulSessionComponent.createSessionRemote();
} catch (Exception t) {
EjbLogger.REMOTE_LOGGER.exceptionGeneratingSessionId(t, statefulSessionComponent.getComponentName(), ejbIdentifier);
sessionOpenRequest.writeException(t);
return;
}
sessionOpenRequest.convertToStateful(sessionID);
};
execute(sessionOpenRequest, runnable, false);
return ignored -> cancelled.set(true);
}
use of org.jboss.as.ee.component.Component in project wildfly by wildfly.
the class JaccInterceptor method processInvocation.
@Override
public Object processInvocation(InterceptorContext context) throws Exception {
Component component = context.getPrivateData(Component.class);
final SecurityDomain securityDomain = context.getPrivateData(SecurityDomain.class);
Assert.checkNotNullParam("securityDomain", securityDomain);
final SecurityIdentity currentIdentity = securityDomain.getCurrentSecurityIdentity();
if (component instanceof EJBComponent == false) {
throw EjbLogger.ROOT_LOGGER.unexpectedComponent(component, EJBComponent.class);
}
Method invokedMethod = context.getMethod();
ComponentView componentView = context.getPrivateData(ComponentView.class);
String viewClassOfInvokedMethod = componentView.getViewClass().getName();
// shouldn't really happen if the interceptor was setup correctly. But let's be safe and do a check
if (!viewClassName.equals(viewClassOfInvokedMethod) || !viewMethod.equals(invokedMethod)) {
throw EjbLogger.ROOT_LOGGER.failProcessInvocation(getClass().getName(), invokedMethod, viewClassOfInvokedMethod, viewMethod, viewClassName);
}
EJBComponent ejbComponent = (EJBComponent) component;
if (WildFlySecurityManager.isChecking()) {
try {
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
hasPermission(ejbComponent, componentView, invokedMethod, currentIdentity);
return null;
});
} catch (PrivilegedActionException e) {
throw e.getException();
}
} else {
hasPermission(ejbComponent, componentView, invokedMethod, currentIdentity);
}
// successful authorization, let the invocation proceed
return context.proceed();
}
Aggregations