当前位置: 首页>>代码示例>>Java>>正文


Java ResourceHandler.setCacheControl方法代码示例

本文整理汇总了Java中org.eclipse.jetty.server.handler.ResourceHandler.setCacheControl方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceHandler.setCacheControl方法的具体用法?Java ResourceHandler.setCacheControl怎么用?Java ResourceHandler.setCacheControl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.server.handler.ResourceHandler的用法示例。


在下文中一共展示了ResourceHandler.setCacheControl方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: attachHandlers

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
private ContextHandlerCollection attachHandlers(final File staticsFolder, final Module... overrides) {
    final MoodcatHandler moodcatHandler = new MoodcatHandler(this, staticsFolder, overrides);

    final ResourceHandler resources = new ResourceHandler();
    resources.setBaseResource(Resource.newResource(staticsFolder));
    resources.setDirectoriesListed(false);
    resources.setCacheControl("max-age=3600");

    final HashSessionManager hashSessionManager = new HashSessionManager();
    hashSessionManager.setMaxInactiveInterval(SESSION_KEEP_ALIVE);

    final ContextHandlerCollection handlers = new ContextHandlerCollection();
    // CHECKSTYLE:OFF
    handlers.addContext("/", "/").setHandler(resources);
    handlers.addContext("/", "/").setHandler(moodcatHandler);
    // CHECKSTYLE:ON

    return handlers;
}
 
开发者ID:MoodCat,项目名称:MoodCat.me-Core,代码行数:20,代码来源:App.java

