Search in sources :

Example 91 with ContextHandler

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);
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection)

Example 92 with ContextHandler

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;
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Resource(org.eclipse.jetty.util.resource.Resource) ManagedObject(org.eclipse.jetty.util.annotation.ManagedObject) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) File(java.io.File)

Example 93 with ContextHandler

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();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Executor(java.util.concurrent.Executor) DecoratedObjectFactory(org.eclipse.jetty.util.DecoratedObjectFactory)

Example 94 with ContextHandler

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);
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ResourceHandler(org.eclipse.jetty.server.handler.ResourceHandler)

Example 95 with ContextHandler

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();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Server(org.eclipse.jetty.server.Server) InetSocketAddress(java.net.InetSocketAddress) SessionReflectionHandler(org.apache.camel.component.http4.handler.SessionReflectionHandler) BeforeClass(org.junit.BeforeClass)

Aggregations

ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)127 Server (org.eclipse.jetty.server.Server)47 ServerConnector (org.eclipse.jetty.server.ServerConnector)27 URI (java.net.URI)21 ResourceHandler (org.eclipse.jetty.server.handler.ResourceHandler)20 Test (org.junit.Test)20 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)19 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)19 IOException (java.io.IOException)18 Handler (org.eclipse.jetty.server.Handler)14 HandlerCollection (org.eclipse.jetty.server.handler.HandlerCollection)14 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)14 File (java.io.File)13 ServletException (javax.servlet.ServletException)13 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)13 BeforeClass (org.junit.BeforeClass)11 BaseIntegrationTest (com.ctrip.framework.apollo.BaseIntegrationTest)10 Config (com.ctrip.framework.apollo.Config)10 ApolloConfig (com.ctrip.framework.apollo.core.dto.ApolloConfig)10 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)10