use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class StandardUndeployer method processBinding.
@Override
public void processBinding(Node node, App app) throws Exception {
ContextHandler handler = app.getContextHandler();
ContextHandlerCollection chcoll = app.getDeploymentManager().getContexts();
recursiveRemoveContext(chcoll, handler);
}
use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class WebAppProvider method createContextHandler.
/* ------------------------------------------------------------ */
@Override
public ContextHandler createContextHandler(final App app) throws Exception {
Resource resource = Resource.newResource(app.getOriginId());
File file = resource.getFile();
if (!resource.exists())
throw new IllegalStateException("App resource does not exist " + resource);
String context = file.getName();
if (resource.exists() && FileID.isXmlFile(file)) {
XmlConfiguration xmlc = new XmlConfiguration(resource.getURI().toURL()) {
@Override
public void initializeDefaults(Object context) {
super.initializeDefaults(context);
if (context instanceof WebAppContext) {
WebAppContext webapp = (WebAppContext) context;
initializeWebAppContextDefaults(webapp);
}
}
};
xmlc.getIdMap().put("Server", getDeploymentManager().getServer());
xmlc.getProperties().put("jetty.home", System.getProperty("jetty.home", "."));
xmlc.getProperties().put("jetty.base", System.getProperty("jetty.base", "."));
xmlc.getProperties().put("jetty.webapp", file.getCanonicalPath());
xmlc.getProperties().put("jetty.webapps", file.getParentFile().getCanonicalPath());
if (getConfigurationManager() != null)
xmlc.getProperties().putAll(getConfigurationManager().getProperties());
return (ContextHandler) xmlc.configure();
} else if (file.isDirectory()) {
// must be a directory
} else if (FileID.isWebArchiveFile(file)) {
// Context Path is the same as the archive.
context = context.substring(0, context.length() - 4);
} else {
throw new IllegalStateException("unable to create ContextHandler for " + app);
}
// Ensure "/" is Not Trailing in context paths.
if (context.endsWith("/") && context.length() > 0) {
context = context.substring(0, context.length() - 1);
}
// Start building the webapplication
WebAppContext webAppContext = new WebAppContext();
webAppContext.setDisplayName(context);
// special case of archive (or dir) named "root" is / context
if (context.equalsIgnoreCase("root")) {
context = URIUtil.SLASH;
} else if (context.toLowerCase(Locale.ENGLISH).startsWith("root-")) {
int dash = context.toLowerCase(Locale.ENGLISH).indexOf('-');
String virtual = context.substring(dash + 1);
webAppContext.setVirtualHosts(new String[] { virtual });
context = URIUtil.SLASH;
}
// Ensure "/" is Prepended to all context paths.
if (context.charAt(0) != '/') {
context = "/" + context;
}
webAppContext.setContextPath(context);
webAppContext.setWar(file.getAbsolutePath());
initializeWebAppContextDefaults(webAppContext);
return webAppContext;
}
use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.
the class WebSocketServerFactory method doStart.
@Override
protected void doStart() throws Exception {
if (this.objectFactory == null && context != null) {
this.objectFactory = (DecoratedObjectFactory) context.getAttribute(DecoratedObjectFactory.ATTR);
if (this.objectFactory == null) {
throw new IllegalStateException("Unable to find required ServletContext attribute: " + DecoratedObjectFactory.ATTR);
}
}
if (this.executor == null && context != null) {
ContextHandler contextHandler = ContextHandler.getContextHandler(context);
this.executor = contextHandler.getServer().getThreadPool();
}
Objects.requireNonNull(this.objectFactory, DecoratedObjectFactory.class.getName());
Objects.requireNonNull(this.executor, Executor.class.getName());
super.doStart();
}
use of org.eclipse.jetty.server.handler.ContextHandler in project pulsar by yahoo.
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.ContextHandler in project camel by apache.
the class HttpProducerSessionTest method initServer.
@BeforeClass
public static void initServer() throws Exception {
port = AvailablePortFinder.getNextAvailable(24000);
localServer = new Server(new InetSocketAddress("127.0.0.1", port));
ContextHandler contextHandler = new ContextHandler();
contextHandler.setContextPath("/session");
SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setHandler(new SessionReflectionHandler());
contextHandler.setHandler(sessionHandler);
localServer.setHandler(contextHandler);
localServer.start();
}
Aggregations