Skip to content

Commit

Permalink
AS7-5464 Make sure JAX-RS component integration is only applied to Se…
Browse files Browse the repository at this point in the history
…ssion beans and Managed Beans
  • Loading branch information
stuartwdouglas committed Nov 26, 2012
1 parent 63bd0fc commit 47d3d51
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jboss.as.ee.managedbean.component;

import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.msc.service.ServiceName;

/**
* Component descriptor for {@link javax.annotation.ManagedBean} managed beans.
*
* This is only here so that other interested processors can tell if a given component is a managed bean,
* it does not add anything to the component description.
*
* @author Stuart Douglas
*/
public class ManagedBeanComponentDescription extends ComponentDescription {
/**
* Construct a new instance.
*
* @param componentName the component name
* @param componentClassName the component instance class name
* @param moduleDescription the EE module description
* @param deploymentUnitServiceName the service name of the DU containing this component
*/
public ManagedBeanComponentDescription(final String componentName, final String componentClassName, final EEModuleDescription moduleDescription, final ServiceName deploymentUnitServiceName) {
super(componentName, componentClassName, moduleDescription, deploymentUnitServiceName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import javax.annotation.ManagedBean;

import org.jboss.as.ee.component.ComponentConfiguration;
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEApplicationClasses;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.TCCLInterceptor;
import org.jboss.as.ee.component.ViewConfiguration;
Expand All @@ -39,6 +37,7 @@
import org.jboss.as.ee.component.deployers.EEResourceReferenceProcessorRegistry;
import org.jboss.as.ee.component.interceptors.InterceptorOrder;
import org.jboss.as.ee.managedbean.component.ManagedBeanAssociatingInterceptorFactory;
import org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription;
import org.jboss.as.ee.managedbean.component.ManagedBeanCreateInterceptorFactory;
import org.jboss.as.ee.managedbean.component.ManagedBeanDestroyInterceptorFactory;
import org.jboss.as.ee.managedbean.component.ManagedBeanResourceReferenceProcessor;
Expand Down Expand Up @@ -80,7 +79,6 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
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 EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
if(compositeIndex == null) {
return;
Expand All @@ -105,7 +103,7 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
// Get the managed bean name from the annotation
final AnnotationValue nameValue = instance.value();
final String beanName = nameValue == null || nameValue.asString().isEmpty() ? beanClassName : nameValue.asString();
final ComponentDescription componentDescription = new ComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());
final ManagedBeanComponentDescription componentDescription = new ManagedBeanComponentDescription(beanName, beanClassName, moduleDescription, deploymentUnit.getServiceName());

// Add the view
ViewDescription viewDescription = new ViewDescription(componentDescription, beanClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,20 @@
import org.jboss.as.ee.component.ComponentDescription;
import org.jboss.as.ee.component.EEModuleDescription;
import org.jboss.as.ee.component.ViewDescription;
import org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription;
import org.jboss.as.ejb3.component.session.SessionBeanComponentDescription;
import org.jboss.as.jaxrs.JaxrsMessages;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.web.deployment.component.WebComponentDescription;
import org.jboss.modules.Module;
import org.jboss.resteasy.util.GetRestful;

import static org.jboss.as.jaxrs.JaxrsLogger.JAXRS_LOGGER;

/**
* Integrates JAX-RS with other component types such as managed beans and EJB's
* <p/>
* This is not needed if beans.xml is present, as in this case the integration is handed by the more general
* integration with CDI.
* Integrates JAX-RS with managed beans and EJB's
*
* @author Stuart Douglas
*/
Expand Down Expand Up @@ -81,25 +78,22 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
}
if (!GetRestful.isRootResource(componentClass)) continue;

if (component instanceof WebComponentDescription) {
continue;
}
if (component instanceof SessionBeanComponentDescription) {
Class jaxrsType = GetRestful.getSubResourceClass(componentClass);
final String jndiName;
if(component.getViews().size() == 1) {
if (component.getViews().size() == 1) {
//only 1 view, just use the simple JNDI name
jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + componentClass.getSimpleName();
} else {
final String jaxRsTypeName = jaxrsType.getName();
boolean found = false;
for(final ViewDescription view : component.getViews()) {
if(view.getViewClassName().equals(jaxRsTypeName)) {
for (final ViewDescription view : component.getViews()) {
if (view.getViewClassName().equals(jaxRsTypeName)) {
found = true;
break;
}
}
if(!found) {
if (!found) {
throw JaxrsMessages.MESSAGES.typeNameNotAnEjbView(jaxRsTypeName, component.getComponentName());
}
jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + componentClass.getSimpleName() + "!" + jaxRsTypeName;
Expand All @@ -112,9 +106,10 @@ public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitPro
resteasy.getScannedJndiComponentResources().add(buf.toString());
// make sure its removed from list
resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
} else {
} else if (component instanceof ManagedBeanComponentDescription) {

String jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();

JAXRS_LOGGER.debugf("Found JAX-RS Managed Bean: %s local jndi name: %s", component.getComponentClassName(), jndiName);
StringBuilder buf = new StringBuilder();
buf.append(jndiName).append(";").append(component.getComponentClassName()).append(";").append("true");
Expand Down

0 comments on commit 47d3d51

Please sign in to comment.