Search in sources :

Example 16 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class EndpointEchoTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    server.addConnector(connector);
    handler = new EchoHandler();
    ContextHandler context = new ContextHandler();
    context.setContextPath("/");
    context.setHandler(handler);
    server.setHandler(context);
    // Start Server
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverUri = new URI(String.format("ws://%s:%d/", host, port));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server) URI(java.net.URI) EchoStringEndpoint(org.eclipse.jetty.websocket.jsr356.samples.EchoStringEndpoint) BeforeClass(org.junit.BeforeClass)

Example 17 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class OneContext method main.

public static void main(String[] args) throws Exception {
    Server server = new Server(8080);
    // Add a single handler on context "/hello"
    ContextHandler context = new ContextHandler();
    context.setContextPath("/hello");
    context.setHandler(new HelloHandler());
    // Can be accessed using http://localhost:8080/hello
    server.setHandler(context);
    // Start the server
    server.start();
    server.join();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Server(org.eclipse.jetty.server.Server)

Example 18 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class GlobalWebappConfigBinding method processBinding.

public void processBinding(Node node, App app) throws Exception {
    ContextHandler handler = app.getContextHandler();
    if (handler == null) {
        throw new NullPointerException("No Handler created for App: " + app);
    }
    if (handler instanceof WebAppContext) {
        WebAppContext context = (WebAppContext) handler;
        if (LOG.isDebugEnabled()) {
            LOG.debug("Binding: Configuring webapp context with global settings from: " + _jettyXml);
        }
        if (_jettyXml == null) {
            LOG.warn("Binding: global context binding is enabled but no jetty-web.xml file has been registered");
        }
        Resource globalContextSettings = Resource.newResource(_jettyXml);
        if (globalContextSettings.exists()) {
            XmlConfiguration jettyXmlConfig = new XmlConfiguration(globalContextSettings.getInputStream());
            Resource resource = Resource.newResource(app.getOriginId());
            File file = resource.getFile();
            jettyXmlConfig.getIdMap().put("Server", app.getDeploymentManager().getServer());
            jettyXmlConfig.getProperties().put("jetty.home", System.getProperty("jetty.home", "."));
            jettyXmlConfig.getProperties().put("jetty.base", System.getProperty("jetty.base", "."));
            jettyXmlConfig.getProperties().put("jetty.webapp", file.getCanonicalPath());
            jettyXmlConfig.getProperties().put("jetty.webapps", file.getParentFile().getCanonicalPath());
            jettyXmlConfig.configure(context);
        } else {
            LOG.info("Binding: Unable to locate global webapp context settings: " + _jettyXml);
        }
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) Resource(org.eclipse.jetty.util.resource.Resource) XmlConfiguration(org.eclipse.jetty.xml.XmlConfiguration) File(java.io.File)

Example 19 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class StandardDeployer method processBinding.

public void processBinding(Node node, App app) throws Exception {
    ContextHandler handler = app.getContextHandler();
    if (handler == null) {
        throw new NullPointerException("No Handler created for App: " + app);
    }
    app.getDeploymentManager().getContexts().addHandler(handler);
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler)

Example 20 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project jetty.project by eclipse.

the class StandardStarter method processBinding.

@Override
public void processBinding(Node node, App app) throws Exception {
    ContextHandler handler = app.getContextHandler();
    // start the handler
    handler.start();
    // After starting let the context manage state
    app.getDeploymentManager().getContexts().manage(handler);
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler)

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