1 2 3 4 Previous Next 48 Replies Latest reply on Jun 26, 2008 1:33 AM by ropalka

    HOWTO deploy webapp dynamically

    thomas.diesler

      Folks,

      this is related to http://jira.jboss.org/jira/browse/JBWS-1967

      I now generate the JBossWebMetaData object in memory and want to deploy it through the main deployer. Previously I used to do

       VirtualFile file = VFS.getRoot(warURL);
       Deployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
       MutableAttachments attach = (MutableAttachments)deployment.getPredeterminedManagedObjects();
       attach.addAttachment(WebMetaDataModifier.PROPERTY_GENERATED_WEBAPP, Boolean.TRUE);
      
       mainDeployer.deploy(deployment);
      


      Please show me how I create a deployment that is not based on a file.

      I looked at http://labs.jboss.com/file-access/default/members/jbossmc/freezone/docs/2.0.x/userGuide/pt04.html
      but that does not give me much information.



        • 1. Re: HOWTO deploy webapp dynamically
          alesj

          Where do you get the warURL?
          Here?
          - http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4123146

          Who uses WebMetaDataModifier.PROPERTY_GENERATED_WEBAPP?
          Or what is its purpose?

          You don't need to create whole new deployment.
          You probably just need to add another deployer in the chain of deployers that modify WebMetaData/JBossWebMetaData, like Scott's MergedJBossMetaDataDeployer does.

          e.g. pseudo chain :-)
          1) Deployer that creates WebMD/JWebMD (usually some parser)
          2) MergedJBossMetaDataDeployer that merges JBoss specific inputs with common one's
          3) Your modifier deployer that adds WS specific info
          4) TomcatDeployer that turns WMD/JWMD into ServiceMetadata
          5) Real ServiceDeployer

          There are of course other deployers in that chain, but those should not be relevant for you.

          • 2. Re: HOWTO deploy webapp dynamically
            alesj

             

            "alesj" wrote:

            2) MergedJBossMetaDataDeployer that merges JBoss specific inputs with common one's

            Aha, this is really for ejbs.
            So basically this is what you need to do, but for the web metadata.

            • 3. Re: HOWTO deploy webapp dynamically

              All you need to do is add the WebMetaData into the attachments
              and make sure your deployer runs before the other WebMetaData processing deployers.
              These other deployers will then turn that metadata into a web/tomcat deployment.

              The other web deployers don't care whether the WebMetaData came from parsing
              a web.xml or if you created it programmatically.

              • 4. Re: HOWTO deploy webapp dynamically
                thomas.diesler

                ok, done.

                • 5. Re: HOWTO deploy webapp dynamically
                  thomas.diesler

                  Using the JAX-WS Endpoint API it is possible to setup a WS endpoint for a given endpoint bean and web context.

                  Prior to the changes above we used to generate webapp descriptors and deployed them through the client deployer API.

                  Please show me how to do this in memory. I generate the JBossWebMetaData ,but I don't have a deployment unit to attach it to.

                   DeploymentUnit unit = dep.getAttachment(DeploymentUnit.class);
                   if (unit != null)
                   {
                   unit.addAttachment(JBossWebMetaData.class, jbwmd);
                   unit.addAttachment(WebMetaDataModifier.PROPERTY_GENERATED_WEBAPP, Boolean.TRUE);
                   }
                   else
                   {
                   // TODO: endpoint API cannot use an existing deployment unit
                   }
                  


                  • 6. Re: HOWTO deploy webapp dynamically
                    alesj

                     

                    "thomas.diesler@jboss.com" wrote:
                    I generate the JBossWebMetaData ,but I don't have a deployment unit to attach it to.

                    Where do you try to do this?
                    Where outside deployers?

                    • 7. Re: HOWTO deploy webapp dynamically
                      thomas.diesler

                      Any component can setup an endpoint using the endpoint API.

                      The impl of that API uses the WS deployment aspect shown above - we do not have a deployer at that time. i.e. the component initiates the deployment at runtime.

                       // Create the endpoint
                       EndpointBean epImpl = new EndpointBean();
                       endpoint = Endpoint.create(SOAPBinding.SOAP11HTTP_BINDING, epImpl);
                      
                       // Create and start the HTTP server
                       SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
                       HttpServer httpServer = spiProvider.getSPI(HttpServerFactory.class).getHttpServer();
                       httpServer.start();
                      
                       // Create the context and publish the endpoint
                       HttpContext context = httpServer.createContext("/jaxws-endpoint");
                       endpoint.publish(context);
                      


                      • 8. Re: HOWTO deploy webapp dynamically
                        thomas.diesler

                        In other words, I have JBossWebMetaData. How can I deploy it?

                        • 9. Re: HOWTO deploy webapp dynamically
                          alesj

                           

                          "thomas.diesler@jboss.com" wrote:
                          In other words, I have JBossWebMetaData - how do I deploy them?

                          OK, I still don't see where you create it.
                          Where does the owner thread come from - who triggers the creation?

                          From Adrian's response:
                          "adrian@jboss.org" wrote:

                          The other web deployers don't care whether the WebMetaData came from parsing
                          a web.xml or if you created it programmatically.

                          You create Deployment on the fly, attach JBWMD to it, and just push it to the deployers.
                          They will pick the metadata the same way as if it came from parsing jboss-web.xml.

                          • 10. Re: HOWTO deploy webapp dynamically
                            thomas.diesler

                             


                            You create Deployment on the fly, attach JBWMD to it, and just push it to the deployers.


                            Yes, please show me the code that does this.

                            • 11. Re: HOWTO deploy webapp dynamically
                              alesj

                               

                              "thomas.diesler@jboss.com" wrote:

                              Yes, please show me the code that does this.

                              A bunch of our tests do this. ;-)

                              OK, but here it goes:
                               DeployerClient main = getMainDeployer();
                               Deployment deployment = createSimpleDeployment("some_name");
                               MutableAttachments mutableAttachments = (MutableAttachments)deployment.getPredeterminedManagedObjects();
                               mutableAttachments.addAttachment(JBossWebMetaData.class, jbwmd);
                               main.deploy(deployment);
                              


                              • 12. Re: HOWTO deploy webapp dynamically
                                thomas.diesler

                                Now I get

                                Caused by: org.jboss.deployers.spi.DeploymentException: Structure can only be determined for VFSDeployments org.jboss.deployers.client.plugins.deployment.AbstractDeployment@1f0eb99
                                 at org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl.determineStructure(VFSStructuralDeployersImpl.java:211)
                                 at org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers.determineStructure(AbstractStructuralDeployers.java:77)
                                 at org.jboss.deployers.plugins.main.MainDeployerImpl.determineStructure(MainDeployerImpl.java:743)
                                 at org.jboss.deployers.plugins.main.MainDeployerImpl.addDeployment(MainDeployerImpl.java:280)
                                 at org.jboss.deployers.plugins.main.MainDeployerImpl.deploy(MainDeployerImpl.java:384)
                                 at org.jboss.wsf.container.jboss50.WebAppDeploymentAspect.create(WebAppDeploymentAspect.java:84)
                                


                                • 13. Re: HOWTO deploy webapp dynamically

                                  If you're not using the VirtualFile then you need to tell it what the structure is.

                                  See
                                  http://viewvc.jboss.org/cgi-bin/viewvc.cgi/jbossas/projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java?revision=70043&view=markup
                                  and its subclasses for how to do things.

                                  e.g.

                                   protected Deployment createSimpleDeployment(String name)
                                   {
                                   AbstractDeployment unit = createAbstractDeployment(name);
                                   // HERE There is one top level deployment
                                   factory.addContext(unit, "");
                                   return unit;
                                   }
                                  


                                  If you don't want to do some research and are just going to post
                                  exceptions into the forum, then please use the user forum not the dev forums.

                                  • 14. Re: HOWTO deploy webapp dynamically
                                    thomas.diesler

                                    I read http://labs.jboss.com/file-access/default/members/jbossmc/freezone/docs/2.0.x/userGuide/pt04.html
                                    Is there anywhere else this is documented?

                                    How do I set the deployments class path?
                                    I cant do

                                     // There is one top level deployment
                                     ContextInfo context = factory.addContext(unit, "");
                                     context.addClassPathEntry(entry);
                                    


                                    because the classpath is not file based.

                                    In my case, the deployment should use the context class loader of the calling component.

                                    I get

                                    Caused by: java.lang.IllegalArgumentException: Null policy
                                     at org.jboss.classloader.spi.base.BaseClassLoaderSystem.registerClassLoaderPolicy(BaseClassLoaderSystem.java:112)
                                     at org.jboss.classloader.spi.ClassLoaderSystem.registerClassLoaderPolicy(ClassLoaderSystem.java:328)
                                     at org.jboss.deployers.plugins.classloading.AbstractClassLoaderSystemDeployer.createClassLoader(AbstractClassLoaderSystemDeployer.java:143)
                                     at org.jboss.deployers.structure.spi.helpers.AbstractDeploymentContext.createClassLoader(AbstractDeploymentContext.java:510)
                                    




                                    1 2 3 4 Previous Next