コード例 #1
0
 private void scanRegistry() {
   methods = new ArrayList<MethodMetaData>();
   locators = new ArrayList<ServiceRegistry>();
   for (Entry<String, List<ResourceInvoker>> entry : registry.getRoot().getBounded().entrySet()) {
     List<ResourceInvoker> invokers = entry.getValue();
     for (ResourceInvoker invoker : invokers) {
       if (invoker instanceof ResourceMethod) {
         methods.add(new MethodMetaData(this, (ResourceMethod) invoker));
       } else if (invoker instanceof ResourceLocator) {
         ResourceLocator locator = (ResourceLocator) invoker;
         Method method = locator.getMethod();
         Class<?> locatorType = method.getReturnType();
         Class<?> locatorResourceType = GetRestful.getSubResourceClass(locatorType);
         if (locatorResourceType == null) {
           // FIXME: we could generate an error for the client, which would be more informative
           // than
           // just logging this
           if (logger.isWarnEnabled()) {
             logger.warn(
                 "Impossible to generate JSAPI for subresource returned by method "
                     + method.getDeclaringClass().getName()
                     + "."
                     + method.getName()
                     + " since return type is not a static JAXRS resource type");
           }
           // skip this
           continue;
         }
         ResourceMethodRegistry locatorRegistry = new ResourceMethodRegistry(providerFactory);
         locatorRegistry.addResourceFactory(null, null, locatorResourceType);
         locators.add(new ServiceRegistry(this, locatorRegistry, providerFactory, locator));
       }
     }
   }
 }
コード例 #2
0
  @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;
    }
    // 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();

    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 SessionBeanComponentDescription) {
        Class[] jaxrsType = GetRestful.getSubResourceClass(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 JaxrsMessages.MESSAGES.typeNameNotAnEjbView(
                Arrays.asList(jaxrsType), component.getComponentName());
          }
          jndiName =
              "java:app/"
                  + moduleDescription.getModuleName()
                  + "/"
                  + component.getComponentName()
                  + "!"
                  + foundType;
        }

        JAXRS_LOGGER.debugf(
            "Found JAX-RS 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 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());
      }
    }
  }