本文整理汇总了Java中org.eclipse.jetty.util.resource.Resource.newResource方法的典型用法代码示例。如果您正苦于以下问题:Java Resource.newResource方法的具体用法?Java Resource.newResource怎么用?Java Resource.newResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.util.resource.Resource
的用法示例。
在下文中一共展示了Resource.newResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
public void init(ServletConfig servletConfig) throws ServletException {
this.servletConfig = servletConfig;
//templateCfg.setClassForTemplateLoading(getClass(), "/");
Resource baseResource;
try {
baseResource = Resource.newResource(servletConfig.getInitParameter("resourceBase"));
} catch (MalformedURLException e) {
throw new ServletException(e);
}
templateCfg.setTemplateLoader(new ResourceTemplateLoader(baseResource));
templateCfg.setDefaultEncoding("UTF-8");
// Sets how errors will appear.
// During web page *development* TemplateExceptionHandler.HTML_DEBUG_HANDLER
// is better.
// cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
templateCfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
}
示例2: getDirectoryResource
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/** Returns a resource for the directory. */
Resource getDirectoryResource(String directory, boolean isInJar,
File installRootDirectory) {
if (isInJar) {
try {
return JarResource.newJarResource(Resource
.newResource(Servlet.class.getClassLoader()
.getResource(directory)));
} catch (final IOException e) {
}
return null;
} else {
return Resource.newResource(new File(installRootDirectory,
directory));
}
}
示例3: getClassPath
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
* Generate the classpath (as a string) of all classloaders
* above the given classloader.
*
* This is primarily used for jasper.
* @return the system class path
*/
public static String getClassPath(ClassLoader loader) throws Exception
{
StringBuilder classpath=new StringBuilder();
while (loader != null && (loader instanceof URLClassLoader))
{
URL[] urls = ((URLClassLoader)loader).getURLs();
if (urls != null)
{
for (int i=0;i<urls.length;i++)
{
Resource resource = Resource.newResource(urls[i]);
File file=resource.getFile();
if (file!=null && file.exists())
{
if (classpath.length()>0)
classpath.append(File.pathSeparatorChar);
classpath.append(file.getAbsolutePath());
}
}
}
loader = loader.getParent();
}
return classpath.toString();
}
示例4: createSSLConnectionFactory
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
private SslConnectionFactory createSSLConnectionFactory(final KeystoreConfig keystore) {
final Resource keystoreResource = Resource.newResource(keystore.getURL());
final SslContextFactory contextFactory = new SslContextFactory();
contextFactory.setEnableCRLDP(false);
contextFactory.setEnableOCSP(false);
contextFactory.setNeedClientAuth(false);
contextFactory.setWantClientAuth(false);
contextFactory.setValidateCerts(false);
contextFactory.setValidatePeerCerts(false);
contextFactory.setRenegotiationAllowed(false); // avoid vulnerability
contextFactory.setSessionCachingEnabled(true); // optimization
contextFactory.setKeyStoreResource(keystoreResource);
contextFactory.setKeyStorePassword(keystore.getPassword());
contextFactory.setCertAlias(keystore.getAlias());
contextFactory.setKeyStoreType(keystore.getType());
contextFactory.setIncludeCipherSuites("TLS_DHE_RSA_WITH_AES_128_CBC_SHA",
"SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_RSA_WITH_AES_128_CBC_SHA",
"SSL_RSA_WITH_3DES_EDE_CBC_SHA", "TLS_DHE_DSS_WITH_AES_128_CBC_SHA",
"SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA"); // check RFC 5430
final SslConnectionFactory factory = new SslConnectionFactory(contextFactory, "http/1.1");
return factory;
}
示例5: chop
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
public static Resource chop(final URL baseURL, final String toChop)
throws MalformedURLException, IOException {
String base = baseURL.toExternalForm();
if (!base.endsWith(toChop)) {
throw new IllegalArgumentException(base + " does not endWith "
+ toChop);
}
base = base.substring(0, base.length() - toChop.length());
if (base.startsWith("jar:file:") && base.endsWith("!")) {
// If it was a jar:file:/.../.jar!/META-INF/web-fragment.xml, then
// 'jar:' & '!' has to go as well:
base = base.substring(0, base.length() - 1);
base = "file:" + base.substring("jar:file:".length());
}
return Resource.newResource(base);
}
示例6: setupFilesHandler
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
private void setupFilesHandler(Reflections reflections) throws IOException {
// Set up the handler if there's anything to be served:
URL url = getFilesUrl(reflections);
if (url != null) {
// Set up the resource handler:
ResourceHandler filesHandler = new ResourceHandler();
Resource resource = Resource.newResource(url);
filesHandler.setBaseResource(resource);
this.filesHandler = filesHandler;
log.info("Set up static file handler for URL: " + url);
} else {
log.info("No static file handler configured.");
}
}
示例7: doStart
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
// unpack and Adjust paths.
Resource base = getBaseResource();
if (base == null) {
base = Resource.newResource(getWar());
}
Resource dir;
if (base.isDirectory()) {
dir = base;
} else {
throw new IllegalArgumentException();
}
Resource qswebxml = dir.addPath("/WEB-INF/quickstart-web.xml");
if (qswebxml.exists()) {
setConfigurationClasses(quickstartConfigurationClasses);
}
super.doStart();
}
示例8: getResource
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
public Resource getResource(String uriInContext) throws MalformedURLException {
if (publishedClasspathResources.contains(uriInContext) && getClassLoader() != null) {
if (uriInContext.startsWith("/"))
uriInContext = uriInContext.substring(1);
URL resource = getClassLoader().getResource(uriInContext);
if (resource == null) {
throw new RuntimeException("Could not found published resource in classpath");
}
return Resource.newResource(resource);
}
return super.getResource(uriInContext);
}
示例9: getResource
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
@Override
public final Resource getResource(String pathInContext) {
ServletContextHandler.Context context = (ServletContextHandler.Context) getServletContext();
ServletContextHandler contextHandler = (ServletContextHandler) context.getContextHandler();
for (ServletMapping mapping: contextHandler.getServletHandler().getServletMappings()) {
if (mapping.getServletName().equals(getServletName())) {
for (String pathSpec: mapping.getPathSpecs()) {
String relativePath = null;
if (pathSpec.endsWith("/*")) {
pathSpec = StringUtils.substringBeforeLast(pathSpec, "/*");
if (pathInContext.startsWith(pathSpec + "/"))
relativePath = pathInContext.substring(pathSpec.length());
} else if (pathSpec.startsWith("*.")) {
pathSpec = StringUtils.stripStart(pathSpec, "*");
if (pathInContext.endsWith(pathSpec))
relativePath = pathInContext;
} else if (pathSpec.equals(pathInContext)) {
relativePath = pathInContext;
}
if (relativePath != null) {
relativePath = StringUtils.stripStart(relativePath, "/");
Resource resource = Resource.newResource(loadResource(relativePath));
if (resource != null && resource.exists())
return resource;
}
}
}
}
return null;
}
示例10: createDocsWebApp
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
private ContextHandler createDocsWebApp(final String contextPath) throws IOException {
final ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(false);
// load the docs directory
final File docsDir = Paths.get("docs").toRealPath().toFile();
final Resource docsResource = Resource.newResource(docsDir);
// load the rest documentation
final File webApiDocsDir = new File(webApiContext.getTempDirectory(), "webapp/docs");
if (!webApiDocsDir.exists()) {
final boolean made = webApiDocsDir.mkdirs();
if (!made) {
throw new RuntimeException(webApiDocsDir.getAbsolutePath() + " could not be created");
}
}
final Resource webApiDocsResource = Resource.newResource(webApiDocsDir);
// create resources for both docs locations
final ResourceCollection resources = new ResourceCollection(docsResource, webApiDocsResource);
resourceHandler.setBaseResource(resources);
// create the context handler
final ContextHandler handler = new ContextHandler(contextPath);
handler.setHandler(resourceHandler);
logger.info("Loading documents web app with context path set to " + contextPath);
return handler;
}
示例11: newResource
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
protected Resource newResource(String path) {
try {
return Resource.newResource(path);
}
catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例12: addClassPath
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
* @param classPath Comma or semicolon separated path of filenames or URLs
* pointing to directories or jar files. Directories should end
* with '/'.
*/
public void addClassPath(String classPath)
throws IOException {
if (classPath == null) {
return;
}
StringTokenizer tokenizer = new StringTokenizer(classPath, ",;");
while (tokenizer.hasMoreTokens()) {
Resource resource = Resource.newResource(tokenizer.nextToken().trim());
// Add the resource
if (resource.isDirectory() && resource instanceof ResourceCollection) {
addClassPath(resource);
}
else {
// Resolve file path if possible
File file = resource.getFile();
if (file != null) {
URL url = resource.getURL();
addURL(url);
} else if (resource.isDirectory()) {
addURL(resource.getURL());
} else {
LOG.error("Check file exists and is not nested jar: " + resource);
throw new IllegalArgumentException("File not resolvable or incompatible with URLClassloader: " + resource);
}
}
}
}
示例13: addClassPath
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
/**
* @param classPath Comma or semicolon separated path of filenames or URLs
* pointing to directories or jar files. Directories should end
* with '/'.
*/
public void addClassPath(String classPath)
throws IOException {
if (classPath == null) {
return;
}
StringTokenizer tokenizer = new StringTokenizer(classPath, ",;");
while (tokenizer.hasMoreTokens()) {
Resource resource = Resource.newResource(tokenizer.nextToken().trim());
// Add the resource
if (resource.isDirectory() && resource instanceof ResourceCollection)
addClassPath(resource);
else {
// Resolve file path if possible
File file = resource.getFile();
if (file != null) {
URL url = resource.getURL();
addURL(url);
} else if (resource.isDirectory()) {
addURL(resource.getURL());
} else {
LOG.error("Check file exists and is not nested jar: " + resource);
throw new IllegalArgumentException("File not resolvable or incompatible with URLClassloader: " + resource);
}
}
}
}
示例14: newResourcesHandler
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的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;
}
示例15: FavIconHandler
import org.eclipse.jetty.util.resource.Resource; //导入方法依赖的package包/类
public FavIconHandler() {
byte[] bytes;
try {
URL fav = this.getClass().getClassLoader().getResource("favicon.ico");
Resource r = Resource.newResource(fav);
bytes = IO.readBytes(r.getInputStream());
} catch (IOException e) {
log.warn("Could not load favicon", e);
bytes = null;
}
favicon = bytes;
}