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. } } } }
@Override public String getVersionIdentifier(ReadableArchive archive) { String versionIdentifierValue = null; try { WebXmlParser webXmlParser = getWebXmlParser(archive); versionIdentifierValue = webXmlParser.getVersionIdentifier(); } catch (XMLStreamException e) { logger.log(Level.SEVERE, e.getMessage()); } catch (IOException e) { logger.log(Level.SEVERE, e.getMessage()); } return versionIdentifierValue; }
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); } } } } }
/** * Parse the web.xml and publish the corresponding web app. The received list is expected to * contain one URL of an web.xml (only first is used. The web.xml will be parsed and resulting web * application structure will be registered with the http service. * * @throws NullArgumentException if bundle or list of web xmls is null * @throws PreConditionException if the list of web xmls is empty or more then one xml * @see BundleObserver#addingEntries(Bundle,List) */ public void addingEntries(final Bundle bundle, final List<URL> entries) { NullArgumentException.validateNotNull(bundle, "Bundle"); NullArgumentException.validateNotNull(entries, "List of *.xml's"); // Context name is also needed for some of the pre-condition checks, therefore it is retrieved // here. String contextName = extractContextName(bundle); LOG.info(String.format("Using [%s] as web application context name", contextName)); List<String> virtualHostList = extractVirtualHostList(bundle); LOG.info(String.format("[%d] virtual hosts defined in bundle header", virtualHostList.size())); List<String> connectorList = extractConnectorList(bundle); LOG.info(String.format("[%d] connectors defined in bundle header", connectorList.size())); // try-catch only to inform framework and listeners of an event. try { // PreConditionException.validateLesserThan( entries.size(), 3, "Number of xml's" ); PreConditionException.validateEqualTo( "WEB-INF".compareToIgnoreCase(Path.getDirectParent(entries.get(0))), 0, "Direct parent of web.xml"); } catch (PreConditionException pce) { LOG.error(pce.getMessage(), pce); eventDispatcher.webEvent( new WebEvent(WebEvent.FAILED, "/" + contextName, bundle, bundleContext.getBundle(), pce)); throw pce; } if (webApps.containsKey(bundle.getBundleId())) { LOG.debug( String.format("Already found a web application in bundle %d", bundle.getBundleId())); return; } URL webXmlURL = null; // = entries.get( 0 ); URL jettyWebXmlURL = null; for (URL url : entries) { if (isJettyWebXml(url)) { // it's the jetty-web.xml jettyWebXmlURL = url; } else if (isWebXml(url)) { // it's the web.xml webXmlURL = url; } else { // just another one } } if (webXmlURL == null) { PreConditionException pce = new PreConditionException("no web.xml configured in web-application"); LOG.error(pce.getMessage(), pce); eventDispatcher.webEvent( new WebEvent(WebEvent.FAILED, "/" + contextName, bundle, bundleContext.getBundle(), pce)); throw pce; } LOG.debug("Parsing a web application from [" + webXmlURL + "]"); String rootPath = extractRootPath(bundle); LOG.info(String.format("Using [%s] as web application root path", rootPath)); InputStream is = null; try { is = webXmlURL.openStream(); final WebApp webApp = m_parser.parse(bundle, is); if (webApp != null) { LOG.debug("Parsed web app [" + webApp + "]"); webApp.setWebXmlURL(webXmlURL); webApp.setJettyWebXmlURL(jettyWebXmlURL); webApp.setVirtualHostList(virtualHostList); webApp.setConnectorList(connectorList); webApp.setBundle(bundle); webApp.setContextName(contextName); webApp.setRootPath(rootPath); webApp.setDeploymentState(WebApp.UNDEPLOYED_STATE); webApps.put(bundle.getBundleId(), webApp); // The Webapp-Deploy header controls if the app is deployed on // startup. if ("true".equals(opt(getHeader(bundle, "Webapp-Deploy"), "true"))) { deploy(webApp); } else { eventDispatcher.webEvent( new WebEvent( WebEvent.UNDEPLOYED, "/" + webApp.getContextName(), webApp.getBundle(), bundleContext.getBundle())); } } } catch (Exception ignore) { LOG.error("Could not parse web.xml", ignore); eventDispatcher.webEvent( new WebEvent( WebEvent.FAILED, "/" + contextName, bundle, bundleContext.getBundle(), ignore)); } finally { if (is != null) { try { is.close(); } catch (IOException ignore) { // just ignore } } } }