Пример #1
0
  @Override
  public void deploy(DeploymentUnit unit) throws DeploymentException {
    log.debug("Deploying rails app as rack: " + unit);
    RailsApplicationMetaData railsAppMetaData = unit.getAttachment(RailsApplicationMetaData.class);

    try {
      RackApplicationMetaData rackMetaData = unit.getAttachment(RackApplicationMetaData.class);

      log.info(rackMetaData);
      log.info(railsAppMetaData);

      if (railsAppMetaData.isRails3()) {
        log.debug("Configuring up a rails 3 application: " + unit);
        rackMetaData.setRackUpScriptLocation("config.ru");
      } else {
        log.debug("Configuring up a rails 2 application: " + unit);
        rackMetaData.setRackUpScript(getRackUpScript(rackMetaData.getContextPath()));
        rackMetaData.setRackUpScriptLocation(null);
      }

      rackMetaData.setStaticPathPrefix(STATIC_PATH_PREFIX);
      log.debug("Configured rack deployment: " + unit + "\n" + rackMetaData);
    } catch (Exception e) {
      throw new DeploymentException(e);
    }
  }
  public void deploy(DeploymentUnit unit) throws DeploymentException {
    Set<? extends RubyEndpointMetaData> allMetaData =
        unit.getAllMetaData(RubyEndpointMetaData.class);

    if (allMetaData.size() == 0) {
      return;
    }

    log.debug("deploying for: " + unit);

    BeanMetaData busMetaData =
        unit.getAttachment(BeanMetaData.class + "$cxf.bus", BeanMetaData.class);

    RubyDynamicClassLoader classLoader = unit.getAttachment(RubyDynamicClassLoader.class);

    for (RubyEndpointMetaData endpointMetaData : allMetaData) {
      String beanName = getBeanName(unit, endpointMetaData.getName());
      BeanMetaDataBuilder builder =
          BeanMetaDataBuilder.createBuilder(beanName, RubyTypeSpace.class.getName());

      builder.addPropertyMetaData("rubyPath", "jboss/databinding/" + endpointMetaData.getName());
      builder.addPropertyMetaData("wsdlLocation", endpointMetaData.getWsdlLocation());
      builder.addPropertyMetaData("rubyDynamicClassLoader", classLoader);

      ValueMetaData busInjection = builder.createInject(busMetaData.getName());
      builder.addPropertyMetaData("bus", busInjection);

      BeanMetaData beanMetaData = builder.getBeanMetaData();
      unit.addAttachment(
          BeanMetaData.class.getName() + "$databinding." + endpointMetaData.getName(),
          beanMetaData,
          BeanMetaData.class);
    }
  }
  /**
   * Process the deployment unit and deploy appropriate MC beans (see details below) if it
   * corresponds to a no-interface view deployment.
   *
   * <p>If any beans in the unit are eligible for no-interface view, then internally this method
   * creates a {@link NoInterfaceViewJNDIBinderFacade} MC bean for the no-interface view.
   *
   * <p>The {@link NoInterfaceViewJNDIBinderFacade}, thus created, will be dependent on the {@link
   * ControllerState#DESCRIBED} state of the container (endpoint) MC bean. This way, we ensure that
   * this {@link NoInterfaceViewJNDIBinderFacade} will be deployed only after the corresponding
   * container MC bean moves to {@link ControllerState#DESCRIBED} state.
   */
  public void deploy(DeploymentUnit unit) throws DeploymentException {

    if (logger.isTraceEnabled()) {
      logger.trace("Deploying unit " + unit.getName());
    }
    // get processed metadata
    JBossMetaData metaData = unit.getAttachment(INPUT, JBossMetaData.class);
    if (metaData == null) {
      if (logger.isTraceEnabled()) logger.trace("No JBossMetadata for unit : " + unit.getName());
      return;
    }
    // work on the ejbs
    JBossEnterpriseBeansMetaData beans = metaData.getEnterpriseBeans();
    for (JBossEnterpriseBeanMetaData bean : beans) {
      if (bean.isSession()) {
        if (logger.isTraceEnabled()) {
          logger.trace(
              "Found bean of type session: " + bean.getEjbClass() + " in unit " + unit.getName());
        }
        // too bad
        if (bean instanceof JBossSessionBean31MetaData) {
          // Process for no-interface view
          deploy(unit, (JBossSessionBean31MetaData) bean);
        }
      }
    }
  }
  @Override
  public void deploy(DeploymentUnit unit) throws DeploymentException {
    TorqueBoxMetaData externalMetaData =
        unit.getAttachment(TorqueBoxMetaData.EXTERNAL, TorqueBoxMetaData.class);
    if (log.isTraceEnabled()) {
      log.trace("External: " + externalMetaData);
    }

    if (externalMetaData == null) {
      return;
    }

    TorqueBoxMetaData metaData = unit.getAttachment(TorqueBoxMetaData.class);
    if (log.isTraceEnabled()) {
      log.trace("Internal: " + metaData);
    }

    if (metaData == null) {
      unit.addAttachment(TorqueBoxMetaData.class, externalMetaData);
      return;
    }
    try {
      TorqueBoxMetaData mergedMetaData = externalMetaData.overlayOnto(metaData);
      if (log.isTraceEnabled()) {
        log.trace("Merged: " + mergedMetaData);
      }
      unit.addAttachment(TorqueBoxMetaData.class, mergedMetaData);
    } catch (ClassCastException e) {
      throw new DeploymentException(
          "Incompatible structures in external and internal deployment descriptors", e);
    }
  }
  protected boolean doAccepts(DeploymentUnit unit) {
    // ejbs
    JBossMetaData jbm = unit.getAttachment(JBossMetaData.class);
    if (jbm != null && jbm.isMetadataComplete()) return false;

    // wars
    JBossWebMetaData jwbm = unit.getAttachment(JBossWebMetaData.class);
    if (jwbm != null && jwbm.isMetadataComplete()) return false;

    return true;
  }
 @Override
 public void deploy(DeploymentUnit unit) throws DeploymentException {
   if (unit.getAllMetaData(MessageProcessorMetaData.class).isEmpty()) {
     return;
   }
   PoolMetaData pool = AttachmentUtils.getAttachment(unit, "messaging", PoolMetaData.class);
   if (pool == null) {
     RubyApplicationMetaData envMetaData = unit.getAttachment(RubyApplicationMetaData.class);
     boolean devMode = envMetaData != null && envMetaData.isDevelopmentMode();
     pool = devMode ? new PoolMetaData("messaging", 1, 2) : new PoolMetaData("messaging");
     pool.setInstanceFactoryName(this.instanceFactoryName);
     AttachmentUtils.multipleAttach(unit, pool, "messaging");
   }
 }
  @Override
  protected void internalDeploy(DeploymentUnit unit) throws DeploymentException {
    if (!isJavaEEModule(unit)) return;

    // appName is either the name of the JavaEE application or null for a stand-alone JavaEE module
    String appName = informer.getApplicationName(unit);
    String moduleName = informer.getModuleName(unit);

    // create JavaEEModule bean
    String name = "jboss.naming:";
    if (appName != null) name += "application=" + appName + ",";
    name += "module=" + moduleName;
    BeanMetaDataBuilder builder =
        BeanMetaDataBuilderFactory.createBuilder(name, MCJavaEEModule.class.getName())
            //         .addAnnotation(annotation(DeploymentScope.class, moduleName))
            .addConstructorParameter(String.class.getName(), moduleName)
        //         .addAlias("java:module")
        ;
    if (appName != null) {
      //         builder.addAnnotation(annotation(ApplicationScope.class, appName));
      //         AbstractInjectionValueMetaData javaApp = new
      // AbstractInjectionValueMetaData("java:app");
      //         javaApp.setSearch(new ParentsLookupStrategy());
      AbstractInjectionValueMetaData javaApp =
          new AbstractInjectionValueMetaData("jboss.naming:application=" + appName);
      builder.addConstructorParameter(JavaEEApplication.class.getName(), javaApp);
    } else builder.addConstructorParameter(JavaEEApplication.class.getName(), (Object) null);
    builder.addPropertyMetaData("nameSpaces", builder.createInject("NameSpaces"));

    unit.addAttachment(BeanMetaData.class + "." + name, builder.getBeanMetaData());
  }
  public void deploy(DeploymentUnit unit) throws DeploymentException {
    RubyApplicationMetaData rubyAppMetaData = unit.getAttachment(RubyApplicationMetaData.class);

    if (rubyAppMetaData.getEnvironmentName() == null
        || rubyAppMetaData.getEnvironmentName().trim().equals("")) {
      rubyAppMetaData.setEnvironmentName(DEFAULT_ENVIRONMENT_NAME);
    }
  }
    public void undeploy(DeploymentUnit unit, TestComponentMetaDataContainer deployment) {
      List<TestComponentMetaData> tests = deployment.componentMetaData;
      if (tests == null) return;

      for (TestComponentMetaData test : tests) {
        unit.removeComponent(test.name);
      }
    }
 protected void assertNoClassLoader(DeploymentUnit unit) throws Exception {
   try {
     unit.getClassLoader();
     fail("Should not be here!");
   } catch (Exception e) {
     checkThrowable(IllegalStateException.class, e);
   }
 }
  /**
   * A template pattern implementation of the deploy() method. This method calls the {@link
   * #performDeploy(WebApplication, String, WebDescriptorParser) performDeploy()} method to perform
   * the container specific deployment steps and registers the returned WebApplication in the
   * deployment map. The steps performed are:
   *
   * <p>ClassLoader appClassLoader = thread.getContextClassLoader(); URLClassLoader warLoader =
   * URLClassLoader.newInstance(empty, appClassLoader); thread.setContextClassLoader(warLoader);
   * WebDescriptorParser webAppParser = ...; WebMetaData metaData = di.metaData; // Create JACC
   * permissions, contextID, etc. ... WebApplication warInfo = new WebApplication(metaData);
   * performDeploy(warInfo, warUrl, webAppParser); deploymentMap.put(warUrl, warInfo);
   * thread.setContextClassLoader(appClassLoader);
   *
   * <p>The subclass performDeploy() implementation needs to invoke processEnc(loader, warInfo) to
   * have the JNDI java:comp/env namespace setup before any web app component can access this
   * namespace.
   *
   * <p>Also, an MBean for each servlet deployed should be created and its JMX ObjectName placed
   * into the DeploymentInfo.mbeans list so that the JSR77 layer can create the approriate model
   * view. The servlet MBean needs to provide access to the min, max and total time in milliseconds.
   * Expose this information via MinServiceTime, MaxServiceTime and TotalServiceTime attributes to
   * integrate seemlessly with the JSR77 factory layer.
   *
   * @param unit The deployment info that contains the context-root element value from the J2EE
   *     application/module/web application.xml descriptor. This may be null if war was is not being
   *     deployed as part of an enterprise application. It also contains the URL of the web
   *     application war.
   */
  public synchronized WebApplication start(DeploymentUnit unit, JBossWebMetaData metaData)
      throws Exception {
    Thread thread = Thread.currentThread();
    ClassLoader appClassLoader = thread.getContextClassLoader();
    WebApplication webApp = null;
    try {
      // Create a classloader for the war to ensure a unique ENC
      ClassLoader warLoader = unit.getClassLoader();
      thread.setContextClassLoader(warLoader);
      String webContext = metaData.getContextRoot();

      // Get the war URL
      URL warUrl = unit.getAttachment("org.jboss.web.expandedWarURL", URL.class);
      if (warUrl == null && unit instanceof VFSDeploymentUnit) {
        VFSDeploymentUnit vdu = VFSDeploymentUnit.class.cast(unit);
        warUrl = VFSUtils.getRealURL(vdu.getRoot());
      }

      // Dynamic WebMetaData deployments might not provide an URL
      // We use the DEploymentUnit name as identifier instead.
      // The JAXWS Endpoint API for example does this.
      String warURLString = (warUrl != null ? warUrl.toExternalForm() : unit.getName());

      // Strip any jar: url syntax. This should be be handled by the vfs
      if (warURLString.startsWith("jar:"))
        warURLString = warURLString.substring(4, warURLString.length() - 2);

      log.debug("webContext: " + webContext);
      log.debug("warURL: " + warURLString);

      // Register the permissions with the JACC layer
      String contextID = metaData.getJaccContextID();
      if (contextID == null) contextID = unit.getSimpleName();
      metaData.setJaccContextID(contextID);

      webApp = new WebApplication(metaData);
      webApp.setClassLoader(warLoader);
      webApp.setDeploymentUnit(unit);
      performDeploy(webApp, warURLString);
    } finally {
      thread.setContextClassLoader(appClassLoader);
    }
    return webApp;
  }
  /**
   * Ultimately, the container name should come from the <code>sessionBeanMetadata</code>. However
   * because of the current behaviour where the container on its start sets the containername in the
   * metadata, its not possible to get this information even before the container is started.
   *
   * <p>Hence let's for the time being create the container name from all the information that we
   * have in the <code>unit</code>
   *
   * @param unit The deployment unit
   * @param sessionBeanMetadata Session bean metadata
   * @return Returns the container name for the bean corresponding to the <code>sessionBeanMetadata
   *     </code> in the <code>unit</code>
   * @throws MalformedObjectNameException
   */
  private String getContainerName(DeploymentUnit unit, JBossSessionBeanMetaData sessionBeanMetadata)
      throws MalformedObjectNameException {
    // TODO the base ejb3 jmx object name comes from Ejb3Module.BASE_EJB3_JMX_NAME, but
    // we don't need any reference to ejb3-core. Right now just hard code here, we need
    // a better way/place for this later
    StringBuilder containerName = new StringBuilder("jboss.j2ee:service=EJB3" + ",");

    // Get the top level unit for this unit (ex: the top level might be an ear and this unit might
    // be the jar
    // in that ear
    DeploymentUnit toplevelUnit = unit.getTopLevel();
    if (toplevelUnit != null) {
      // if top level is an ear, then create the name with the ear reference
      if (isEar(toplevelUnit)) {
        containerName.append("ear=");
        containerName.append(toplevelUnit.getSimpleName());
        containerName.append(",");
      }
    }
    // now work on the passed unit, to get the jar name
    if (unit.getSimpleName() == null) {
      containerName.append("*");
    } else {
      containerName.append("jar=");
      containerName.append(unit.getSimpleName());
    }
    // now the ejbname
    containerName.append(",name=");
    containerName.append(sessionBeanMetadata.getEjbName());

    if (logger.isTraceEnabled()) {
      logger.trace(
          "Container name generated for ejb = "
              + sessionBeanMetadata.getEjbName()
              + " in unit "
              + unit
              + " is "
              + containerName);
    }
    ObjectName containerJMXName = new ObjectName(containerName.toString());
    return containerJMXName.getCanonicalName();
  }
 private void linkServiceRefs(
     DeploymentUnit unit, ServiceReferencesMetaData serviceRefs, Context envCtx)
     throws NamingException {
   if (unit instanceof VFSDeploymentUnit) {
     VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit) unit;
     ClassLoader loader = unit.getClassLoader();
     UnifiedVirtualFile vfsRoot = new VirtualFileAdaptor(vfsUnit.getRoot());
     for (ServiceReferenceMetaData sref : serviceRefs) {
       String refName = sref.getServiceRefName();
       new ServiceReferenceHandler().bindServiceRef(envCtx, refName, vfsRoot, loader, sref);
     }
   }
 }
 /**
  * Returns true if this <code>unit</code> represents an .ear deployment
  *
  * @param unit
  * @return
  */
 private boolean isEar(DeploymentUnit unit) {
   return unit.getSimpleName().endsWith(".ear")
       || unit.getAttachment(JBossAppMetaData.class) != null;
 }
 protected static void removeTestComponent(DeploymentUnit unit, TestComponentMetaData test) {
   unit.removeComponent(test.name);
 }
 protected static void addTestComponent(DeploymentUnit unit, TestComponentMetaData test) {
   DeploymentUnit component = unit.addComponent(test.name);
   component.addAttachment(TestComponentMetaData.class, test);
 }
