Java 类org.apache.catalina.WebResourceRoot 实例源码

项目:light    文件:TomcatMain.java   
public static void main(String[] args) throws Exception
{
    String userDir = System.getProperty("user.dir") + File.separator + "server.tomcat";
    String webappDirLocation = userDir + File.separator +"src/main/webapp/";
    Tomcat tomcat = new Tomcat();

    String webPort = System.getenv("PORT");
    if (webPort == null || webPort.isEmpty())
    {
        webPort = "8080";
    }

    tomcat.setPort(Integer.valueOf(webPort));

    System.out.println("configuring app with basedir: " + new File(webappDirLocation).getAbsolutePath());

    StandardContext standardContext = (StandardContext) tomcat.addWebapp("/", new File(webappDirLocation).getAbsolutePath());
    File additionWebInfClasses = new File(userDir + File.separator + "build/classes");
    WebResourceRoot resourceRoot = new StandardRoot(standardContext);
    resourceRoot.addPreResources(new DirResourceSet(resourceRoot, "/WEB-INF/classes", additionWebInfClasses.getAbsolutePath(), "/"));
    standardContext.setResources(resourceRoot);

    tomcat.start();
    tomcat.getServer().await();
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
/**
 * Inform tomcat runtime setup. UNPACKAGED_WAR not covered yet.
 * @param resources of the tomcat
 * @return tomcat runtime
 */
TomcatRuntime getTomcatRuntime(WebResourceRoot resources) {
    TomcatRuntime result = null;

    if (isUberJar(resources)) {
        result = TomcatRuntime.UBER_JAR;
    }
    else if (isUberWar(resources)) {
        result = TomcatRuntime.UBER_WAR;
    }
    else if (isTesting(resources)) {
        result = TomcatRuntime.TEST;
    }
    else if (isUnpackagedJar(resources)) {
        result = TomcatRuntime.UNPACKAGED_JAR;
    }

    return result;
}
项目:joinfaces    文件:JsfTomcatApplicationListenerIT.java   
@Test
public void jarResourcesNull() throws LifecycleException {
    Context standardContext = mock(Context.class);
    WebResourceRoot webResourceRoot = mock(WebResourceRoot.class);
    Mockito.when(standardContext.getResources()).thenReturn(webResourceRoot);
    Mockito.when(standardContext.getAddWebinfClassesResources()).thenReturn(Boolean.FALSE);
    Mockito.when(webResourceRoot.getJarResources()).thenReturn(null);

    JsfTomcatContextCustomizer jsfTomcatContextCustomizer = new JsfTomcatContextCustomizer();
    jsfTomcatContextCustomizer.customize(standardContext);

    JsfTomcatApplicationListener jsfTomcatApplicationListener = JsfTomcatApplicationListener
        .builder().context(jsfTomcatContextCustomizer.getContext()).build();
    jsfTomcatApplicationListener.onApplicationEvent(mock(ApplicationReadyEvent.class));

    assertThat(jsfTomcatApplicationListener)
        .isNotNull();
}
项目:RAFTools    文件:RAFSResource.java   
public RAFSResource(WebResourceRoot root, Path path, RAFS rafs) {
    super(root, path);

    m_RAFS = rafs;

    m_Cache = null;

    try {

        if(Files.exists(path) && !Files.isDirectory(path) && isInRAF()) {
            Version v = rafs.getVersionDataForFile(path, null);
            if(v != null) {
                m_Cache = v.dataSource.read();
            }
        }
    } catch(IOException e) {
        m_Cache = null;
    }
}
项目:upload-parser    文件:TomcatIntegrationTest.java   
/**
 * Sets up the test environment, generates data to upload, starts a
 * Tomcat instance which will receive the client requests.
 * @throws Exception If an error occurred with the servlets
 */
@BeforeClass
public static void setUpClass() throws Exception {
    server = new Tomcat();

    Path base = Paths.get("build/tomcat");
    Files.createDirectories(base);

    server.setPort(8100);
    server.setBaseDir("build/tomcat");
    server.getHost().setAppBase("build/tomcat");
    server.getHost().setAutoDeploy(true);
    server.getHost().setDeployOnStartup(true);

    StandardContext context = (StandardContext) server.addWebapp("/", base.toAbsolutePath().toString());

    Path additionWebInfClasses = Paths.get("build/classes");
    WebResourceRoot resources = new StandardRoot(context);
    resources.addPreResources(new DirResourceSet(resources, "/WEB-INF/classes",
            additionWebInfClasses.toAbsolutePath().toString(), "/"));
    context.setResources(resources);
    context.getJarScanner().setJarScanFilter((jarScanType, jarName) -> false);

    server.start();
}
项目:find    文件:TomcatConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    final TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();

    if(useReverseProxy) {
        tomcat.addAdditionalTomcatConnectors(createAjpConnector());
    }

    // Set the web resources cache size (this defaults to 10MB but that is too small for Find)
    tomcat.addContextCustomizers(context -> {
        final WebResourceRoot resources = new StandardRoot(context);
        resources.setCacheMaxSize(webResourcesCacheSize);
        context.setResources(resources);
    });

    tomcat.addConnectorCustomizers(connector -> {
        connector.setMaxPostSize(connectorMaxPostSize);
    });

    return tomcat;
}
项目:metric    文件:Startup.java   
public static void main(String[] args) {
    Connector connector = new Connector();
    connector.setPort(80);
    Tomcat tomcat = new Tomcat();
    tomcat.setPort(80);
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);
    try {
        Context ctx = tomcat.addWebapp("", Conf.getAbsolutePath("../src/main/webapp"));
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(new DirResourceSet(resources,
                "/WEB-INF/classes", Conf.getAbsolutePath("classes"), "/"));
        ctx.setResources(resources);

        Server server = tomcat.getServer();
        server.start();
        server.setPort(8005);
        server.await();
        server.stop();
    } catch (ServletException | LifecycleException e) {
        Log.e(e);
    }
}
项目:tomee    文件:TomEEWebappClassLoader.java   
@Override
public void setResources(final WebResourceRoot resources) {
    this.resources = resources;
    if (StandardRoot.class.isInstance(resources)) {
        final List<WebResourceSet> jars = (List<WebResourceSet>) Reflections.get(resources, "jarResources");
        if (jars != null && !jars.isEmpty()) {
            final Iterator<WebResourceSet> jarIt = jars.iterator();
            while (jarIt.hasNext()) {
                final WebResourceSet set = jarIt.next();
                if (set.getBaseUrl() == null) {
                    continue;
                }
                final File file = URLs.toFile(set.getBaseUrl());
                try {
                    if (file.exists() && (!TomEEClassLoaderEnricher.validateJarFile(file) || !jarIsAccepted(file))) {
                        // need to remove this resource
                        LOGGER.warning("Removing " + file.getAbsolutePath() + " since it is offending");
                        jarIt.remove();
                    }
                } catch (final IOException e) {
                    // ignore
                }
            }
        }
    }
}
项目:tomee    文件:TomcatWebAppBuilder.java   
/**
 * {@inheritDoc}
 */
