public void deployWar(final StandardContext standardContext, final String host, final AppInfo info) { // TODO: instead of storing deployers, we could just lookup the right hostconfig for the server. final HostConfig deployer = deployers.get(host); if (isReady(deployer)) { // if not ready using directly host to avoid a NPE if (info != null) { final ContextInfo contextInfo = addContextInfo(host, standardContext); contextInfo.appInfo = info; contextInfo.deployer = deployer; contextInfo.module = extractModule(standardContext, info); } deployer.manageApp(standardContext); } else { final Host theHost = hosts.get(host); if (theHost != null) { if (info != null) { final ContextInfo contextInfo = addContextInfo(host, standardContext); contextInfo.appInfo = info; contextInfo.host = theHost; contextInfo.module = extractModule(standardContext, info); } theHost.addChild(standardContext); } } }
if (state == 0) { tomcatWebAppBuilder.init(standardContext); } else if (state == 1) { Thread.currentThread().setContextClassLoader(standardContext.getLoader().getClassLoader()); try { tomcatWebAppBuilder.init(standardContext); tomcatWebAppBuilder.beforeStart(standardContext); tomcatWebAppBuilder.start(standardContext); tomcatWebAppBuilder.afterStart(standardContext); } finally { Thread.currentThread().setContextClassLoader(oldCL);
/** * {@inheritDoc} */ @Override public void undeployWebApps(final AppInfo appInfo) throws Exception { final String version = appVersion(appInfo); for (final WebAppInfo webApp : appInfo.webApps) { final ContextInfo contextInfo = getContextInfo(webApp.host, webApp.contextRoot, version); if (contextInfo != null) { final StandardContext standardContext = contextInfo.standardContext; if (!appInfo.webAppAlone || !appInfo.properties.containsKey("tomee.destroying")) { undeploy(standardContext, contextInfo); final File extracted = Contexts.warPath(standardContext); if (isExtracted(extracted)) { deleteDir(extracted); } removeContextInfo(standardContext); } } } }
/** * {@inheritDoc} */ @Override public void afterStop(StandardContext standardContext) { if (isIgnored(standardContext)) return; ContextInfo contextInfo = getContextInfo(standardContext); if (contextInfo != null && contextInfo.appInfo != null && contextInfo.deployer == null && getAssembler().getDeployedApplications().contains(contextInfo.appInfo)) { try { getAssembler().destroyApplication(contextInfo.appInfo.path); } catch (Exception e) { logger.error("Unable to stop web application " + standardContext.getPath() + ": Exception: " + e.getMessage(), e); } } removeContextInfo(standardContext); }
if (isIgnored(standardContext)) { return; if (shouldNotDeploy(standardContext)) { return; final CoreContainerSystem cs = getContainerSystem(); final Assembler a = getAssembler(); if (a == null) { logger.warning("OpenEJB has not been initialized so war will not be scanned for nested modules " + standardContext.getPath()); ContextInfo contextInfo = getContextInfo(standardContext); ClassLoader classLoader = standardContext.getLoader().getClassLoader(); safeBind(comp, "TransactionManager", transactionManager); safeBind(comp, "TransactionSynchronizationRegistry", synchronizationRegistry); } catch (final NamingException e) { final AppModule appModule = loadApplication(standardContext); appModule.getProperties().put("loader.from", "tomcat"); properties.setProperty("appName", getId(standardContext)); properties.setProperty("factory", (String) resource.getProperty("factory")); final Reference reference = createReference(resource); if (reference != null) { properties.put("reference", reference);
if (isIgnored(standardContext)) return; CoreContainerSystem cs = getContainerSystem(); Assembler a = getAssembler(); if (a == null) { logger.warning("OpenEJB has not been initialized so war will not be scanned for nested modules " + standardContext.getPath()); ContextInfo contextInfo = getContextInfo(standardContext); final ClassLoader classLoader = standardContext.getLoader().getClassLoader(); if (contextInfo == null) { AppModule appModule = loadApplication(standardContext); if (appModule != null) { try { contextInfo = addContextInfo(standardContext.getHostname(), standardContext); AppInfo appInfo = configurationFactory.configureApplication(appModule); contextInfo.appInfo = appInfo; undeploy(standardContext, contextInfo); logger.error("Unable to deploy collapsed ear in war " + standardContext.getPath() + ": Exception: " + e.getMessage(), e); if (("/" + w.contextRoot).equals(standardContext.getPath()) || isRootApplication(standardContext)) { webAppInfo = w; appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId); bindings.putAll(getJndiBuilder(classLoader, webAppInfo, injections).buildBindings(JndiEncBuilder.JndiScope.comp));
if (isIgnored(standardContext)) { return; if (shouldNotDeploy(standardContext)) { return; thread.setContextClassLoader(classLoader); try { standardContext.setRealm(tomeeRealm(realm)); } finally { thread.setContextClassLoader(originalLoader); final ContextInfo contextInfo = getContextInfo(standardContext); final String id = getId(standardContext); WebAppInfo currentWebAppInfo = null; for (final WebAppInfo webAppInfo : contextInfo.appInfo.webApps) { final String wId = getId(webAppInfo.host, webAppInfo.contextRoot, contextInfo.version); if (id.equals(wId)) { currentWebAppInfo = webAppInfo; ContextAccessController.setWritable(listenerName, standardContext.getNamingToken()); try { final Context openejbContext = (Context) getContainerSystem().getJNDIContext().lookup("openejb"); final Context root = (Context) ContextBindings.getClassLoader().lookup(""); final Context comp = (Context) ContextBindings.getClassLoader().lookup("comp"); // usually fails safeBind(root, "openejb", openejbContext);
if (isIgnored(standardContext)) return; ContextInfo contextInfo = getContextInfo(standardContext); if (contextInfo != null && contextInfo.appInfo == null) { return; try { Context openejbContext = getContainerSystem().getJNDIContext(); openejbContext = (Context) openejbContext.lookup("openejb"); safeBind(root, "openejb", openejbContext); boolean isRoot = isRootApplication(standardContext); if (("/" + webAppInfo.contextRoot).equals(standardContext.getPath()) || isRoot) { WebContext webContext = getContainerSystem().getWebContext(webAppInfo.moduleId); if (webContext != null) { webContext.setJndiEnc(comp); safeBind(comp, "TransactionManager", transactionManager); safeBind(comp, "TransactionSynchronizationRegistry", synchronizationRegistry); safeBind(comp, "ORB", new SystemComponentReference(ORB.class)); safeBind(comp, "HandleDelegate", new SystemComponentReference(HandleDelegate.class)); } catch (NamingException e) { final WebBeansListener webBeansListener = getWebBeansContext(contextInfo);
if (isIgnored(standardContext)) { return; final TomEEWebappClassLoader old = lazyClassLoader(standardContext); if (old != null) { // should always be the case TldScanner.forceCompleteClean(old); final ContextInfo contextInfo = getContextInfo(standardContext); boolean destroyFromTomcat = contextInfo != null && getAssembler().getDeployedApplications().contains(contextInfo.appInfo); if (destroyFromTomcat && isUnDeployable(contextInfo)) { contextInfo.appInfo.properties.setProperty("tomee.destroying", "true"); try { getAssembler().destroyApplication(contextInfo.appInfo.path); } catch (final Exception e) { logger.error("Unable to stop web application " + standardContext.getPath() + ": Exception: " + e.getMessage(), e); removeContextInfo(standardContext);
if (deployedApplication.appInfo != null) { // can happen with badly formed config try { getAssembler().destroyApplication(deployedApplication.appInfo.path); } catch (final Exception e) { logger.error("Unable to application " + deployedApplication.appInfo.path, e); final File appBase = appBase(standardHost); final File[] files = appBase.listFiles(); if (null != files) { if (name.toLowerCase().endsWith(".war") || isRoot(name) || name.equalsIgnoreCase("META-INF") || name.equalsIgnoreCase("WEB-INF")) { continue; if (isDeployed(file, standardHost)) { continue; getAssembler().createApplication(appInfo);
/** * {@inheritDoc} */ @Override public void undeployWebApps(AppInfo appInfo) throws Exception { for (WebAppInfo webApp : appInfo.webApps) { ContextInfo contextInfo = getContextInfo(webApp.host, webApp.contextRoot); if (contextInfo != null && contextInfo.deployer != null) { StandardContext standardContext = contextInfo.standardContext; HostConfig deployer = contextInfo.deployer; if (deployer != null) { deployer.unmanageApp(standardContext.getPath()); } else if (contextInfo.host != null) { contextInfo.host.removeChild(standardContext); } deleteDir(new File(standardContext.getServletContext().getRealPath(""))); removeContextInfo(standardContext); } } }
if (deployedApplication.isModified()) { try { getAssembler().destroyApplication(deployedApplication.appInfo.path); } catch (Exception e) { logger.error("Unable to application " + deployedApplication.appInfo.path + ": Exception: " + e.getMessage(), e); File appBase = appBase(standardHost); File[] files = appBase.listFiles(); for (File file : files) { if (isDeployed(file, standardHost)) { continue; getAssembler().createApplication(appInfo);
standardContext.addApplicationParameter(appParam); if (getContextInfo(webApp.host, webApp.contextRoot) == null) { if (standardContext.getPath() == null) { if (webApp.contextRoot != null && webApp.contextRoot.startsWith("/")) { if (isReady(deployer)) { // if not ready using directly host to avoid a NPE ContextInfo contextInfo = addContextInfo(host, standardContext); contextInfo.appInfo = appInfo; contextInfo.deployer = deployer; Host theHost = hosts.get(host); ContextInfo contextInfo = addContextInfo(host, standardContext); contextInfo.appInfo = appInfo; contextInfo.host = theHost;
@Override public void configureStart(StandardContext standardContext) { if (TomcatHelper.isTomcat7()) { TomcatHelper.configureJarScanner(standardContext); ContextTransaction contextTransaction = new ContextTransaction(); contextTransaction.setProperty(org.apache.naming.factory.Constants.FACTORY, UserTransactionFactory.class.getName()); standardContext.getNamingResources().setTransaction(contextTransaction); startInternal(standardContext); } // clear a bit log for default case addMyFacesDefaultParameters(standardContext.getLoader().getClassLoader(), standardContext.getServletContext()); }
tomcatWebAppBuilder = new TomcatWebAppBuilder(); tomcatWebAppBuilder.start(); SystemInstance.get().setComponent(WebAppBuilder.class, tomcatWebAppBuilder);
/** * Deletes given directory. * * @param dir directory */ private void deleteDir(File dir) { if (dir == null) { return; } if (dir.isFile()) { return; } for (File file : dir.listFiles()) { if (file.isDirectory()) { deleteDir(file); } else { file.delete(); } } dir.delete(); }
private WebBeansContext getWebBeansContext(final ContextInfo contextInfo) { final AppContext appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId); if (appContext == null) { return null; } WebBeansContext webBeansContext = appContext.getWebBeansContext(); if (webBeansContext == null) { return null; } for (final WebContext web : appContext.getWebContexts()) { final String stdName = removeFirstSlashAndWar(contextInfo.standardContext.getName()); if (stdName == null) { continue; } final String name = removeFirstSlashAndWar(web.getContextRoot()); if (stdName.equals(name)) { webBeansContext = web.getWebbeansContext(); if (Contexts.getHostname(contextInfo.standardContext).equals(web.getHost())) { break; } // else loop hoping to find a better matching } } if (webBeansContext == null) { webBeansContext = appContext.getWebBeansContext(); } return webBeansContext; }
private void check() { final StandardServer server = TomcatHelper.getServer(); for (final Service service : server.findServices()) { if (service.getContainer() instanceof Engine) { final Engine engine = (Engine) service.getContainer(); for (final Container engineChild : engine.findChildren()) { if (engineChild instanceof StandardHost) { final StandardHost host = (StandardHost) engineChild; webappBuilder.checkHost(host); } } } } }
private WebBeansListener getWebBeansContext(ContextInfo contextInfo) { final AppContext appContext = getContainerSystem().getAppContext(contextInfo.appInfo.appId); if (appContext == null) return null; final WebBeansContext webBeansContext = appContext.getWebBeansContext(); if (webBeansContext == null) return null; return new WebBeansListener(webBeansContext); }
@Override public void configureStart(final LifecycleEvent event, final StandardContext standardContext) { final ContextTransaction contextTransaction = new ContextTransaction(); contextTransaction.setProperty(org.apache.naming.factory.Constants.FACTORY, UserTransactionFactory.class.getName()); standardContext.getNamingResources().setTransaction(contextTransaction); if (event != null) { // ensure NamingContext is available for eager usage (@Observes @Initialized(ApplicationScoped) for instance) standardContext.getNamingContextListener().lifecycleEvent(event); } TomcatHelper.configureJarScanner(standardContext); startInternal(standardContext); // clear a bit log for default case addMyFacesDefaultParameters(standardContext.getLoader().getClassLoader(), standardContext.getServletContext()); // breaks cdi standardContext.setTldValidation(Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.tld.validation", "false"))); // breaks jstl standardContext.setXmlValidation(Boolean.parseBoolean(SystemInstance.get().getProperty("tomee.xml.validation", "false"))); }