use of org.jboss.as.ee.component.InterceptorDescription in project wildfly by wildfly.
the class WeldComponentIntegrationProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
return;
}
final DeploymentUnit topLevelDeployment = getRootDeploymentUnit(deploymentUnit);
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final ServiceName weldBootstrapService = topLevelDeployment.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
final ServiceName weldStartService = topLevelDeployment.getServiceName().append(WeldStartService.SERVICE_NAME);
final ServiceName beanManagerService = ServiceNames.beanManagerServiceName(deploymentUnit);
final Iterable<ComponentIntegrator> componentIntegrators = ServiceLoader.load(ComponentIntegrator.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldComponentIntegrationProcessor.class));
final ComponentInterceptorSupport componentInterceptorSupport = ServiceLoaders.loadSingle(ComponentInterceptorSupport.class, WeldComponentIntegrationProcessor.class).orElse(null);
WeldClassIntrospector.install(deploymentUnit, phaseContext.getServiceTarget());
eeModuleDescription.setDefaultClassIntrospectorServiceName(WeldClassIntrospector.serviceName(deploymentUnit));
for (ComponentDescription component : eeModuleDescription.getComponentDescriptions()) {
final String beanName;
if (isBeanNameRequired(component, componentIntegrators)) {
beanName = component.getComponentName();
} else {
beanName = null;
}
component.getConfigurators().add((context, description, configuration) -> {
//add interceptor to activate the request scope if required
final EjbRequestScopeActivationInterceptor.Factory requestFactory = new EjbRequestScopeActivationInterceptor.Factory(beanManagerService);
for (ViewConfiguration view : configuration.getViews()) {
view.addViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
}
configuration.addTimeoutViewInterceptor(requestFactory, InterceptorOrder.View.CDI_REQUEST_SCOPE);
});
component.getConfigurators().addFirst(new ComponentConfigurator() {
@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
final Class<?> componentClass = configuration.getComponentClass();
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ModuleClassLoader classLoader = module.getClassLoader();
//get the interceptors so they can be injected as well
final Set<Class<?>> interceptorClasses = new HashSet<Class<?>>();
for (InterceptorDescription interceptorDescription : description.getAllInterceptors()) {
try {
interceptorClasses.add(ClassLoadingUtils.loadClass(interceptorDescription.getInterceptorClassName(), module));
} catch (ClassNotFoundException e) {
throw WeldLogger.ROOT_LOGGER.couldNotLoadInterceptorClass(interceptorDescription.getInterceptorClassName(), e);
}
}
addWeldIntegration(componentIntegrators, componentInterceptorSupport, context.getServiceTarget(), configuration, description, componentClass, beanName, weldBootstrapService, weldStartService, beanManagerService, interceptorClasses, classLoader, description.getBeanDeploymentArchiveId());
}
});
}
}
use of org.jboss.as.ee.component.InterceptorDescription in project wildfly by wildfly.
the class EJBContainerInterceptorsViewConfigurator method doConfigure.
private void doConfigure(final DeploymentPhaseContext context, final EJBComponentDescription ejbComponentDescription, final ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final Map<String, List<InterceptorFactory>> userAroundInvokesByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
final Map<String, List<InterceptorFactory>> userAroundTimeoutsByInterceptorClass;
if (ejbComponentDescription.isTimerServiceRequired()) {
userAroundTimeoutsByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
} else {
userAroundTimeoutsByInterceptorClass = null;
}
// info
for (final InterceptorDescription interceptorDescription : ejbComponentDescription.getAllContainerInterceptors()) {
final String interceptorClassName = interceptorDescription.getInterceptorClassName();
final Class<?> intereptorClass;
try {
intereptorClass = ClassLoadingUtils.loadClass(interceptorClassName, module);
} catch (ClassNotFoundException e) {
throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptorClassName);
}
// run the interceptor class (and its super class hierarchy) through the InterceptorClassDescriptionTraversal so that it can
// find the relevant @AroundInvoke/@AroundTimeout methods
final InterceptorClassDescriptionTraversal interceptorClassDescriptionTraversal = new InterceptorClassDescriptionTraversal(intereptorClass, applicationClasses, deploymentUnit, ejbComponentDescription);
interceptorClassDescriptionTraversal.run();
// now that the InterceptorClassDescriptionTraversal has done the relevant processing, keep track of the @AroundInvoke and
// @AroundTimeout methods applicable for this interceptor class, within a map
final List<InterceptorFactory> aroundInvokeInterceptorFactories = interceptorClassDescriptionTraversal.getAroundInvokeInterceptorFactories();
if (aroundInvokeInterceptorFactories != null) {
userAroundInvokesByInterceptorClass.put(interceptorClassName, aroundInvokeInterceptorFactories);
}
if (ejbComponentDescription.isTimerServiceRequired()) {
final List<InterceptorFactory> aroundTimeoutInterceptorFactories = interceptorClassDescriptionTraversal.getAroundTimeoutInterceptorFactories();
if (aroundTimeoutInterceptorFactories != null) {
userAroundTimeoutsByInterceptorClass.put(interceptorClassName, aroundTimeoutInterceptorFactories);
}
}
}
// At this point we have each interceptor class mapped against their corresponding @AroundInvoke/@AroundTimeout InterceptorFactory(s)
// Let's now iterate over all the methods of the EJB view and apply the relevant InterceptorFactory(s) to that method
final List<InterceptorDescription> classLevelContainerInterceptors = ejbComponentDescription.getClassLevelContainerInterceptors();
final Map<MethodIdentifier, List<InterceptorDescription>> methodLevelContainerInterceptors = ejbComponentDescription.getMethodLevelContainerInterceptors();
final List<Method> viewMethods = viewConfiguration.getProxyFactory().getCachedMethods();
for (final Method method : viewMethods) {
final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
final List<InterceptorFactory> aroundInvokesApplicableForMethod = new ArrayList<InterceptorFactory>();
final List<InterceptorFactory> aroundTimeoutsApplicableForMethod = new ArrayList<InterceptorFactory>();
// first add the default interceptors (if not excluded) to the deque
if (!ejbComponentDescription.isExcludeDefaultContainerInterceptors() && !ejbComponentDescription.isExcludeDefaultContainerInterceptors(methodIdentifier)) {
for (final InterceptorDescription interceptorDescription : ejbComponentDescription.getDefaultContainerInterceptors()) {
String interceptorClassName = interceptorDescription.getInterceptorClassName();
final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
if (aroundInvokesOnInterceptor != null) {
aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
}
if (ejbComponentDescription.isTimerServiceRequired()) {
final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
if (aroundTimeoutsOnInterceptor != null) {
aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
}
}
}
}
// now add class level interceptors (if not excluded) to the deque
if (!ejbComponentDescription.isExcludeClassLevelContainerInterceptors(methodIdentifier)) {
for (final InterceptorDescription interceptorDescription : classLevelContainerInterceptors) {
String interceptorClassName = interceptorDescription.getInterceptorClassName();
final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
if (aroundInvokesOnInterceptor != null) {
aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
}
if (ejbComponentDescription.isTimerServiceRequired()) {
final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
if (aroundTimeoutsOnInterceptor != null) {
aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
}
}
}
}
// now add method level interceptors for to the deque so that they are triggered after the class interceptors
final List<InterceptorDescription> interceptorsForMethod = methodLevelContainerInterceptors.get(methodIdentifier);
if (interceptorsForMethod != null) {
for (final InterceptorDescription methodLevelInterceptor : interceptorsForMethod) {
String interceptorClassName = methodLevelInterceptor.getInterceptorClassName();
final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
if (aroundInvokesOnInterceptor != null) {
aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
}
if (ejbComponentDescription.isTimerServiceRequired()) {
final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
if (aroundTimeoutsOnInterceptor != null) {
aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
}
}
}
}
// apply the interceptors to the view's method.
viewConfiguration.addViewInterceptor(method, new UserInterceptorFactory(weaved(aroundInvokesApplicableForMethod), weaved(aroundTimeoutsApplicableForMethod)), InterceptorOrder.View.USER_APP_SPECIFIC_CONTAINER_INTERCEPTORS);
}
}
use of org.jboss.as.ee.component.InterceptorDescription in project wildfly by wildfly.
the class EJBContainerInterceptorsViewConfigurator method configure.
@Override
public void configure(DeploymentPhaseContext deploymentPhaseContext, ComponentConfiguration componentConfiguration, ViewDescription viewDescription, ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException {
final ComponentDescription componentDescription = componentConfiguration.getComponentDescription();
// ideally it should always be an EJBComponentDescription when this view configurator is invoked, but let's just make sure
if (!(componentDescription instanceof EJBComponentDescription)) {
return;
}
final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
// we don't want to waste time processing if there are no container interceptors applicable for the EJB
final Set<InterceptorDescription> allContainerInterceptors = ejbComponentDescription.getAllContainerInterceptors();
if (allContainerInterceptors == null || allContainerInterceptors.isEmpty()) {
return;
}
// do the processing
this.doConfigure(deploymentPhaseContext, ejbComponentDescription, viewConfiguration);
}
Aggregations