@Override
public void destroy(final StandardContext standardContext) {
    final Loader standardContextLoader = standardContext.getLoader();
    if (LazyStopLoader.class.isInstance(standardContextLoader)) {
        final Loader delegate = LazyStopLoader.class.cast(standardContextLoader).getDelegateLoader();
        if (TomEEWebappLoader.class.isInstance(delegate)) {
            final TomEEWebappLoader webappLoader = TomEEWebappLoader.class.cast(delegate);
            final ClassLoader loader = webappLoader.internalLoader();
            webappLoader.clearLoader();
            if (TomEEWebappClassLoader.class.isInstance(loader)) {
                TomEEWebappClassLoader.class.cast(loader).internalDestroy();
            }
        }
    }

    final WebResourceRoot root = standardContext.getResources();
    if (LazyStopStandardRoot.class.isInstance(root)) {
        try {
            LazyStopStandardRoot.class.cast(root).internalDestroy();
        } catch (final LifecycleException e) {
            throw new IllegalStateException(e);
        }
    }
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private JarWarResourceSet getFirstJarWarResourceSetAtJarResources(WebResourceRoot resources) {
    JarWarResourceSet result = null;
    for (WebResourceSet resourceSet :resources.getJarResources()) {
        if (resourceSet instanceof JarWarResourceSet) {
            result = (JarWarResourceSet) resourceSet;
            break;
        }
    }
    return result;
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private URL mainFile(WebResourceRoot resources) {
    URL result = null;
    for (WebResourceSet resourceSet :resources.getJarResources()) {
        if (resourceSet instanceof JarWarResourceSet) {
            result = resourceSet.getBaseUrl();
            break;
        }
    }
    return result;
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private void addMainJarResourceSet(WebResourceRoot resources) throws URISyntaxException {
    String webAppMount = "/";
    String archivePath = null;
    String internalPath = "/META-INF/resources";

    resources.createWebResourceSet(WebResourceRoot.ResourceSetType.POST,
        webAppMount, base(mainFile(resources)), archivePath, internalPath);
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private void addClasspathResourceSets(WebResourceRoot resources) throws URISyntaxException {
    String webAppMount = "/";
    String archivePath = null;
    String internalPath = "/META-INF/resources";

    for (URL url : ClasspathHelper.forResource("META-INF/resources/", this.getClass().getClassLoader())) {
        resources.createWebResourceSet(WebResourceRoot.ResourceSetType.POST,
            webAppMount, base(url), archivePath, internalPath);
    }
}
项目:armeria    文件:JarSubsetResourceSet.java   
JarSubsetResourceSet(WebResourceRoot root, String webAppMount, String base, String internalPath,
                     String jarRoot) {
    super(root, webAppMount, base, internalPath);

    // Should be normalized by TomcatServiceBuilder.
    assert !"/".equals(jarRoot) : "JarResourceSet should be used instead.";
    assert jarRoot.startsWith("/") : "jarRoot must be absolute.";
    assert !jarRoot.endsWith("/") : "jarRoot must not end with '/'.";

    prefix = jarRoot.substring(1) + '/';
}
项目:heroku-identity-java    文件:Main.java   
public static void main(String[] args) throws Exception {

        String webappDirLocation = "src/main/webapp/";
        Tomcat tomcat = new Tomcat();

        //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();
    }
项目:metric    文件:Startup.java   
public static void main(String[] args) {
    Connector connector = new Connector();
    connector.setPort(80);
    Tomcat tomcat = new Tomcat();
    tomcat.setPort(80);
    tomcat.getService().addConnector(connector);
    tomcat.setConnector(connector);
    try {
        Context ctx = tomcat.addWebapp("", Conf.getAbsolutePath("../src/main/webapp"));
        // Ensure to Load All Classes in the Same Class Loader
        ctx.setLoader(new WebappLoader(Startup.class.getClassLoader()) {
            @Override
            public ClassLoader getClassLoader() {
                return Startup.class.getClassLoader();
            }
        });
        WebResourceRoot resources = new StandardRoot(ctx);
        resources.addPreResources(new DirResourceSet(resources,
                "/WEB-INF/classes", Conf.getAbsolutePath("classes"), "/"));
        ctx.setResources(resources);

        Server server = tomcat.getServer();
        server.start();
        server.setPort(8005);
        server.await();
        server.stop();
    } catch (ServletException | LifecycleException e) {
        Log.e(e);
    }
}
项目:cims-server    文件:WebConfig.java   
@Bean
public EmbeddedServletContainerFactory servletContainer() {
    return new TomcatEmbeddedServletContainerFactory() {
        @Override
        protected void postProcessContext(Context ctx) {
            final int sizeInKB = 32 * 1024;  // default is 10MiB, increase to 32
            WebResourceRoot resourceRoot = new StandardRoot(ctx);
            resourceRoot.setCacheMaxSize(sizeInKB);
            ctx.setResources(resourceRoot);
        }
    };
}
项目:executable-embeded-tomcat-sample    文件:EmbededContextConfig.java   
/**
 * Scan JARs that contain web-fragment.xml files that will be used to
 * configure this application to see if they also contain static resources.
 * If static resources are found, add them to the context. Resources are
 * added in web-fragment.xml priority order.
 */
@Override
protected void processResourceJARs(Set<WebXml> fragments) {
    for (WebXml fragment : fragments) {
        URL url = fragment.getURL();

        try {
            String urlString = url.toString();
            if (isInsideNestedJar(urlString)) {
                // It's a nested jar but we now don't want the suffix
                // because
                // Tomcat
                // is going to try and locate it as a root URL (not the
                // resource
                // inside it)
                urlString = urlString.substring(0, urlString.length() - 2);
            }
            url = new URL(urlString);

            if ("jar".equals(url.getProtocol())) {
                try (Jar jar = JarFactory.newInstance(url)) {
                    jar.nextEntry();
                    String entryName = jar.getEntryName();
                    while (entryName != null) {
                        if (entryName.startsWith("META-INF/resources/")) {
                            context.getResources().createWebResourceSet(
                                    WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/", url, "/META-INF/resources");
                            break;
                        }
                        jar.nextEntry();
                        entryName = jar.getEntryName();
                    }
                }
            } else if ("file".equals(url.getProtocol())) {
                File file = new File(url.toURI());
                File resources = new File(file, "META-INF/resources/");
                if (resources.isDirectory()) {
                    context.getResources().createWebResourceSet(WebResourceRoot.ResourceSetType.RESOURCE_JAR, "/",
                            resources.getAbsolutePath(), null, "/");
                }
            }
        } catch (IOException ioe) {
            log.error(sm.getString("contextConfig.resourceJarFail", url, context.getName()));
        } catch (URISyntaxException e) {
            log.error(sm.getString("contextConfig.resourceJarFail", url, context.getName()));
        }
    }
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private boolean isUberJar(WebResourceRoot resources) {
    JarWarResourceSet jarWarResourceSet = getFirstJarWarResourceSetAtJarResources(resources);
    return jarWarResourceSet != null
            && jarWarResourceSet.getBaseUrl().getFile().endsWith(".jar");
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private boolean isUberWar(WebResourceRoot resources) {
    JarWarResourceSet jarWarResourceSet = getFirstJarWarResourceSetAtJarResources(resources);
    return jarWarResourceSet != null
            && jarWarResourceSet.getBaseUrl().getFile().endsWith(".war");
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private boolean isTesting(WebResourceRoot resources) {
    return !isUberJar(resources) && !isUberWar(resources)
            && getFirstDirResourceSetAtJarResources(resources) == null;
}
项目:joinfaces    文件:JsfTomcatApplicationListener.java   
private boolean isUnpackagedJar(WebResourceRoot resources) {
    return !isUberJar(resources)
            && getFirstDirResourceSetAtJarResources(resources) != null;
}
项目:RAFTools    文件:NIOResource.java   
public NIOResource(WebResourceRoot root, Path path) {
    super(root, getWebappRoot(path));
    this.path = path;
}
项目:tomee    文件:TomEEWebappClassLoader.java   
public PremptiveDirResourceSet(final WebResourceRoot resources, final String s, final String absolutePath, final String s1) {
    super(resources, s, absolutePath, s1);
}
项目:tomee    文件:LazyStopStandardRoot.java   
public LazyStopStandardRoot(final WebResourceRoot delegate) {
    this.delegate = delegate;
    this.isJmxEnabled = JmxEnabled.class.isInstance(delegate);
    this.isLifecycleMBeanBase = LifecycleMBeanBase.class.isInstance(delegate);
}
项目:tomee    文件:LazyStopStandardRoot.java   
public WebResourceRoot getDelegate() {
    return delegate;
}
项目:tomee    文件:TomcatWebAppBuilder.java   
private static DeploymentLoader.ExternalConfiguration configuredClasspath(final StandardContext standardContext) {
    Loader loader = standardContext.getLoader();
    if (loader != null && LazyStopLoader.class.isInstance(loader)) {
        loader = LazyStopLoader.class.cast(loader).getDelegateLoader();
    }
    if (loader != null) {
        final ClassLoader cl = standardContext.getLoader().getClassLoader();
        if (cl == null) {
            return null;
        }

        final Collection<String> cp = new LinkedList<>();

        final WebResourceRoot webResources = standardContext.getResources();
        if (webResources != null) { // to enhance
            for (final WebResourceSet[] sets : asList(webResources.getPreResources(), webResources.getPostResources(), webResources.getJarResources())) {
                for (final WebResourceSet wr : sets) {
                    final URL base = wr.getBaseUrl();
                    if (base != null) {
                        final File baseFile = URLs.toFile(base);
                        if (baseFile.isDirectory()) {
                            final String[] libs = wr.list("/WEB-INF/lib/");
                            if (libs != null) {
                                for (final String resource : libs) {
                                    cp.add(new File(baseFile, resource).getAbsolutePath());
                                }
                            }

                            final WebResource classes = wr.getResource("/WEB-INF/classes/");
                            if (classes != null) {
                                final String path = classes.getCanonicalPath();
                                if (path != null) {
                                    cp.add(path);
                                }
                            }
                        } else if (baseFile.exists() && baseFile.getName().endsWith(".jar") && wr.getResource("/WEB-INF/classes/").exists()) {
                            try {
                                cp.add(baseFile.getCanonicalPath());
                            } catch (final IOException e) {
                                throw new IllegalStateException(e);
                            }
                        }
                    }
                }
            }
        }

        if (!cp.isEmpty()) {
            return new DeploymentLoader.ExternalConfiguration(cp.toArray(new String[cp.size()]), null /*for now doesnt make sense, todo: configure*/);
        }
    }
    return null;
}
项目:embed-apache-tomcat    文件:TomcatApplicationBuilderImpl.java   
@Override
public TomcatApplicationBuilder setResources(WebResourceRoot resources) {
    context.setResources(resources);
    return this;
}
项目:embed-apache-tomcat    文件:TomcatApplicationBuilder.java   
/**
 * @return this
 */
TomcatApplicationBuilder setResources(WebResourceRoot resources);