Search in sources :

Example 86 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.

the class IncludedServletTest method startServer.

@Before
public void startServer() throws Exception {
    this.server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost("localhost");
    connector.setPort(0);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addServlet(TopServlet.class, "/top");
    context.addServlet(IncludedServlet.class, "/included");
    server.setHandler(context);
    server.start();
    int port = connector.getLocalPort();
    String host = connector.getHost();
    baseUri = URI.create("http://" + host + ":" + port + "/");
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) Matchers.containsString(org.hamcrest.Matchers.containsString) Before(org.junit.Before)

Example 87 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.

the class RequestURITest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setPort(0);
    server.addConnector(connector);
    ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    server.setHandler(context);
    context.addServlet(RequestUriServlet.class, "/*");
    server.start();
    String host = connector.getHost();
    if (host == null) {
        host = "localhost";
    }
    int port = connector.getLocalPort();
    serverURI = new URI(String.format("http://%s:%d/", host, port));
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server) URI(java.net.URI) BeforeClass(org.junit.BeforeClass)

Example 88 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.

the class ServletTester method createConnector.

/** Create a port based connector.
     * This methods adds a port connector to the server
     * @param localhost true if connector should use localhost, false for default host behavior.
     * @return A URL to access the server via the connector.
     * @throws Exception on test failure
     */
public String createConnector(boolean localhost) throws Exception {
    ServerConnector connector = new ServerConnector(_server);
    if (localhost)
        connector.setHost("127.0.0.1");
    _server.addConnector(connector);
    if (_server.isStarted())
        connector.start();
    else
        connector.open();
    return "http://" + (localhost ? "127.0.0.1" : InetAddress.getLocalHost().getHostAddress()) + ":" + connector.getLocalPort();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector)

Example 89 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.

the class DigestPostTest method setUpServer.

@BeforeClass
public static void setUpServer() {
    try {
        _server = new Server();
        _server.setConnectors(new Connector[] { new ServerConnector(_server) });
        ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SECURITY);
        context.setContextPath("/test");
        context.addServlet(PostServlet.class, "/");
        TestLoginService realm = new TestLoginService("test");
        realm.putUser("testuser", new Password("password"), new String[] { "test" });
        _server.addBean(realm);
        ConstraintSecurityHandler security = (ConstraintSecurityHandler) context.getSecurityHandler();
        security.setAuthenticator(new DigestAuthenticator());
        security.setLoginService(realm);
        Constraint constraint = new Constraint("SecureTest", "test");
        constraint.setAuthenticate(true);
        ConstraintMapping mapping = new ConstraintMapping();
        mapping.setConstraint(constraint);
        mapping.setPathSpec("/*");
        security.setConstraintMappings(Collections.singletonList(mapping));
        HandlerCollection handlers = new HandlerCollection();
        handlers.setHandlers(new Handler[] { context, new DefaultHandler() });
        _server.setHandler(handlers);
        _server.start();
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) ConstraintMapping(org.eclipse.jetty.security.ConstraintMapping) Server(org.eclipse.jetty.server.Server) DigestAuthenticator(org.eclipse.jetty.security.authentication.DigestAuthenticator) Constraint(org.eclipse.jetty.util.security.Constraint) ConstraintSecurityHandler(org.eclipse.jetty.security.ConstraintSecurityHandler) HandlerCollection(org.eclipse.jetty.server.handler.HandlerCollection) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) IOException(java.io.IOException) Password(org.eclipse.jetty.util.security.Password) DefaultHandler(org.eclipse.jetty.server.handler.DefaultHandler) BeforeClass(org.junit.BeforeClass)

Example 90 with ServerConnector

use of org.eclipse.jetty.server.ServerConnector in project jetty.project by eclipse.

the class HttpInputIntegrationTest method beforeClass.

@BeforeClass
public static void beforeClass() throws Exception {
    __config = new HttpConfiguration();
    __server = new Server();
    LocalConnector local = new LocalConnector(__server, new HttpConnectionFactory(__config));
    local.setIdleTimeout(4000);
    __server.addConnector(local);
    ServerConnector http = new ServerConnector(__server, new HttpConnectionFactory(__config), new HTTP2CServerConnectionFactory(__config));
    http.setIdleTimeout(4000);
    __server.addConnector(http);
    // SSL Context Factory for HTTPS and HTTP/2
    String jetty_distro = System.getProperty("jetty.distro", "../../jetty-distribution/target/distribution");
    __sslContextFactory = new SslContextFactory();
    __sslContextFactory.setKeyStorePath(jetty_distro + "/../../../jetty-server/src/test/config/etc/keystore");
    __sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
    __sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
    // HTTPS Configuration
    __sslConfig = new HttpConfiguration(__config);
    __sslConfig.addCustomizer(new SecureRequestCustomizer());
    // HTTP/1 Connection Factory
    HttpConnectionFactory h1 = new HttpConnectionFactory(__sslConfig);
    /* TODO
        // HTTP/2 Connection Factory
        HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(__sslConfig);
        
        NegotiatingServerConnectionFactory.checkProtocolNegotiationAvailable();
        ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
        alpn.setDefaultProtocol(h1.getProtocol());
        */
    // SSL Connection Factory
    SslConnectionFactory ssl = new SslConnectionFactory(__sslContextFactory, h1.getProtocol());
    // HTTP/2 Connector
    ServerConnector http2 = new ServerConnector(__server, ssl, /*TODO alpn,h2,*/
    h1);
    http2.setIdleTimeout(4000);
    __server.addConnector(http2);
    ServletContextHandler context = new ServletContextHandler(__server, "/ctx");
    ServletHolder holder = new ServletHolder(new TestServlet());
    holder.setAsyncSupported(true);
    context.addServlet(holder, "/*");
    __server.start();
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HTTP2CServerConnectionFactory(org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) BeforeClass(org.junit.BeforeClass)

Aggregations

ServerConnector (org.eclipse.jetty.server.ServerConnector)291 Server (org.eclipse.jetty.server.Server)213 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)91 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)83 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)67 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)64 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)55 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)53 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)45 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)45 URI (java.net.URI)37 Test (org.junit.Test)32 File (java.io.File)30 BeforeClass (org.junit.BeforeClass)29 IOException (java.io.IOException)27 Before (org.junit.Before)25 BeforeClass (org.testng.annotations.BeforeClass)22 ServletException (javax.servlet.ServletException)21 HttpServletRequest (javax.servlet.http.HttpServletRequest)19 Connector (org.eclipse.jetty.server.Connector)19