use of org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription in project wildfly by wildfly.
the class ManagedBeanAnnotationProcessor method deploy.
/**
* Check the deployment annotation index for all classes with the @ManagedBean annotation. For each class with the
* annotation, collect all the required information to create a managed bean instance, and attach it to the context.
*
* @param phaseContext the deployment unit context
* @throws DeploymentUnitProcessingException
*/
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEResourceReferenceProcessorRegistry registry = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.RESOURCE_REFERENCE_PROCESSOR_REGISTRY);
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
if (compositeIndex == null) {
return;
}
final List<AnnotationInstance> instances = compositeIndex.getAnnotations(MANAGED_BEAN_ANNOTATION_NAME);
if (instances == null || instances.isEmpty()) {
return;
}
for (AnnotationInstance instance : instances) {
AnnotationTarget target = instance.target();
if (!(target instanceof ClassInfo)) {
throw EeLogger.ROOT_LOGGER.classOnlyAnnotation("@ManagedBean", target);
}
final ClassInfo classInfo = (ClassInfo) target;
// skip if it's not a valid managed bean class
if (!assertManagedBeanClassValidity(classInfo)) {
continue;
}
final String beanClassName = classInfo.name().toString();
// Get the managed bean name from the annotation
final AnnotationValue nameValue = instance.value();
final String beanName = (nameValue == null || nameValue.asString().isEmpty()) ? beanClassName : replacer.replaceProperties(nameValue.asString());
final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
// Add the view
ViewDescription viewDescription = new ViewDescription(componentDescription, beanClassName);
viewDescription.getConfigurators().addFirst(new ViewConfigurator() {
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
// Add MB association interceptors
configuration.addClientPostConstructInterceptor(ManagedBeanCreateInterceptor.FACTORY, InterceptorOrder.ClientPostConstruct.INSTANCE_CREATE);
final ClassLoader classLoader = componentConfiguration.getModuleClassLoader();
configuration.addViewInterceptor(AccessCheckingInterceptor.getFactory(), InterceptorOrder.View.CHECKING_INTERCEPTOR);
configuration.addViewInterceptor(new ImmediateInterceptorFactory(new ContextClassLoaderInterceptor(classLoader)), InterceptorOrder.View.TCCL_INTERCEPTOR);
}
});
viewDescription.getBindingNames().addAll(Arrays.asList("java:module/" + beanName, "java:app/" + moduleDescription.getModuleName() + "/" + beanName));
componentDescription.getViews().add(viewDescription);
moduleDescription.addComponent(componentDescription);
// register an EEResourceReferenceProcessor which can process @Resource references to this managed bean.
registry.registerResourceReferenceProcessor(new ManagedBeanResourceReferenceProcessor(beanClassName));
}
}
use of org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription in project wildfly by wildfly.
the class EjbComponentIntegrator method integrate.
@Override
public boolean integrate(ServiceName beanManagerServiceName, ComponentConfiguration configuration, ComponentDescription description, ServiceBuilder<?> weldComponentServiceBuilder, Supplier<ServiceName> bindingServiceNameSupplier, DefaultInterceptorIntegrationAction integrationAction, ComponentInterceptorSupport interceptorSupport) {
if (description instanceof EJBComponentDescription) {
ServiceName bindingServiceName = bindingServiceNameSupplier.get();
integrationAction.perform(bindingServiceName);
if (description.isPassivationApplicable()) {
configuration.addPrePassivateInterceptor(factory(InterceptionType.PRE_PASSIVATE, weldComponentServiceBuilder, bindingServiceName, interceptorSupport), InterceptorOrder.ComponentPassivation.CDI_INTERCEPTORS);
configuration.addPostActivateInterceptor(factory(InterceptionType.POST_ACTIVATE, weldComponentServiceBuilder, bindingServiceName, interceptorSupport), InterceptorOrder.ComponentPassivation.CDI_INTERCEPTORS);
}
if (description instanceof StatefulComponentDescription) {
// add a context key for weld interceptor replication
configuration.getInterceptorContextKeys().add(SerializedCdiInterceptorsKey.class);
}
return true;
} else if (description instanceof ManagedBeanComponentDescription) {
integrationAction.perform(bindingServiceNameSupplier.get());
return true;
}
return false;
}
use of org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription in project wildfly by wildfly.
the class JaxrsComponentDeployer method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
if (module == null) {
return;
}
final ResteasyDeploymentData resteasy = deploymentUnit.getAttachment(JaxrsAttachments.RESTEASY_DEPLOYMENT_DATA);
if (resteasy == null) {
return;
}
// Set up the context for managed threads
phaseContext.getDeploymentUnit().addToAttachmentList(Attachments.ADDITIONAL_FACTORIES, ResteasyContextHandleFactory.INSTANCE);
// right now I only support resources
if (!resteasy.isScanResources())
return;
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
if (moduleDescription == null) {
return;
}
final ClassLoader loader = module.getClassLoader();
final CapabilityServiceSupport support = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.CAPABILITY_SERVICE_SUPPORT);
boolean partOfWeldDeployment = false;
if (support.hasCapability(WELD_CAPABILITY_NAME)) {
partOfWeldDeployment = support.getOptionalCapabilityRuntimeAPI(WELD_CAPABILITY_NAME, WeldCapability.class).get().isPartOfWeldDeployment(deploymentUnit);
}
for (final ComponentDescription component : moduleDescription.getComponentDescriptions()) {
Class<?> componentClass = null;
try {
componentClass = loader.loadClass(component.getComponentClassName());
} catch (ClassNotFoundException e) {
throw new DeploymentUnitProcessingException(e);
}
if (!GetRestful.isRootResource(componentClass))
continue;
if (isInstanceOf(component, SESSION_BEAN_DESCRIPTION_CLASS_NAME)) {
if (isInstanceOf(component, STATEFUL_SESSION_BEAN_DESCRIPTION_CLASS_NAME)) {
// using SFSB's as Jakarta RESTful Web Services endpoints is not recommended, but if people really want to do it they can
JAXRS_LOGGER.debugf("Stateful session bean %s is being used as a Jakarta RESTful Web Services endpoint, this is not recommended", component.getComponentName());
if (partOfWeldDeployment) {
// if possible just let CDI handle the integration
continue;
}
}
Class<?>[] jaxrsType = GetRestful.getSubResourceClasses(componentClass);
final String jndiName;
if (component.getViews().size() == 1) {
// only 1 view, just use the simple JNDI name
jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
} else {
boolean found = false;
String foundType = null;
for (final ViewDescription view : component.getViews()) {
for (Class<?> subResource : jaxrsType) {
if (view.getViewClassName().equals(subResource.getName())) {
foundType = subResource.getName();
found = true;
break;
}
}
if (found) {
break;
}
}
if (!found) {
throw JAXRS_LOGGER.typeNameNotAnEjbView(Arrays.asList(jaxrsType), component.getComponentName());
}
jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName() + "!" + foundType;
}
JAXRS_LOGGER.debugf("Found Jakarta RESTful Web Services Managed Bean: %s local jndi jaxRsTypeName: %s", component.getComponentClassName(), jndiName);
StringBuilder buf = new StringBuilder();
buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");
resteasy.getScannedJndiComponentResources().add(buf.toString());
// make sure its removed from list
resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
} else if (component instanceof ManagedBeanComponentDescription) {
String jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
JAXRS_LOGGER.debugf("Found Jakarta RESTful Web Services Managed Bean: %s local jndi name: %s", component.getComponentClassName(), jndiName);
StringBuilder buf = new StringBuilder();
buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");
resteasy.getScannedJndiComponentResources().add(buf.toString());
// make sure its removed from list
resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
}
}
}
Aggregations