Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.jboss.as.jaxrs.deployment;
 
 import static org.jboss.as.jaxrs.JaxrsLogger.JAXRS_LOGGER;
 
Integrate's JAX-RS with other component types such as managed beans and EJB's

This is not needed if beans.xml is present, as in this case the integration is handed by the more general integration with CDI.

Author(s):
Stuart Douglas
public class JaxrsComponentDeployer implements DeploymentUnitProcessor {
    @Override
    public void deploy(DeploymentPhaseContext phaseContextthrows DeploymentUnitProcessingException {
        final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
        if (WeldDeploymentMarker.isWeldDeployment(deploymentUnit)) {
            //this is already handled by the weld integration
            //no need to integrate twice.
            return;
        }
        final Module module = deploymentUnit.getAttachment(......);
        if (module == null) {
            return;
        }
        final ResteasyDeploymentData resteasy = deploymentUnit.getAttachment(.);
        if (resteasy == null) {
            return;
        }
        // right now I only support resources
        if (!resteasy.isScanResources()) return;
        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(.);
        if (moduleDescription == null) {
            return;
        }
        final ClassLoader loader = module.getClassLoader();
        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 (component instanceof WebComponentDescription) {
                continue;
            }
            if (component instanceof SessionBeanComponentDescription) {
                Class jaxrsType = GetRestful.getSubResourceClass(componentClass);
                String jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + componentClass.getSimpleName() + "!" + jaxrsType.getName();
                .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");
                resteasy.getScannedJndiComponentResources().add(buf.toString());
                // make sure its removed from list
                resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
            } else {
                String jndiName = "java:app/" + moduleDescription.getModuleName() + "/" + component.getComponentName();
                .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");
                resteasy.getScannedJndiComponentResources().add(buf.toString());
                // make sure its removed from list
                resteasy.getScannedResourceClasses().remove(component.getComponentClassName());
            }
        }
    }
    @Override
    public void undeploy(DeploymentUnit context) {
    }
New to GrepCode? Check out our FAQ X