use of org.eclipse.jetty.server.handler.ContextHandler in project i2p.i2p by i2p.
the class WebAppStarter method stopWebApp.
/**
* Stop it and remove the context.
* Throws just about anything, caller would be wise to catch Throwable
* @since public since 0.9.33, was package private
*/
public static void stopWebApp(RouterContext ctx, String appName) {
ContextHandler wac = getWebApp(appName);
if (wac == null)
return;
ctx.portMapper().unregister(appName);
try {
// not graceful is default in Jetty 6?
wac.stop();
} catch (Exception ie) {
}
ContextHandlerCollection server = getConsoleServer();
if (server == null)
return;
try {
server.removeHandler(wac);
server.mapContexts();
} catch (IllegalStateException ise) {
}
}
use of org.eclipse.jetty.server.handler.ContextHandler 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.ContextHandler in project Manga by herrlock.
the class JettyServer method createMangaBaseHandler.
private Handler createMangaBaseHandler() {
ContextHandler contextHandler = new ContextHandler("j");
contextHandler.setHandler(new MangaBaseHandler());
return contextHandler;
}
use of org.eclipse.jetty.server.handler.ContextHandler 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.ContextHandler in project activemq-artemis by apache.
the class WebServerComponent method configure.
@Override
public void configure(ComponentDTO config, String artemisInstance, String artemisHome) throws Exception {
webServerConfig = (WebServerDTO) config;
uri = new URI(webServerConfig.bind);
server = new Server();
String scheme = uri.getScheme();
if ("https".equals(scheme)) {
SslContextFactory sslFactory = new SslContextFactory();
sslFactory.setKeyStorePath(webServerConfig.keyStorePath == null ? artemisInstance + "/etc/keystore.jks" : webServerConfig.keyStorePath);
sslFactory.setKeyStorePassword(webServerConfig.getKeyStorePassword() == null ? "password" : webServerConfig.getKeyStorePassword());
if (webServerConfig.clientAuth != null) {
sslFactory.setNeedClientAuth(webServerConfig.clientAuth);
if (webServerConfig.clientAuth) {
sslFactory.setTrustStorePath(webServerConfig.trustStorePath);
sslFactory.setTrustStorePassword(webServerConfig.getTrustStorePassword());
}
}
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslFactory, "HTTP/1.1");
HttpConfiguration https = new HttpConfiguration();
https.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory httpFactory = new HttpConnectionFactory(https);
connector = new ServerConnector(server, sslConnectionFactory, httpFactory);
} else {
connector = new ServerConnector(server);
}
connector.setPort(uri.getPort());
connector.setHost(uri.getHost());
server.setConnectors(new Connector[] { connector });
handlers = new HandlerList();
Path homeWarDir = Paths.get(artemisHome != null ? artemisHome : ".").resolve(webServerConfig.path).toAbsolutePath();
Path instanceWarDir = Paths.get(artemisInstance != null ? artemisInstance : ".").resolve(webServerConfig.path).toAbsolutePath();
if (webServerConfig.apps != null && webServerConfig.apps.size() > 0) {
webContexts = new ArrayList<>();
for (AppDTO app : webServerConfig.apps) {
Path dirToUse = homeWarDir;
if (new File(instanceWarDir.toFile().toString() + File.separator + app.war).exists()) {
dirToUse = instanceWarDir;
}
WebAppContext webContext = deployWar(app.url, app.war, dirToUse);
webContexts.add(webContext);
if (app.war.startsWith("console")) {
consoleUrl = webServerConfig.bind + "/" + app.url;
}
}
}
ResourceHandler homeResourceHandler = new ResourceHandler();
homeResourceHandler.setResourceBase(homeWarDir.toString());
homeResourceHandler.setDirectoriesListed(false);
homeResourceHandler.setWelcomeFiles(new String[] { "index.html" });
ContextHandler homeContext = new ContextHandler();
homeContext.setContextPath("/");
homeContext.setResourceBase(homeWarDir.toString());
homeContext.setHandler(homeResourceHandler);
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
ResourceHandler instanceResourceHandler = new ResourceHandler();
instanceResourceHandler.setResourceBase(instanceWarDir.toString());
instanceResourceHandler.setDirectoriesListed(false);
instanceResourceHandler.setWelcomeFiles(new String[] { "index.html" });
ContextHandler instanceContext = new ContextHandler();
instanceContext.setContextPath("/");
instanceContext.setResourceBase(instanceWarDir.toString());
instanceContext.setHandler(instanceResourceHandler);
homeContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
DefaultHandler defaultHandler = new DefaultHandler();
defaultHandler.setServeIcon(false);
handlers.addHandler(homeContext);
handlers.addHandler(instanceContext);
handlers.addHandler(defaultHandler);
server.setHandler(handlers);
}
Aggregations