本文整理汇总了Java中org.eclipse.jetty.util.resource.Resource类的典型用法代码示例。如果您正苦于以下问题:Java Resource类的具体用法?Java Resource怎么用?Java Resource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Resource类属于org.eclipse.jetty.util.resource包,在下文中一共展示了Resource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
public void start() throws Exception {
server = new Server(port);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS);
context.addFilter(AuthenticationFilter.class, "/*", null);
context.setServer(server);
// Add static files handler
context.setBaseResource(Resource.newResource(JettyServer.class.getResource("/webapp")));
context.addServlet(DefaultServlet.class,"/");
context.setWelcomeFiles(new String[]{"index.html"});
ServerContainer wsContainer = WebSocketServerContainerInitializer.configureContext(context);
wsContainer.addEndpoint(createEndpointConfig(EchoEndpoint.class));
server.setHandler(context);
server.start();
}
示例2: start
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
private void start() throws Exception {
resourcesExample();
ResourceHandler resourceHandler = new ResourceHandler();
Resource resource = Resource.newClassPathResource(PUBLIC_HTML);
resourceHandler.setBaseResource(resource);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(new TimerServlet()), "/timer");
Server server = new Server(PORT);
server.setHandler(new HandlerList(resourceHandler, context));
server.start();
server.join();
}
示例3: configureSslTrustStore
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
private void configureSslTrustStore(SslContextFactory factory, Ssl ssl) {
if (ssl.getTrustStorePassword() != null) {
factory.setTrustStorePassword(ssl.getTrustStorePassword());
}
if (ssl.getTrustStore() != null) {
try {
URL url = ResourceUtils.getURL(ssl.getTrustStore());
factory.setTrustStoreResource(Resource.newResource(url));
}
catch (IOException ex) {
throw new EmbeddedServletContainerException(
"Could not find trust store '" + ssl.getTrustStore() + "'", ex);
}
}
if (ssl.getTrustStoreType() != null) {
factory.setTrustStoreType(ssl.getTrustStoreType());
}
if (ssl.getTrustStoreProvider() != null) {
factory.setTrustStoreProvider(ssl.getTrustStoreProvider());
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:22,代码来源:JettyEmbeddedServletContainerFactory.java
示例4: configureSslKeyStore
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
private void configureSslKeyStore(SslContextFactory factory, Ssl ssl) {
try {
URL url = ResourceUtils.getURL(ssl.getKeyStore());
factory.setKeyStoreResource(Resource.newResource(url));
}
catch (IOException ex) {
throw new EmbeddedServletContainerException(
"Could not find key store '" + ssl.getKeyStore() + "'", ex);
}
if (ssl.getKeyStoreType() != null) {
factory.setKeyStoreType(ssl.getKeyStoreType());
}
if (ssl.getKeyStoreProvider() != null) {
factory.setKeyStoreProvider(ssl.getKeyStoreProvider());
}
}
示例5: getResource
import org.eclipse.jetty.util.resource.Resource; //导入依赖的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;
}
示例6: start
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
public void start() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
// Integer port = getPort();
// if (port != null && port > 0) {
// Connector[] connectors = server.getConnectors();
// for (Connector connector : connectors) {
// connector.setPort(port);
// }
// }
Handler handler = server.getHandler();
if (handler != null && handler instanceof WebAppContext) {
WebAppContext webAppContext = (WebAppContext) handler;
webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例7: afterPropertiesSet
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
public void afterPropertiesSet() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
Integer port = getPort();
if (port != null && port > 0) {
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", htdocsDir);
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例8: main
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
public static void main(String args[]) throws Exception {
Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
Server server = (Server) configuration.configure();
int port = 8081;
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
}
server.start();
server.join();
}
示例9: configureSslKeyStore
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
private void configureSslKeyStore(SslContextFactory factory, Ssl ssl) {
try {
URL url = ResourceUtils.getURL(ssl.getKeyStore());
factory.setKeyStoreResource(Resource.newResource(url));
} catch (IOException ex) {
throw new WebServerException(
"Could not find key store '" + ssl.getKeyStore() + "'", ex);
}
if (ssl.getKeyStoreType() != null) {
factory.setKeyStoreType(ssl.getKeyStoreType());
}
if (ssl.getKeyStoreProvider() != null) {
factory.setKeyStoreProvider(ssl.getKeyStoreProvider());
}
}
示例10: configureSslTrustStore
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
private void configureSslTrustStore(final SslContextFactory factory, final Ssl ssl) {
if (ssl.getTrustStorePassword() != null) {
factory.setTrustStorePassword(ssl.getTrustStorePassword());
}
if (ssl.getTrustStore() != null) {
try {
URL url = ResourceUtils.getURL(ssl.getTrustStore());
factory.setTrustStoreResource(Resource.newResource(url));
} catch (IOException ex) {
throw new WebServerException(
"Could not find trust store '" + ssl.getTrustStore() + "'", ex);
}
}
if (ssl.getTrustStoreType() != null) {
factory.setTrustStoreType(ssl.getTrustStoreType());
}
if (ssl.getTrustStoreProvider() != null) {
factory.setTrustStoreProvider(ssl.getTrustStoreProvider());
}
}
示例11: 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);
}
示例12: addStaticResourceConfig
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
private void addStaticResourceConfig(ServletContextHandler context) {
URL webappLocation = getClass().getResource("/webapp/index.html");
if (webappLocation == null) {
System.err.println("Couldn't get webapp location.");
} else {
try {
URI webRootUri = URI.create(webappLocation.toURI().toASCIIString().replaceFirst("/index.html$", "/"));
context.setBaseResource(Resource.newResource(webRootUri));
context.setWelcomeFiles(new String[]{"index.html"});
GzipHandler gzipHandler = new GzipHandler();
gzipHandler.setIncludedMethods(HttpMethod.GET.name(), HttpMethod.POST.name(), HttpMethod.PUT.name());
context.setGzipHandler(gzipHandler);
context.addFilter(TryFilesFilter.class, "*", EnumSet.of(DispatcherType.REQUEST));
} catch (URISyntaxException | MalformedURLException e) {
e.printStackTrace();
}
}
}
示例13: addFolderResource
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
protected void addFolderResource(final WebAppContext context) throws IOException {
for (Resource resource : context.getMetaData().getWebInfJars()) {
String url = resource.toString();
if (!isClassesDir(url)) {
continue;
}
{
Resource fragmentResource = resource.getResource("META-INF/web-fragment.xml");
if (fragmentResource.exists()) {
// addResource(context, METAINF_FRAGMENTS, resource);
}
}
this.addTldResource(context, resource, "META-INF/fnx.tld");
this.addTldResource(context, resource, "META-INF/dw.tld");
}
}
示例14: findJars
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
@Override
protected List<Resource> findJars(WebAppContext context) throws Exception {
List<Resource> list = super.findJars(context);
if (list == null) {
list = new ArrayList<Resource>();
}
ClassLoader aLoader = getClass().getClassLoader();
if (aLoader instanceof URLClassLoader) {
URL[] _urls = ((URLClassLoader) aLoader).getURLs();
for (URL _url : _urls) {
// System.err.println("EmbedWebInfConfiguration url:" + _url.getPath());
list.add(Resource.newResource(_url));
}
}
if (true) {
List<Resource> extendResourceList = new ResourceLoaderImpl().findJars(context);
// System.err.println("extendResourceList:" + extendResourceList);
if (extendResourceList != null) {
list.addAll(extendResourceList);
}
}
return list;
}
示例15: getResource
import org.eclipse.jetty.util.resource.Resource; //导入依赖的package包/类
protected Resource getResource(HttpServletRequest request) throws MalformedURLException {
System.err.println("getResource uri:" + request.getRequestURI());
// return super.getResource(request);
// }
//
// @Override
// public Resource getResource(String path) {
// System.err.println("getResource path:" + path);
Resource resource = super.getResource(request);
if (resource == null || !resource.exists()) {
return resource;
}
String path = request.getRequestURI();
if ("/js/jquery.min.js".equals(path)) {
try {
resource = this.append(request, resource, path);
}
catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
return resource;
}