示例2: initWebApp

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
private void initWebApp() {
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setResourceBase(config.getString("web.path"));
    if (config.getBoolean("web.debug")) {
        resourceHandler.setWelcomeFiles(new String[] {"debug.html", "index.html"});
        resourceHandler.setMinMemoryMappedContentLength(-1); // avoid locking files on Windows
    } else {
        String cache = config.getString("web.cacheControl");
        if (cache != null && !cache.isEmpty()) {
            resourceHandler.setCacheControl(cache);
        }
        resourceHandler.setWelcomeFiles(new String[] {"release.html", "index.html"});
    }
    handlers.addHandler(resourceHandler);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:16,代码来源:WebServer.java

示例3: newResourcesHandler

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
private ResourceHandler newResourcesHandler() throws MalformedURLException {
    final ResourceHandler resources = new ResourceHandler();
    final Resource location =
            config.getBoolean("web.static.resources.embedded") ?
                      Resource.newClassPathResource("web", false, false)
                    : Resource.newResource("src/main/resources/web", false);
    resources.setBaseResource(location);
    resources.setCacheControl("no-store");
    return resources;
}
 
开发者ID:alpian,项目名称:tired,代码行数:11,代码来源:WebServer.java

示例4: addStaticResources

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
public void addStaticResources(String basePath, String resourcePath) {
    ContextHandler capHandler = new ContextHandler();
    capHandler.setContextPath(basePath);
    ResourceHandler resHandler = new ResourceHandler();
    resHandler.setBaseResource(Resource.newClassPathResource(resourcePath));
    resHandler.setEtags(true);
    resHandler.setCacheControl(WebService.HANDLER_CACHE_CONTROL);
    capHandler.setHandler(resHandler);
    handlers.add(capHandler);
}
 
开发者ID:apache,项目名称:incubator-pulsar,代码行数:11,代码来源:WebService.java

示例5: addResourcesDir

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
private void addResourcesDir(String path, String dir) throws IOException, URISyntaxException {
    Resource newResource = Resource.newResource(this.getClass().getResource(path + "/" + dir).toURI());
    ResourceHandler resourceHandler = new ResourceHandler();
    resourceHandler.setBaseResource(newResource);
    resourceHandler.setCacheControl("public, max-age=31536000");
    ContextHandler ctx = new ContextHandler("/" + dir);
    ctx.setHandler(resourceHandler);
    handlers.addHandler(ctx);
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:10,代码来源:RestfulServer.java

示例6: enableWebServer

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
private void enableWebServer() {
	if (server.isRunning())
		throw new IllegalStateException("Webserver can not be enabled while running");
	ResourceHandler resourceHandler = new ResourceHandler();
	resourceHandler.setDirectoriesListed(true);
	resourceHandler.setWelcomeFiles(new String[] { "index.html" });
	resourceHandler.setResourceBase(webPath);
	resourceHandler.setCacheControl("max-age=600,public"); //cache 10 minutes
	ContextHandler contentHandler = new ContextHandler();
	contentHandler.setContextPath("/");
	contentHandler.setResourceBase(".");
	contentHandler.setClassLoader(Thread.currentThread().getContextClassLoader());
	contentHandler.setHandler(resourceHandler);
	handlers.add(contentHandler);
}
 
开发者ID:Xenoage,项目名称:Zong,代码行数:16,代码来源:Webserver.java

示例7: getResourceHandler

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
public ResourceHandler getResourceHandler() {
    ResourceHandler handler = new ResourceHandler();

    String resourceBase = null;
    org.eclipse.jetty.util.resource.Resource baseResource = null;

    for (String path : resourcePaths) {
        File dir = new File(rootDir, path);
        // seriously?
        if (dir.isDirectory() && dir.list().length > 0) {
            resourceBase = dir.getAbsolutePath();
            break;
        }
    }

    if (resourceBase == null) {
        for (String classpathResource : classpathResources) {
            baseResource = org.eclipse.jetty.util.resource.Resource.newClassPathResource(classpathResource);
            // this sucks
            if (baseResource != null && baseResource.exists()) {
                break;
            }
        }
    }

    if (resourceBase == null && baseResource == null) {
        throw new IllegalStateException("Could not find resourceBase or baseResource for context " + this.context);
    }

    // the things I do for backwards compatibility
    if (resourceBase != null) {
        log.info("Assigning " + resourceBase + " to context " + this.context);
        handler.setResourceBase(resourceBase);
    } else { // baseResource != null
        log.info("Assigning " + baseResource.getName() + " to context " + this.context);
        handler.setBaseResource(baseResource);
    }
    handler.setWelcomeFiles(welcomeFiles.toArray(new String[welcomeFiles.size()]));
    handler.setDirectoriesListed(allowDirectoryListing);
    handler.setCacheControl("max-age=21600"); //6hrs
    handler.setEtags(true);

    return handler;
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:45,代码来源:Resource.java

示例8: __invoke

import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
@Signature
public void __invoke(PHttpServerRequest request, PHttpServerResponse response) throws Exception {
    final boolean[] once = {false};

    ResourceHandler resourceHandler = new ResourceHandler() {
        @Override
        public Resource getResource(String path) {
            if (!once[0]) {
                once[0] = true;
                Object attr = request.getRequest().getAttribute("**");
                File file;

                if (attr != null) {
                    file = new File(PHttpResourceHandler.this.file, "/" + attr);
                } else {
                    file = new File(PHttpResourceHandler.this.file);
                }

                if (file.exists()) {
                    return new PathResource(file.getAbsoluteFile());
                } else {
                    return null;
                }
            } else {
                return null;
            }
        }
    };

    resourceHandler.doStart();

    resourceHandler.setResourceBase(file());

    if (cacheControl() != null) {
        resourceHandler.setCacheControl(cacheControl());
    }

    resourceHandler.setRedirectWelcome(redirectWelcome());
    resourceHandler.setPathInfoOnly(pathInfoOnly());
    resourceHandler.setDirectoriesListed(directoriesListed());
    resourceHandler.setDirAllowed(dirAllowed());
    resourceHandler.setAcceptRanges(acceptRanges());
    resourceHandler.setEtags(etags());

    Request baseRequest = Request.getBaseRequest(request.getRequest());

    resourceHandler.handle(
            request.getRequest().getRequestURI(), baseRequest, request.getRequest(), response.getResponse()
    );
}
 
开发者ID:jphp-compiler,项目名称:jphp,代码行数:51,代码来源:PHttpResourceHandler.java


注:本文中的org.eclipse.jetty.server.handler.ResourceHandler.setCacheControl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。