Search in sources :

Example 21 with LocalConnector

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

the class DefaultServletRangesTest method init.

@Before
public void init() throws Exception {
    server = new Server();
    connector = new LocalConnector(server);
    connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendServerVersion(false);
    context = new ServletContextHandler();
    context.setContextPath("/context");
    context.setWelcomeFiles(new String[] { "index.html", "index.jsp", "index.htm" });
    server.setHandler(context);
    server.addConnector(connector);
    testdir.ensureEmpty();
    File resBase = testdir.getPathFile("docroot").toFile();
    FS.ensureDirExists(resBase);
    File data = new File(resBase, "data.txt");
    createFile(data, DATA);
    String resBasePath = resBase.getAbsolutePath();
    ServletHolder defholder = context.addServlet(DefaultServlet.class, "/");
    defholder.setInitParameter("acceptRanges", "true");
    defholder.setInitParameter("resourceBase", resBasePath);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) File(java.io.File) Before(org.junit.Before)

Example 22 with LocalConnector

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

the class DefaultServletTest method init.

@Before
public void init() throws Exception {
    server = new Server();
    connector = new LocalConnector(server);
    connector.getConnectionFactory(HttpConfiguration.ConnectionFactory.class).getHttpConfiguration().setSendServerVersion(false);
    context = new ServletContextHandler();
    context.setContextPath("/context");
    context.setWelcomeFiles(new String[] { "index.html", "index.jsp", "index.htm" });
    server.setHandler(context);
    server.addConnector(connector);
    server.start();
}
Also used : Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) Before(org.junit.Before)

Example 23 with LocalConnector

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

the class ServletTester method createLocalConnector.

public LocalConnector createLocalConnector() {
    LocalConnector connector = new LocalConnector(_server);
    _server.addConnector(connector);
    return connector;
}
Also used : LocalConnector(org.eclipse.jetty.server.LocalConnector)

Example 24 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector 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)

Example 25 with LocalConnector

use of org.eclipse.jetty.server.LocalConnector in project felix by apache.

the class HttpJettyConnectorTest method testRegisterConnectorFactoryOk.

@Test
public void testRegisterConnectorFactoryOk() throws Exception {
    final CountDownLatch openLatch = new CountDownLatch(1);
    final CountDownLatch closeLatch = new CountDownLatch(1);
    ConnectorFactory factory = new ConnectorFactory() {

        @Override
        public Connector createConnector(Server server) {
            return new LocalConnector(server) {

                @Override
                public void doStart() throws Exception {
                    openLatch.countDown();
                    super.doStart();
                }

                @Override
                public void doStop() throws Exception {
                    closeLatch.countDown();
                    super.doStop();
                }
            };
        }
    };
    ServiceRegistration reg = m_context.registerService(ConnectorFactory.class.getName(), factory, null);
    // Should be opened automatically when picked up by the Jetty implementation...
    assertTrue("Felix HTTP Jetty did not open the Connection or pick up the registered ConnectionFactory", openLatch.await(5, TimeUnit.SECONDS));
    // Should close our connection...
    reg.unregister();
    assertTrue("Felix HTTP Jetty did not close the Connection", closeLatch.await(5, TimeUnit.SECONDS));
}
Also used : ConnectorFactory(org.apache.felix.http.jetty.ConnectorFactory) Server(org.eclipse.jetty.server.Server) LocalConnector(org.eclipse.jetty.server.LocalConnector) CountDownLatch(java.util.concurrent.CountDownLatch) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

LocalConnector (org.eclipse.jetty.server.LocalConnector)47 Server (org.eclipse.jetty.server.Server)43 Before (org.junit.Before)20 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)13 Test (org.junit.Test)12 Matchers.containsString (org.hamcrest.Matchers.containsString)7 BeforeClass (org.junit.BeforeClass)7 ContextHandler (org.eclipse.jetty.server.handler.ContextHandler)6 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)5 ContextHandlerCollection (org.eclipse.jetty.server.handler.ContextHandlerCollection)4 SessionHandler (org.eclipse.jetty.server.session.SessionHandler)4 Password (org.eclipse.jetty.util.security.Password)4 File (java.io.File)3 IOException (java.io.IOException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ServerConnector (org.eclipse.jetty.server.ServerConnector)3 HandlerList (org.eclipse.jetty.server.handler.HandlerList)3 Path (java.nio.file.Path)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2