Search in sources :

Example 16 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class TomcatWebAppBuilder method checkHost.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void checkHost(final StandardHost standardHost) {
    if (noHostCheck) {
        return;
    }
    if (standardHost.getAutoDeploy()) {
        // Undeploy any modified application
        for (final Iterator<Map.Entry<String, DeployedApplication>> iterator = deployedApps.entrySet().iterator(); iterator.hasNext(); ) {
            final Map.Entry<String, DeployedApplication> entry = iterator.next();
            final DeployedApplication deployedApplication = entry.getValue();
            if (deployedApplication.isModified()) {
                // TODO: for war use StandardContext.redeploy()
                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);
                    }
                } else {
                    logger.error("appinfo is null for " + deployedApplication);
                }
                iterator.remove();
            }
        }
        // Deploy new applications
        final File appBase = appBase(standardHost);
        final File[] files = appBase.listFiles();
        if (null != files) {
            for (File file : files) {
                if (file.getName().endsWith(".tmp")) {
                    // tomcat is uploading, see org.apache.catalina.manager.ManagerServlet.deploy(java.io.PrintWriter, org.apache.catalina.util.ContextName, java.lang.String, boolean, javax.servlet.http.HttpServletRequest, org.apache.tomcat.util.res.StringManager)
                    continue;
                }
                final String name = file.getName();
                // ignore war files
                if (name.toLowerCase().endsWith(".war") || isRoot(name) || name.equalsIgnoreCase("META-INF") || name.equalsIgnoreCase("WEB-INF")) {
                    continue;
                }
                // Simple fix for TOMEE-23
                if (name.toLowerCase().equals(".ds_store")) {
                    continue;
                }
                // ignore unpacked web apps
                if (file.isDirectory() && new File(file, "WEB-INF").exists()) {
                    continue;
                }
                // ignore unpacked apps where packed version is present (packed version is owner)
                if (file.isDirectory() && (new File(file.getParent(), file.getName() + ".ear").exists() || new File(file.getParent(), file.getName() + ".war").exists() || new File(file.getParent(), file.getName() + ".rar").exists())) {
                    continue;
                }
                // ignore already deployed apps
                if (isDeployed(file, standardHost)) {
                    continue;
                }
                final AppInfo appInfo;
                try {
                    file = file.getCanonicalFile().getAbsoluteFile();
                    final AppModule appModule = deploymentLoader.load(file, null);
                    // Ignore any standalone web modules - this happens when the app is unpaked and doesn't have a WEB-INF dir
                    if (appModule.getDeploymentModule().size() == 1 && appModule.getWebModules().size() == 1) {
                        final WebModule webModule = appModule.getWebModules().iterator().next();
                        if (file.getAbsolutePath().equals(webModule.getJarLocation())) {
                            continue;
                        }
                    }
                    // tell web modules to deploy using this host
                    for (final WebModule webModule : appModule.getWebModules()) {
                        webModule.setHost(standardHost.getName());
                    }
                    appInfo = configurationFactory.configureApplication(appModule);
                    if (file.isFile() && file.getName().toLowerCase().endsWith(".ear")) {
                        // this is to prevent any WARs inside the EARs being unpacked in a directory where they'll then be deployed again
                        appInfo.properties.setProperty("tomcat.unpackWar", "false");
                    }
                    // if this is an unpacked dir, tomcat will pick it up as a webapp so undeploy it first
                    if (file.isDirectory()) {
                        final ContainerBase context = (ContainerBase) standardHost.findChild("/" + name);
                        if (context != null) {
                            try {
                                standardHost.removeChild(context);
                            } catch (final Throwable t) {
                                logger.warning("Error undeploying wep application from Tomcat  " + name, t);
                            }
                            try {
                                context.destroy();
                            } catch (final Throwable t) {
                                logger.warning("Error destroying Tomcat web context " + name, t);
                            }
                        }
                    }
                    getAssembler().createApplication(appInfo);
                    deployedApps.put(file.getAbsolutePath(), new DeployedApplication(file, appInfo));
                } catch (final Throwable e) {
                    logger.warning("Error deploying application " + file.getAbsolutePath(), e);
                }
            }
        }
    }
}
Also used : ContainerBase(org.apache.catalina.core.ContainerBase) AppModule(org.apache.openejb.config.AppModule) WebModule(org.apache.openejb.config.WebModule) LifecycleException(org.apache.catalina.LifecycleException) NameNotFoundException(javax.naming.NameNotFoundException) IOException(java.io.IOException) NamingException(javax.naming.NamingException) OpenEJBException(org.apache.openejb.OpenEJBException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) AppInfo(org.apache.openejb.assembler.classic.AppInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) EnvEntry(org.apache.openejb.jee.EnvEntry) JarEntry(java.util.jar.JarEntry) Map(java.util.Map) TreeMap(java.util.TreeMap) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) File(java.io.File) JarFile(java.util.jar.JarFile)

Example 17 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class CheckDescriptorLocation method validate.

@Override
public void validate(final AppModule appModule) {
    final List<String> validated = new ArrayList<String>();
    for (final WebModule webModule : safe(appModule.getWebModules())) {
        validated.add(webModule.getModuleId());
        validateWebModule(webModule);
    }
    for (final EjbModule ejbModule : safe(appModule.getEjbModules())) {
        // without this check, CheckDescriptorLocationTest#testWarWithDescriptorInRoot() would fail
        if (!validated.contains(ejbModule.getModuleId())) {
            validateEjbModule(ejbModule);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) EjbModule(org.apache.openejb.config.EjbModule) WebModule(org.apache.openejb.config.WebModule)

Example 18 with WebModule

use of org.apache.openejb.config.WebModule in project tomee by apache.

the class SimplePojoTest method war.

@Module
@Classes(cdi = true, value = { MyFirstRestClass.class })
public WebModule war() {
    final WebModule webModule = new WebModule(new WebApp(), "/foo", Thread.currentThread().getContextClassLoader(), "", "foo");
    webModule.getRestClasses().add(MyFirstRestClass.class.getName());
    return webModule;
}
Also used : MyFirstRestClass(org.apache.openejb.server.cxf.rs.beans.MyFirstRestClass) WebModule(org.apache.openejb.config.WebModule) WebApp(org.apache.openejb.jee.WebApp) WebModule(org.apache.openejb.config.WebModule) Module(org.apache.openejb.testing.Module) Classes(org.apache.openejb.testing.Classes)

Aggregations

WebModule (org.apache.openejb.config.WebModule)18 AppModule (org.apache.openejb.config.AppModule)9 EjbModule (org.apache.openejb.config.EjbModule)9 File (java.io.File)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 WebApp (org.apache.openejb.jee.WebApp)5 OpenejbJar (org.apache.openejb.jee.oejb3.OpenejbJar)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 EjbJar (org.apache.openejb.jee.EjbJar)4 Module (org.apache.openejb.testing.Module)4 URL (java.net.URL)3 LinkedList (java.util.LinkedList)3 OpenEJBException (org.apache.openejb.OpenEJBException)3 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)3 Beans (org.apache.openejb.jee.Beans)3 EnvEntry (org.apache.openejb.jee.EnvEntry)3 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2