예제 #1
0
  protected WebXmlParser getWebXmlParser(ReadableArchive archive)
      throws XMLStreamException, IOException {

    WebXmlParser webXmlParser = null;
    boolean hasWSLDD = archive.exists(WEBLOGIC_XML);
    File runtimeAltDDFile =
        archive.getArchiveMetaData(DeploymentProperties.RUNTIME_ALT_DD, File.class);
    if (runtimeAltDDFile != null
        && "glassfish-web.xml".equals(runtimeAltDDFile.getPath())
        && runtimeAltDDFile.isFile()) {
      webXmlParser = new GlassFishWebXmlParser(archive);
    } else if (!gfDDOverWLSDD && !ignoreWLSDD && hasWSLDD) {
      webXmlParser = new WeblogicXmlParser(archive);
    } else if (archive.exists(GLASSFISH_WEB_XML)) {
      webXmlParser = new GlassFishWebXmlParser(archive);
    } else if (archive.exists(SUN_WEB_XML)) {
      webXmlParser = new SunWebXmlParser(archive);
    } else if (gfDDOverWLSDD && !ignoreWLSDD && hasWSLDD) {
      webXmlParser = new WeblogicXmlParser(archive);
    } else { // default
      if (gfDDOverWLSDD || ignoreWLSDD) {
        webXmlParser = new GlassFishWebXmlParser(archive);
      } else {
        webXmlParser = new WeblogicXmlParser(archive);
      }
    }
    return webXmlParser;
  }
예제 #2
0
  protected void configureLoaderProperties(
      WebappClassLoader cloader, WebXmlParser webXmlParser, File base) {

    cloader.setUseMyFaces(webXmlParser.isUseBundledJSF());

    File libDir = new File(base, "WEB-INF/lib");
    if (libDir.exists()) {
      int baseFileLen = base.getPath().length();
      final boolean ignoreHiddenJarFiles = webXmlParser.isIgnoreHiddenJarFiles();

      for (File file :
          libDir.listFiles(
              new FileFilter() {
                @Override
                public boolean accept(File pathname) {
                  String fileName = pathname.getName();
                  return ((fileName.endsWith(".jar") || fileName.endsWith(".zip"))
                      && (!ignoreHiddenJarFiles || !fileName.startsWith(".")));
                }
              })) {
        try {
          if (file.isDirectory()) {
            // support exploded jar file
            cloader.addRepository("WEB-INF/lib/" + file.getName() + "/", file);
          } else {
            cloader.addJar(file.getPath().substring(baseFileLen), new JarFile(file), file);
            cloader.closeJARs(true);
          }
        } catch (Exception e) {
          // Catch and ignore any exception in case the JAR file
          // is empty.
        }
      }
    }
  }
예제 #3
0
  protected void configureLoaderAttributes(
      WebappClassLoader cloader, WebXmlParser webXmlParser, File base) {

    boolean delegate = webXmlParser.isDelegate();
    cloader.setDelegate(delegate);
    if (logger.isLoggable(Level.FINE)) {
      logger.fine("WebModule[" + base + "]: Setting delegate to " + delegate);
    }

    String extraClassPath = webXmlParser.getExtraClassPath();
    if (extraClassPath != null) {
      // Parse the extra classpath into its ':' and ';' separated
      // components. Ignore ':' as a separator if it is preceded by
      // '\'
      String[] pathElements = extraClassPath.split(";|((?<!\\\\):)");
      for (String path : pathElements) {
        path = path.replace("\\:", ":");
        if (logger.isLoggable(Level.FINE)) {
          logger.fine("WarHandler[" + base + "]: Adding " + path + " to the classpath");
        }

        try {
          URL url = new URL(path);
          cloader.addRepository(path);
        } catch (MalformedURLException mue1) {
          // Not a URL, interpret as file
          File file = new File(path);
          // START GlassFish 904
          if (!file.isAbsolute()) {
            // Resolve relative extra class path to the
            // context's docroot
            file = new File(base.getPath(), path);
          }
          // END GlassFish 904

          try {
            URL url = file.toURI().toURL();
            cloader.addRepository(url.toString());
          } catch (MalformedURLException mue2) {
            String msg = rb.getString(CLASSPATH_ERROR);
            Object[] params = {path};
            msg = MessageFormat.format(msg, params);
            logger.log(Level.SEVERE, msg, mue2);
          }
        }
      }
    }
  }
예제 #4
0
    ContextXmlParser(File contextXmlFile) throws XMLStreamException, IOException {

      if (contextXmlFile.exists()) {
        try (InputStream is = new FileInputStream(contextXmlFile)) {
          init(is);
        }
      }
    }
