Search in sources :

Example 61 with ContextHandler

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

the class RoutingHandlerTest method withSessionHandler.

@Test
void withSessionHandler() throws Exception {
    final ContextHandler handler1 = new ContextHandler();
    final ServletContextHandler handler2 = new ServletContextHandler();
    final SessionHandler childHandler1 = new SessionHandler();
    handler2.setSessionHandler(childHandler1);
    final RoutingHandler handler = new RoutingHandler(Maps.of(connector1, handler1, connector2, handler2));
    new Server().setHandler(handler);
    handler.start();
    try {
        assertThat(getSessionHandlers(handler)).containsOnly(childHandler1);
    } finally {
        handler.stop();
    }
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) Server(org.eclipse.jetty.server.Server) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.jupiter.api.Test)

Example 62 with ContextHandler

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

the class JettyServer method makeContext.

private Handler makeContext(JettyEnv env, Config cfg, SessionHandler sessionHandler) {
    final Set<String> paths = new HashSet<>();
    for (URI u : listenURLs(cfg)) {
        String p = u.getPath();
        if (p == null || p.isEmpty()) {
            p = "/";
        }
        while (1 < p.length() && p.endsWith("/")) {
            p = p.substring(0, p.length() - 1);
        }
        paths.add(p);
    }
    final List<ContextHandler> all = new ArrayList<>();
    for (String path : paths) {
        all.add(makeContext(path, env, cfg, sessionHandler));
    }
    if (all.size() == 1) {
        // 
        return all.get(0);
    }
    // We have more than one path served out of this container so
    // combine them in a handler which supports dispatching to the
    // individual contexts.
    // 
    final ContextHandlerCollection r = new ContextHandlerCollection();
    r.setHandlers(all.toArray(new Handler[0]));
    return r;
}
Also used : ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ArrayList(java.util.ArrayList) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) StatisticsHandler(org.eclipse.jetty.server.handler.StatisticsHandler) Handler(org.eclipse.jetty.server.Handler) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SessionHandler(org.eclipse.jetty.server.session.SessionHandler) RequestLogHandler(org.eclipse.jetty.server.handler.RequestLogHandler) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) URI(java.net.URI) HashSet(java.util.HashSet)

Example 63 with ContextHandler

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

the class Jetty9ServerTest method shouldAddRootRequestHandler.

@Test
public void shouldAddRootRequestHandler() throws Exception {
    jetty9Server.configure();
    jetty9Server.startHandlers();
    ContextHandler rootRequestHandler = getLoadedHandlers().get(GoServerLoadingIndicationHandler.class);
    assertThat(rootRequestHandler.getContextPath(), is("/"));
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Test(org.junit.jupiter.api.Test)

Example 64 with ContextHandler

use of org.eclipse.jetty.server.handler.ContextHandler in project rabbitmq-java-client by rabbitmq.

the class OAuth2ClientCredentialsGrantCredentialsProviderTest method startHttpsServer.

KeyStore startHttpsServer(int port, Handler handler) throws Exception {
    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    String keyStorePassword = "password";
    keyStore.load(null, keyStorePassword.toCharArray());
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    kpg.initialize(2048);
    KeyPair kp = kpg.generateKeyPair();
    JcaX509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(new X500NameBuilder().addRDN(BCStyle.CN, "localhost").build(), BigInteger.valueOf(new SecureRandom().nextInt()), Date.from(Instant.now().minus(10, ChronoUnit.DAYS)), Date.from(Instant.now().plus(10, ChronoUnit.DAYS)), new X500NameBuilder().addRDN(BCStyle.CN, "localhost").build(), kp.getPublic());
    X509CertificateHolder certificateHolder = certificateBuilder.build(new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(kp.getPrivate()));
    X509Certificate certificate = new JcaX509CertificateConverter().getCertificate(certificateHolder);
    keyStore.setKeyEntry("default", kp.getPrivate(), keyStorePassword.toCharArray(), new Certificate[] { certificate });
    server = new Server();
    SslContextFactory sslContextFactory = new SslContextFactory.Server();
    sslContextFactory.setKeyStore(keyStore);
    sslContextFactory.setKeyStorePassword(keyStorePassword);
    HttpConfiguration httpsConfiguration = new HttpConfiguration();
    httpsConfiguration.setSecureScheme("https");
    httpsConfiguration.setSecurePort(port);
    httpsConfiguration.setOutputBufferSize(32768);
    SecureRequestCustomizer src = new SecureRequestCustomizer();
    src.setStsMaxAge(2000);
    src.setStsIncludeSubDomains(true);
    httpsConfiguration.addCustomizer(src);
    ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), new HttpConnectionFactory(httpsConfiguration));
    https.setPort(port);
    https.setIdleTimeout(500000);
    server.setConnectors(new Connector[] { https });
    ContextHandler context = new ContextHandler();
    context.setContextPath("/uaa/oauth/token");
    context.setHandler(handler);
    server.setHandler(context);
    server.start();
    return keyStore;
}
Also used : KeyPair(java.security.KeyPair) X500NameBuilder(org.bouncycastle.asn1.x500.X500NameBuilder) JcaContentSignerBuilder(org.bouncycastle.operator.jcajce.JcaContentSignerBuilder) SecureRandom(java.security.SecureRandom) KeyPairGenerator(java.security.KeyPairGenerator) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) JcaX509CertificateConverter(org.bouncycastle.cert.jcajce.JcaX509CertificateConverter) JcaX509v3CertificateBuilder(org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder) X509CertificateHolder(org.bouncycastle.cert.X509CertificateHolder)

Example 65 with ContextHandler

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

the class Jetty9WebSocketDestination method getServer.

Server getServer(ServletConfig config, ServletContext context) {
    ContextHandler.Context c = (ContextHandler.Context) context;
    ContextHandler h = c.getContextHandler();
    return h.getServer();
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) ServletContext(javax.servlet.ServletContext)

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