use of org.eclipse.jetty.server.handler.ResourceHandler in project incubator-pulsar by apache.
the class WebService method addStaticResources.
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);
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project nifi-registry by apache.
the class JettyServer method createDocsWebApp.
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;
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project Manga by herrlock.
the class JettyServer method createResourceHandler.
private Handler createResourceHandler() {
ResourceHandler resourceHandler = new ResourceHandler();
// load from the jetty-folder
resourceHandler.setResourceBase("jetty");
// enable caching via etags
resourceHandler.setEtags(true);
// prevent locked files
resourceHandler.setMinMemoryMappedContentLength(-1);
return resourceHandler;
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project structr by structr.
the class HttpService method collectResourceHandlers.
// ----- private methods -----
private List<ContextHandler> collectResourceHandlers() throws ClassNotFoundException, InstantiationException, IllegalAccessException {
final List<ContextHandler> resourceHandlers = new LinkedList<>();
final String resourceHandlerList = Settings.ResourceHandlers.getValue();
if (resourceHandlerList != null) {
for (String resourceHandlerName : resourceHandlerList.split("[ \\t]+")) {
if (StringUtils.isNotBlank(resourceHandlerName)) {
final String contextPath = Settings.getOrCreateStringSetting(resourceHandlerName, "contextPath").getValue();
if (contextPath != null) {
final String resourceBase = Settings.getOrCreateStringSetting(resourceHandlerName, "resourceBase").getValue();
if (resourceBase != null) {
final ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setDirectoriesListed(Settings.getBooleanSetting(resourceHandlerName, "directoriesListed").getValue());
final String welcomeFiles = Settings.getOrCreateStringSetting(resourceHandlerName, "welcomeFiles").getValue();
if (welcomeFiles != null) {
resourceHandler.setWelcomeFiles(StringUtils.split(welcomeFiles));
}
resourceHandler.setResourceBase(resourceBase);
resourceHandler.setCacheControl("max-age=0");
// resourceHandler.setEtags(true);
final ContextHandler staticResourceHandler = new ContextHandler();
staticResourceHandler.setContextPath(contextPath);
staticResourceHandler.setHandler(resourceHandler);
resourceHandlers.add(staticResourceHandler);
} else {
logger.warn("Unable to register resource handler {}, missing {}.resourceBase", resourceHandlerName, resourceHandlerName);
}
} else {
logger.warn("Unable to register resource handler {}, missing {}.contextPath", resourceHandlerName, resourceHandlerName);
}
}
}
} else {
logger.warn("No resource handlers configured for HttpService.");
}
return resourceHandlers;
}
use of org.eclipse.jetty.server.handler.ResourceHandler in project calcite by apache.
the class HttpServer method start.
void start() {
if (server != null) {
throw new RuntimeException("Server is already started");
} else {
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setDaemon(true);
server = new Server(threadPool);
server.manage(threadPool);
final ServerConnector connector = new ServerConnector(server);
connector.setIdleTimeout(60 * 1000);
connector.setSoLingerTime(-1);
connector.setPort(0);
server.setConnectors(new Connector[] { connector });
final ResourceHandler resHandler = new ResourceHandler();
resHandler.setResourceBase(resourceBase.getAbsolutePath());
final HandlerList handlerList = new HandlerList();
handlerList.setHandlers(new Handler[] { resHandler, new DefaultHandler() });
server.setHandler(handlerList);
try {
server.start();
} catch (Exception e) {
throw new RuntimeException(e);
}
port = connector.getLocalPort();
}
}
Aggregations