예제 #5
0
 /**
  * Returns the classpath URIs for this archive.
  *
  * @param archive file
  * @return classpath URIs for this archive
  */
 @Override
 public List<URI> getClassPathURIs(ReadableArchive archive) {
   List<URI> uris = super.getClassPathURIs(archive);
   try {
     File archiveFile = new File(archive.getURI());
     if (archiveFile.exists() && archiveFile.isDirectory()) {
       uris.add(new URI(archive.getURI().toString() + "WEB-INF/classes/"));
       File webInf = new File(archiveFile, "WEB-INF");
       File webInfLib = new File(webInf, "lib");
       if (webInfLib.exists()) {
         uris.addAll(ASClassLoaderUtil.getLibDirectoryJarURIs(webInfLib));
       }
     }
   } catch (Exception e) {
     logger.log(Level.WARNING, e.getMessage(), e);
   }
   return uris;
 }
예제 #6
0
  protected void configureContextXmlAttribute(
      WebappClassLoader cloader, File base, DeploymentContext dc)
      throws XMLStreamException, IOException {

    boolean consistent = true;
    Boolean value = null;

    File warContextXml = new File(base.getAbsolutePath(), WAR_CONTEXT_XML);
    if (warContextXml.exists()) {
      ContextXmlParser parser = new ContextXmlParser(warContextXml);
      value = parser.getClearReferencesStatic();
    }

    if (value == null) {
      Boolean domainCRS = null;
      File defaultContextXml = new File(serverEnvironment.getInstanceRoot(), DEFAULT_CONTEXT_XML);
      if (defaultContextXml.exists()) {
        ContextXmlParser parser = new ContextXmlParser(defaultContextXml);
        domainCRS = parser.getClearReferencesStatic();
      }

      List<Boolean> csrs = new ArrayList<Boolean>();
      HttpService httpService = serverConfig.getHttpService();
      DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class);
      String vsIDs = params.virtualservers;
      List<String> vsList = StringUtils.parseStringList(vsIDs, " ,");
      if (httpService != null && vsList != null && !vsList.isEmpty()) {
        for (VirtualServer vsBean : httpService.getVirtualServer()) {
          if (vsList.contains(vsBean.getId())) {
            Boolean csr = null;
            Property prop = vsBean.getProperty("contextXmlDefault");
            if (prop != null) {
              File contextXml = new File(serverEnvironment.getInstanceRoot(), prop.getValue());
              if (contextXml.exists()) { // vs context.xml
                ContextXmlParser parser = new ContextXmlParser(contextXml);
                csr = parser.getClearReferencesStatic();
              }
            }

            if (csr == null) {
              csr = domainCRS;
            }
            csrs.add(csr);
          }
        }

        // check that it is consistent
        for (Boolean b : csrs) {
          if (b != null) {
            if (value != null && !b.equals(value)) {
              consistent = false;
              break;
            }
            value = b;
          }
        }
      }
    }

    if (consistent) {
      if (value != null) {
        cloader.setClearReferencesStatic(value);
      }
    } else if (logger.isLoggable(Level.WARNING)) {
      logger.log(Level.WARNING, INCONSISTENT_CLEAR_REFERENCE_STATIC);
    }
  }
예제 #7
0
  @Override
  public ClassLoader getClassLoader(final ClassLoader parent, DeploymentContext context) {
    WebappClassLoader cloader =
        AccessController.doPrivileged(
            new PrivilegedAction<WebappClassLoader>() {
              @Override
              public WebappClassLoader run() {
                return new WebappClassLoader(parent);
              }
            });
    try {
      WebDirContext r = new WebDirContext();
      File base = new File(context.getSource().getURI());
      r.setDocBase(base.getAbsolutePath());

      cloader.setResources(r);
      cloader.addRepository("WEB-INF/classes/", new File(base, "WEB-INF/classes/"));
      if (context.getScratchDir("ejb") != null) {
        cloader.addRepository(context.getScratchDir("ejb").toURI().toURL().toString().concat("/"));
      }
      if (context.getScratchDir("jsp") != null) {
        cloader.setWorkDir(context.getScratchDir("jsp"));
      }

      // add libraries referenced from manifest
      for (URL url : getManifestLibraries(context)) {
        cloader.addRepository(url.toString());
      }

      WebXmlParser webXmlParser = getWebXmlParser(context.getSource());
      configureLoaderAttributes(cloader, webXmlParser, base);
      configureLoaderProperties(cloader, webXmlParser, base);

      configureContextXmlAttribute(cloader, base, context);

      try {
        final DeploymentContext dc = context;
        final ClassLoader cl = cloader;

        AccessController.doPrivileged(
            new PermsArchiveDelegate.SetPermissionsAction(
                SMGlobalPolicyUtil.CommponentType.war, dc, cl));
      } catch (PrivilegedActionException e) {
        throw new SecurityException(e.getException());
      }

    } catch (XMLStreamException xse) {
      logger.log(Level.SEVERE, xse.getMessage());
      if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, xse.getMessage(), xse);
      }
      xse.printStackTrace();
    } catch (IOException ioe) {
      logger.log(Level.SEVERE, ioe.getMessage());
      if (logger.isLoggable(Level.FINE)) {
        logger.log(Level.FINE, ioe.getMessage(), ioe);
      }
      ioe.printStackTrace();
    }

    cloader.start();

    return cloader;
  }