Search in sources :

Example 1 with StandardRoot

use of org.apache.catalina.webresources.StandardRoot in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method customize.

@Test
public void customize() {
    Context standardContext = mock(Context.class);
    StandardRoot webResourceRoot = new StandardRoot(standardContext);
    Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
    Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
    JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
    jsfTomcatContextCustomizer.customize(standardContext);
    JsfTomcatApplicationListener jsfTomcatApplicationListener = new JsfTomcatApplicationListener(jsfTomcatContextCustomizer.getContext());
    jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
    assertThat(webResourceRoot.getPostResources().length).isGreaterThanOrEqualTo(9);
}
Also used : Context(org.apache.catalina.Context) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) StandardRoot(org.apache.catalina.webresources.StandardRoot) Test(org.junit.Test)

Example 2 with StandardRoot

use of org.apache.catalina.webresources.StandardRoot in project joinfaces by joinfaces.

the class JsfTomcatApplicationListenerIT method customizeTargetTestClasses.

@Test
public void customizeTargetTestClasses() {
    Context standardContext = mock(Context.class);
    StandardRoot webResourceRoot = new StandardRoot(standardContext);
    Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
    Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
    String absolutePath = new File("").getAbsolutePath();
    String internalPath = METAINF_RESOURCES;
    String targetTestClassesBase = absolutePath + "/" + "target/test-classes";
    File testClassesResources = new File(targetTestClassesBase + internalPath);
    if (!testClassesResources.mkdirs()) {
        throw new RuntimeException("Could not create dir: " + testClassesResources.toString());
    }
    JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
    jsfTomcatContextCustomizer.customize(standardContext);
    JsfTomcatApplicationListener jsfTomcatApplicationListener = new JsfTomcatApplicationListener(jsfTomcatContextCustomizer.getContext());
    jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));
    if (!testClassesResources.delete()) {
        throw new RuntimeException("Could not delete dir: " + testClassesResources.toString());
    }
    assertThat(webResourceRoot.getPostResources().length).isGreaterThanOrEqualTo(10);
}
Also used : Context(org.apache.catalina.Context) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) StandardRoot(org.apache.catalina.webresources.StandardRoot) File(java.io.File) Test(org.junit.Test)

Example 3 with StandardRoot

use of org.apache.catalina.webresources.StandardRoot in project ofbiz-framework by apache.

the class CatalinaContainer method prepareContext.

private StandardContext prepareContext(Host host, ContainerConfig.Configuration configuration, ComponentConfig.WebappInfo appInfo, Property clusterProp) throws ContainerException {
    StandardContext context = new StandardContext();
    Tomcat.initWebappDefaults(context);
    String location = getWebappRootLocation(appInfo);
    boolean contextIsDistributable = isContextDistributable(configuration, location);
    context.setParent(host);
    context.setDocBase(location);
    context.setPath(getWebappMountPoint(appInfo));
    context.addLifecycleListener(new ContextConfig());
    context.setJ2EEApplication("OFBiz");
    context.setJ2EEServer("OFBiz Container");
    context.setLoader(new WebappLoader(Thread.currentThread().getContextClassLoader()));
    context.setDisplayName(appInfo.name);
    context.setDocBase(location);
    context.setReloadable(ContainerConfig.getPropertyValue(configuration, "apps-context-reloadable", false));
    context.setDistributable(contextIsDistributable);
    context.setCrossContext(ContainerConfig.getPropertyValue(configuration, "apps-cross-context", true));
    context.setPrivileged(appInfo.privileged);
    context.getServletContext().setAttribute("_serverId", appInfo.server);
    context.getServletContext().setAttribute("componentName", appInfo.componentConfig.getComponentName());
    if (clusterProp != null && contextIsDistributable) {
        context.setManager(prepareClusterManager(clusterProp));
    }
    StandardRoot resources = new StandardRoot(context);
    resources.setAllowLinking(true);
    context.setResources(resources);
    JarScanner jarScanner = context.getJarScanner();
    if (jarScanner instanceof StandardJarScanner) {
        StandardJarScanner standardJarScanner = (StandardJarScanner) jarScanner;
        standardJarScanner.setJarScanFilter(new FilterJars());
        standardJarScanner.setScanClassPath(true);
    }
    Map<String, String> initParameters = appInfo.getInitParameters();
    // request dumper filter
    if ("true".equals(initParameters.get("enableRequestDump"))) {
        FilterDef requestDumperFilterDef = new FilterDef();
        requestDumperFilterDef.setFilterClass(RequestDumperFilter.class.getName());
        requestDumperFilterDef.setFilterName("RequestDumper");
        context.addFilterDef(requestDumperFilterDef);
        FilterMap requestDumperFilterMap = new FilterMap();
        requestDumperFilterMap.setFilterName("RequestDumper");
        requestDumperFilterMap.addURLPattern("*");
        context.addFilterMap(requestDumperFilterMap);
    }
    // set the init parameters
    initParameters.entrySet().forEach(entry -> context.addParameter(entry.getKey(), entry.getValue()));
    return context;
}
Also used : FilterDef(org.apache.tomcat.util.descriptor.web.FilterDef) RequestDumperFilter(org.apache.catalina.filters.RequestDumperFilter) StandardRoot(org.apache.catalina.webresources.StandardRoot) JarScanner(org.apache.tomcat.JarScanner) StandardJarScanner(org.apache.tomcat.util.scan.StandardJarScanner) FilterMap(org.apache.tomcat.util.descriptor.web.FilterMap) ContextConfig(org.apache.catalina.startup.ContextConfig) StandardContext(org.apache.catalina.core.StandardContext) StandardJarScanner(org.apache.tomcat.util.scan.StandardJarScanner) WebappLoader(org.apache.catalina.loader.WebappLoader)

