本文整理汇总了Java中org.eclipse.jetty.util.resource.PathResource类的典型用法代码示例。如果您正苦于以下问题:Java PathResource类的具体用法?Java PathResource怎么用?Java PathResource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PathResource类属于org.eclipse.jetty.util.resource包,在下文中一共展示了PathResource类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResource
import org.eclipse.jetty.util.resource.PathResource; //导入依赖的package包/类
@Override
public Resource getResource(String path) {
try {
Resource resource = super.getResource(path);
if (resource == null) return null;
if (!(resource instanceof PathResource) || !resource.exists()) return resource;
File f = resource.getFile();
if (f.isDirectory() && !path.equals("/")) return resource;
CacheResource cache = resourceCache.get(f);
if (cache != null) return cache;
if (f.length() < CACHE_LIMIT || f.getName().endsWith(".html") || path.equals("/")) {
cache = new CacheResource((PathResource) resource);
resourceCache.put(f, cache);
return cache;
}
return resource;
} catch (IOException e) {
Data.logger.warn("", e);
}
return null;
}
示例2: CacheResource
import org.eclipse.jetty.util.resource.PathResource; //导入依赖的package包/类
public CacheResource(PathResource pathResource) throws IOException {
this.file = pathResource.getFile();
if (this.file.isDirectory()) this.file = new File(this.file, "index.html");
this.includes = new ArrayList<>(8);
initCache(System.currentTimeMillis());
pathResource.close();
}
示例3: createdWebAppContext
import org.eclipse.jetty.util.resource.PathResource; //导入依赖的package包/类
/**
* Build web app context used to launch server.
* May be override by subclasses.
*
* @throws Exception May be thrown by web app context initialization (will be wrapped later).
*/
private WebAppContext createdWebAppContext() throws Exception {
final String path = configuration.getPath();
final String webapp = configuration.getWebapp();
final String classpath = configuration.getClasspath();
final Collection<URL> parentClasspath = configuration.getParentClasspath();
final String overrideDescriptor = configuration.getOverrideDescriptor ();
final Resource baseResource = configuration.getBaseResource();
final ClassLoader threadCl = Thread.currentThread().getContextClassLoader();
final ClassLoader classLoader;
if (!parentClasspath.isEmpty()) {
int nbUrls = parentClasspath.size();
URL[] urls = parentClasspath.toArray(new URL[nbUrls]);
classLoader = new URLClassLoader(urls, threadCl);
} else {
classLoader = threadCl;
}
WebAppContext ctx = new WebAppContext();
ctx.setClassLoader(classLoader);
ctx.setContextPath(path);
if (baseResource == null) {
// use default base resource
ctx.setBaseResource(newResource(webapp));
} else {
ctx.setBaseResource(baseResource);
}
if (overrideDescriptor != null) {
ctx.setOverrideDescriptor(overrideDescriptor);
}
ctx.setConfigurations(new Configuration[]{
new WebInfConfiguration(),
new WebXmlConfiguration(),
new AnnotationConfiguration(),
new JettyWebXmlConfiguration(),
new MetaInfConfiguration(),
new FragmentConfiguration()
});
if (isNotBlank(classpath)) {
// Fix to scan Spring WebApplicationInitializer
// This will add compiled classes to jetty classpath
// See: http://stackoverflow.com/questions/13222071/spring-3-1-webapplicationinitializer-embedded-jetty-8-annotationconfiguration
// And more precisely: http://stackoverflow.com/a/18449506/1215828
File classes = new File(classpath);
PathResource containerResources = new PathResource(classes.toURI());
ctx.getMetaData().addContainerResource(containerResources);
}
ctx.setParentLoaderPriority(true);
ctx.setWar(webapp);
ctx.setServer(server);
// Add server context
server.setHandler(ctx);
return ctx;
}
示例4: __invoke
import org.eclipse.jetty.util.resource.PathResource; //导入依赖的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()
);
}