7 Replies Latest reply on Feb 22, 2008 9:49 AM by Thomas Diesler

    Deploying multiple service through the ServiceDeployer

    Thomas Diesler Master

      Folks,

      I have/had an issue with a deployment wanting to create multiple services

      1) EJBDeployer attaches ServiceMetaData
      2) WebServiceDeployerEJB generates and attaches JBossWebMetaData
      3) TomcatDeployer also attaches ServiceMetaData

      my proposed fix is

       // In case there already is a ServiceMetaData object attached, we use a set
       ServiceMetaData prevService = unit.getAttachment(ServiceMetaData.class);
       if (prevService != null)
       {
       ServiceMetaDataSet services = new ServiceMetaDataSet();
       services.add(prevService);
       services.add(webModule);
       unit.addAttachment(ServiceMetaDataSet.class, services);
       unit.removeAttachment(ServiceMetaData.class);
       }
       else
       {
       unit.addAttachment(ServiceMetaData.class, webModule);
       }
      


      and a new deployer

      public class MultipleServicesDeployer extends AbstractSimpleRealDeployer<ServiceMetaDataSet>
      {
       private ServiceDeployer serviceDeployer;
      
       public MultipleServicesDeployer()
       {
       super(ServiceMetaDataSet.class);
       }
      
       public void setServiceDeployer(ServiceDeployer serviceDeployer)
       {
       this.serviceDeployer = serviceDeployer;
       }
      
       @Override
       public void deploy(DeploymentUnit unit, ServiceMetaDataSet deployment) throws DeploymentException
       {
       Iterator<ServiceMetaData> it = deployment.iterator();
       while (it.hasNext())
       {
       ServiceMetaData service = it.next();
       unit.addAttachment(ServiceMetaData.class, service);
       try
       {
       serviceDeployer.deploy(unit, service);
       }
       finally
       {
       unit.removeAttachment(ServiceMetaData.class);
       }
       }
       }
       ...
      


      Please review.