Пример #17
0
  @Override
  protected void internalDeploy(DeploymentUnit unit) throws DeploymentException {
    JBossEnterpriseBeanMetaData beanMetaData =
        unit.getAttachment(JBossEnterpriseBeanMetaData.class);
    if (beanMetaData == null) return;

    if (!beanMetaData.isSession()) return;

    JBossSessionBeanMetaData sessionBeanMetaData = (JBossSessionBeanMetaData) beanMetaData;

    String appName = getApplicationName(unit);
    String moduleName = getModuleName(unit);
    String componentName = getComponentName(unit);

    String javaCompName = "jboss.naming:";
    if (appName != null) javaCompName += "application=" + appName + ",";
    javaCompName += "module=" + moduleName + ",component=" + componentName;

    String sessionBeanTypeName = "jboss.ejb3:";
    if (appName != null) sessionBeanTypeName += "application=" + appName + ",";
    sessionBeanTypeName +=
        "module="
            + moduleName
            + ",component="
            + componentName
            + ",service="
            + SessionBeanTypeWrapper.class.getSimpleName();
    {
      BeanMetaDataBuilder builder =
          BeanMetaDataBuilderFactory.createBuilder(
              sessionBeanTypeName, SessionBeanTypeWrapper.class.getName());
      builder.addConstructorParameter(
          JBossSessionBeanMetaData.class.getName(), sessionBeanMetaData);
      builder.addConstructorParameter(ClassLoader.class.getName(), unit.getClassLoader());
      builder.addConstructorParameter(
          JavaEEComponent.class.getName(), builder.createInject(javaCompName));

      unit.getParent().addAttachment(sessionBeanTypeName, builder.getBeanMetaData());
    }

    String beanInstanceName = "jboss.ejb3:";
    if (appName != null) beanInstanceName += "application=" + appName + ",";
    beanInstanceName +=
        "module="
            + moduleName
            + ",component="
            + componentName
            + ",service="
            + EJBBinder.class.getSimpleName();
    BeanMetaDataBuilder builder =
        BeanMetaDataBuilderFactory.createBuilder(beanInstanceName, EJBBinder.class.getName());
    builder.addConstructorParameter(
        SessionBeanType.class.getName(), builder.createInject(sessionBeanTypeName));
    builder.addPropertyMetaData(
        "globalContext", builder.createInject("NameSpaces", "globalContext"));
    builder.addPropertyMetaData("proxyFactory", sessionBeanMetaData.isStateless() ? lazy : legacy);
    builder.setStart("bind");
    builder.setStop("unbind");

    for (DependencyBuilder db : builders) db.buildDependency(unit, builder);

    unit.getParent().addAttachment(beanInstanceName, builder.getBeanMetaData());
  }
 public static String getBeanName(DeploymentUnit unit, String serviceName) {
   return PREFIX + unit.getSimpleName() + "." + serviceName;
 }
 /**
  * @see
  *     org.jboss.ejb3.deployers.metadata.processor.JBossMetaDataProcessorFactory#create(org.jboss.deployers.structure.spi.DeploymentUnit)
  * @throws NullPointerException If <code>deploymentUnit</code> is null
  */
 @Override
 public JBossMetaDataProcessor<JBossMetaData> create(DeploymentUnit deploymentUnit) {
   return new ImplicitNoInterfaceViewProcessor(deploymentUnit.getClassLoader());
 }
  /**
   * Creates a {@link NoInterfaceViewJNDIBinderFacade} MC bean for the no-interface view represented
   * by the <code>sessionBeanMetaData</code>. The {@link NoInterfaceViewJNDIBinderFacade} is created
   * only if the bean is eligible for a no-interface view as defined by the EJB3.1 spec
   *
   * <p>The {@link NoInterfaceViewJNDIBinderFacade}, thus created, will be dependent on the {@link
   * ControllerState#DESCRIBED} state of the container (endpoint) MC bean. This way, we ensure that
   * this {@link NoInterfaceViewJNDIBinderFacade} will be deployed only after the corresponding
   * container MC bean moves to {@link ControllerState#DESCRIBED} state.
   *
   * @param unit Deployment unit
   * @param sessionBeanMetaData Session bean metadata
   * @throws DeploymentException If any exceptions are encountered during processing of the
   *     deployment unit
   */
  private void deploy(DeploymentUnit unit, JBossSessionBean31MetaData sessionBeanMetaData)
      throws DeploymentException {
    try {
      if (!sessionBeanMetaData.isNoInterfaceBean()) {
        if (logger.isTraceEnabled()) {
          logger.trace(
              "Bean class "
                  + sessionBeanMetaData.getEjbClass()
                  + " is not eligible for no-interface view");
        }
        return;
      }
      Class<?> beanClass =
          Class.forName(sessionBeanMetaData.getEjbClass(), false, unit.getClassLoader());

      String containerMCBeanName = sessionBeanMetaData.getContainerName();
      if (logger.isTraceEnabled()) {
        logger.trace(
            "Container name for bean "
                + sessionBeanMetaData.getEjbName()
                + " in unit "
                + unit
                + " is "
                + containerMCBeanName);
      }
      if (containerMCBeanName == null) {
        // The container name is set in the metadata only after the creation of the container
        // However, this deployer does not have an dependency on the creation of a container,
        // so getting the container name from the bean metadata won't work. Need to do a
        // different/better way
        // String containerMCBeanName = sessionBeanMetaData.getContainerName();
        containerMCBeanName = getContainerName(unit, sessionBeanMetaData);
      }

      // Create the NoInterfaceViewJNDIBinder (MC bean) and add a dependency on the DESCRIBED
      // state of the container (endpoint) MC bean
      NoInterfaceViewJNDIBinderFacade noInterfaceViewJNDIBinderFacade =
          new NoInterfaceViewJNDIBinderFacade(new InitialContext(), beanClass, sessionBeanMetaData);
      String noInterfaceViewMCBeanName = unit.getName() + "$" + sessionBeanMetaData.getEjbName();
      BeanMetaDataBuilder builder =
          BeanMetaDataBuilder.createBuilder(
              noInterfaceViewMCBeanName, noInterfaceViewJNDIBinderFacade.getClass().getName());
      builder.setConstructorValue(noInterfaceViewJNDIBinderFacade);

      // add dependency
      AbstractInjectionValueMetaData injectMetaData =
          new AbstractInjectionValueMetaData(containerMCBeanName);
      // EJBTHREE-2166 - Depending on DESCRIBED state and then pushing to INSTALLED
      // through MC API, won't work. So for now, just depend on INSTALLED state.
      // injectMetaData.setDependentState(ControllerState.DESCRIBED);
      injectMetaData.setDependentState(ControllerState.INSTALLED);
      injectMetaData.setFromContext(FromContext.CONTEXT);

      // Too bad we have to know the field name. Need to do more research on MC to see if we can
      // add property metadata based on type instead of field name.
      builder.addPropertyMetaData("endpointContext", injectMetaData);

      // Add this as an attachment
      unit.addAttachment(
          BeanMetaData.class + ":" + noInterfaceViewMCBeanName, builder.getBeanMetaData());

      logger.debug(
          "No-interface JNDI binder for container "
              + containerMCBeanName
              + " has been created and added to the deployment unit "
              + unit);

    } catch (Throwable t) {
      DeploymentException.rethrowAsDeploymentException(
          "Could not create no-interface view for "
              + sessionBeanMetaData.getEjbClass()
              + " in unit "
              + unit.getName(),
          t);
    }
  }