本文整理汇总了Java中org.eclipse.jetty.server.handler.ResourceHandler.setBaseResource方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceHandler.setBaseResource方法的具体用法?Java ResourceHandler.setBaseResource怎么用?Java ResourceHandler.setBaseResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.server.handler.ResourceHandler
的用法示例。
在下文中一共展示了ResourceHandler.setBaseResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的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();
}
示例2: run
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
public int run() throws Exception {
org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(port);
HandlerList handlerList = new HandlerList();
ServletContextHandler servletContextHandler = new ServletContextHandler();
FilterHolder cof = new FilterHolder(new CrossOriginFilter());
cof.setInitParameter(
CrossOriginFilter.EXPOSED_HEADERS_PARAM,
"Date");
servletContextHandler.addFilter(cof, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
servletContextHandler.addServlet(new ServletHolder(new SmoothStreamingServlet(dataDir)), "/*");
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("supportfiles"));
handlerList.addHandler(resourceHandler);
handlerList.addHandler(servletContextHandler);
server.setHandler(handlerList);
server.start();
server.dumpStdErr();
server.join();
return 0;
}
示例3: startServer
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
public void startServer() throws Exception {
int serverPort = propertiesConfiguration.getInt("server.port.http");
Server server = new Server(serverPort);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("/web"));
ServletContextHandler servletContextHandler = new ServletContextHandler(server, "/api");
servletContextHandler.addFilter(GuiceFilter.class, "/*", EnumSet.allOf(DispatcherType.class));
initGuiceInjector();
HandlerList handlerList = new HandlerList();
handlerList.addHandler(resourceHandler);
handlerList.addHandler(servletContextHandler);
server.setHandler(handlerList);
server.start();
server.join();
}
示例4: setup
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
private void setup(int port) {
if (server == null) {
server = new Server(port);
ServletHandler servletHandler = new ServletHandler();
webSocketServlet = new WebsocketOutboundServlet();
ServletHolder holder = new ServletHolder(webSocketServlet);
servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/"));
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()});
server.setHandler(handlers);
try {
server.start();
String url = "ws://localhost:" + port + uri;
System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url));
// add the shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown()));
} catch (Exception error) {
System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()));
error.printStackTrace();
}
}
}
开发者ID:Esri,项目名称:performance-test-harness-for-geoevent,代码行数:27,代码来源:WebsocketServerEventProducer.java
示例5: setup
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
private void setup(int port) {
if (server == null) {
server = new Server(port);
ServletHandler servletHandler = new ServletHandler();
webSocketServlet = new WebsocketOutboundServlet(message -> receive(message));
ServletHolder holder = new ServletHolder(webSocketServlet);
servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/"));
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()});
server.setHandler(handlers);
try {
server.start();
String url = "ws://localhost:" + port + uri;
System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url));
// add the shutdown hook
Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown()));
} catch (Exception error) {
System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage()));
error.printStackTrace();
}
}
}
开发者ID:Esri,项目名称:performance-test-harness-for-geoevent,代码行数:27,代码来源:WebsocketServerEventConsumer.java
示例6: main
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Server server = new Server(15000);
HandlerCollection hc = new HandlerCollection();
ResourceHandler rh = new ResourceHandler();
rh.setBaseResource(Resource.newClassPathResource("/com/frinika/web/content/"));
rh.setDirectoriesListed(true);
hc.addHandler(rh);
server.setHandler(hc);
server.start();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initAndShowGUI();
}
});
}
示例7: setUpGuiHandler
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
/**
* do setup for the static resource handler
* @return ContextHandler for the static resource handler
*/
private static ContextHandler setUpGuiHandler() throws MalformedURLException
{
ContextHandler context1 = new ContextHandler();
context1.setContextPath("/");
ResourceHandler res = new ResourceHandler();
res.setWelcomeFiles(new String[]{"index.html"});
res.setBaseResource(Resource.newResource("./resources/"));
context1.setHandler(res);
logger.info("<---gui handler initialised--->");
// WebAppContext webApp = new WebAppContext();
// webApp.setContextPath("/");
// webApp.setResourceBase("/home/orpheus/projects/BeSeen/BeSeenium/resources/");
// webApp.setWar("/home/orpheus/projects/BeSeen/BeSeenium/resources/quercus-4.0.18.war");
// webApp.setServer(server);
// context1.setHandler(webApp);
return context1;
}
示例8: 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;
}
示例9: setupFilesHandler
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的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.");
}
}
示例10: JettyCrosServer
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
public JettyCrosServer() throws Exception {
server = new Server(80);
HandlerList handlers = new HandlerList();
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setWelcomeFiles(new String[] { "index.html" });
resource_handler.setBaseResource(Resource.newClassPathResource("web"));
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.setInitParameter("maxInterval", "1000");
context.setInitParameter("logLevel", "2");
handlers.setHandlers(new Handler[] { resource_handler, context});
server.setHandler(handlers);
FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter());
filterHolder.getInitParameters().put(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,Authorization");
context.addFilter(filterHolder, "/*", EnumSet.allOf(DispatcherType.class));
context.addServlet(new ServletHolder(new JsonServlet()), "/t.json");
context.addServlet(new ServletHolder(new DefaultServlet()), "/*");
}
示例11: createDocsWebApp
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的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;
}
示例12: 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;
}
示例13: 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);
}
示例14: createContextHandler
import org.eclipse.jetty.server.handler.ResourceHandler; //导入方法依赖的package包/类
/** Creates a context handler for the directory. */
private ContextHandler createContextHandler(String directory,
boolean isInJar, File installRootDirectory, int expiresInSeconds) {
final ContextHandler contextHandler = new ContextHandler();
final ResourceHandler resourceHandler = new ExpiresResourceHandler(expiresInSeconds);
final String directoryWithSlash = "/" + directory;
contextHandler.setContextPath(directoryWithSlash);
Resource directoryResource = getDirectoryResource(directory, isInJar,
installRootDirectory);
directoryResource = new JsMinifyingResource(directoryResource);
if (isInJar) {
directoryResource = new CachingResource(directoryResource,
directoryWithSlash);
}
resourceHandler.setBaseResource(directoryResource);
if (!isInJar) {
// This makes development easier because Eclipse can copy files
// to the target directory on each save on Windows.
resourceHandler.setMinMemoryMappedContentLength(0);
}
contextHandler.setHandler(resourceHandler);
return contextHandler;
}
示例15: 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);
}