本文整理汇总了Java中org.eclipse.jetty.server.handler.ResourceHandler.setEtags方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceHandler.setEtags方法的具体用法?Java ResourceHandler.setEtags怎么用?Java ResourceHandler.setEtags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.handler.ResourceHandler
的用法示例。
在下文中一共展示了ResourceHandler.setEtags方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addResources
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
public void addResources(String contextPath, String resourcePath, String welcomesCsv) {
int opt = ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS;
ServletContextHandler context = new ServletContextHandler(opt);
{
context.setContextPath(contextPath);
context.setCompactPath(true);
context.setAllowNullPathInfo(true);
if (Resources.exists(resourcePath)) {
URL url = Resources.getURL(resourcePath);
context.setResourceBase(url.toExternalForm());
}
ResourceHandler h = new ResourceHandler();
h.setMinMemoryMappedContentLength(-1);
h.setEtags(true);
context.setHandler(h);
context.setWelcomeFiles(Iterables.toArray(Splitters.notEmpties(",").split(welcomesCsv), String.class));
}
this.handlers.addHandler(context);
}
示例2: 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);
}
示例3: 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;
}
示例4: __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()
);
}