當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。