glassfish
  1. glassfish
  2. GLASSFISH-20856

org.glassfish.main.deployment:deployment-client cannot be used WITHIN the GlassFish container

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Critical Critical
    • Resolution: Unresolved
    • Affects Version/s: 3.1.2.2, 4.0
    • Fix Version/s: None
    • Component/s: deployment
    • Labels:
      None

      Description

      The GlassFish JSR-88 Deployment Client 4.0 (and apparently also 3.1.2.2) does not work when deployed as part of a module to a GlassFish container (say within an EAR). When running the following code within the deployed module:

      final DeploymentFactory df = new org.glassfish.deployapi.SunDeploymentFactory();
      final DeploymentManager dm = df.getDeploymentManager("deployer:Sun:AppServer::localhost:4848", "admin", "");
      try {
          final Target[] targets = dm.getTargets();
          Logger  .getLogger(Jsr88UpdateInstaller.class.getName())
                  .log(Level.INFO, "Found {0,choice,0#No targets|1#one target|1<{0} targets}.", targets.length);
          for (final Target target : targets) {
              Logger  .getLogger(Jsr88UpdateInstaller.class.getName())
                      .log(Level.INFO, "Target {0}: {1}.", new Object[] { target.getName(), target.getDescription() });
          }
          for (final ModuleType mt : new ModuleType[] { ModuleType.EAR, ModuleType.EJB, ModuleType.CAR, ModuleType.RAR, ModuleType.WAR }) {
              final TargetModuleID[] tmids = dm.getRunningModules(mt, targets);
              if (null == tmids) continue;
              for (final TargetModuleID tmid : tmids) {
                  Logger  .getLogger(Jsr88UpdateInstaller.class.getName())
                          .log(Level.INFO, "Target module ID {0} .", tmid.toString());
              }
          }
      } finally {
          dm.release();
      }
      

      Then it should list the available modules. However, it fails on the call to DeploymentManager.getRunningModules(ModuleType, Target[]) with the following exception:

      javax.enterprise.deploy.spi.exceptions.TargetException: Error getting required modules
      	at org.glassfish.deployapi.SunDeploymentManager.getModules(SunDeploymentManager.java:297)
      	at org.glassfish.deployapi.SunDeploymentManager.getRunningModules(SunDeploymentManager.java:197)
      

      When debug-stepping through the code, I see it throws and discards a ClassCastException saying that it cannot cast org.glassfish.deployapi.TargetImpl to the same class! This hints that there is an issue with the class loader configuration. Further investigating the issue, I found the following declaration in META-INF/MANIFEST.MF:

      Export-Package: org.glassfish.deployment.client;uses:="org.glassfish.a
       pi.admin,javax.enterprise.deploy.spi,com.sun.enterprise.util,org.glas
       sfish.api.deployment.archive,com.sun.enterprise.deployment.deploy.sha
       red,javax.enterprise.deploy.shared,org.xml.sax.helpers,org.xml.sax,ja
       vax.xml.parsers,javax.enterprise.deploy.spi.status,com.sun.enterprise
       .admin.cli,com.sun.enterprise.admin.cli.remote";version="4.0.0"
      

      Apparently, the package org.glassfish.deployapi is missing here. I don't know much about OSGI, but I think this is the reason why the TargetImpl class gets defined by two different class loaders.

      When googling for this ClassCastException, you will find that this is quite a frequent issue, e.g. when running Jenkins on GlassFish. Furthermore, it's a showstopper for using the Deployment Client from within the GlassFish container.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Hong Zhang
            Reporter:
            Christian Schlichtherle
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: