本文整理匯總了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);
}