Example 4 with StandardRoot

use of org.apache.catalina.webresources.StandardRoot in project kontraktor by RuedigerMoeller.

the class TomcatEmbeddedMain method main.

public static void main(String[] args) throws Exception {
    String webappDirLocation = "src/main/webapp/";
    Tomcat tomcat = new Tomcat();
    if (!new File(webappDirLocation + "client/index.html").exists()) {
        System.out.println("Please run with working dir: '[..]examples/servlet");
        System.exit(-1);
    }
    // The port that we should run on can be set into an environment variable
    // Look for that variable and default to 8080 if it isn't there.
    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty()) {
        webPort = "8080";
    }
    tomcat.setPort(Integer.valueOf(webPort));
    StandardContext ctx = (StandardContext) tomcat.addWebapp("", new File(webappDirLocation).getAbsolutePath());
    System.out.println("configuring app with basedir: " + new File("./" + webappDirLocation).getAbsolutePath());
    // Declare an alternative location for your "WEB-INF/classes" dir
    // Servlet 3.0 annotation will work
    File additionWebInfClasses = new File("target/classes");
    WebResourceRoot resources = new StandardRoot(ctx);
    resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
    ctx.setResources(resources);
    tomcat.start();
    tomcat.getServer().await();
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) DirResourceSet(org.apache.catalina.webresources.DirResourceSet) StandardContext(org.apache.catalina.core.StandardContext) StandardRoot(org.apache.catalina.webresources.StandardRoot) File(java.io.File) WebResourceRoot(org.apache.catalina.WebResourceRoot)

Example 5 with StandardRoot

use of org.apache.catalina.webresources.StandardRoot in project component-runtime by Talend.

the class EnhancedCli method run.

@Override
public void run() {
    try {
        try (final Meecrowave meecrowave = new Meecrowave(create(args))) {
            this.instance = meecrowave;
            meecrowave.start();
            meecrowave.deployClasspath(new Meecrowave.DeploymentMeta("", null, stdCtx -> {
                stdCtx.setResources(new StandardRoot() {

                    @Override
                    protected void registerURLStreamHandlerFactory() {
                    // no-op: not supported into OSGi since there is already one and it must set a
                    // single time
                    }
                });
            }));
            doWait(meecrowave, null);
        }
    } catch (final Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : StandardRoot(org.apache.catalina.webresources.StandardRoot) Optional.ofNullable(java.util.Optional.ofNullable) StandardServer(org.apache.catalina.core.StandardServer) Meecrowave(org.apache.meecrowave.Meecrowave) Cli(org.apache.meecrowave.runner.Cli) StandardRoot(org.apache.catalina.webresources.StandardRoot) Meecrowave(org.apache.meecrowave.Meecrowave)

Aggregations

StandardRoot (org.apache.catalina.webresources.StandardRoot)25 File (java.io.File)19 StandardContext (org.apache.catalina.core.StandardContext)16 Tomcat (org.apache.catalina.startup.Tomcat)14 Test (org.junit.Test)11 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)7 Context (org.apache.catalina.Context)6 URLClassLoader (java.net.URLClassLoader)4 WebResourceRoot (org.apache.catalina.WebResourceRoot)4 StandardJarScanner (org.apache.tomcat.util.scan.StandardJarScanner)4 WebappLoader (org.apache.catalina.loader.WebappLoader)3 ServletContext (jakarta.servlet.ServletContext)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 DirResourceSet (org.apache.catalina.webresources.DirResourceSet)2 CoreContainerSystem (org.apache.openejb.core.CoreContainerSystem)2 JarScanner (org.apache.tomcat.JarScanner)2 ByteChunk (org.apache.tomcat.util.buf.ByteChunk)2 FilterMap (org.apache.tomcat.util.descriptor.web.FilterMap)2