Search in sources :

Example 36 with ServerConnector

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

the class SslSelectChannelTimeoutTest method init.

@Before
public void init() throws Exception {
    String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystorePath);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystorePath);
    sslContextFactory.setTrustStorePassword("storepwd");
    ServerConnector connector = new ServerConnector(_server, 1, 1, sslContextFactory);
    //250 msec max idle
    connector.setIdleTimeout(MAX_IDLE_TIME);
    startServer(connector);
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = new FileInputStream(keystorePath)) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    __sslContext = SSLContext.getInstance("SSL");
    __sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) Before(org.junit.Before)

Example 37 with ServerConnector

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

the class SSLCloseTest method testClose.

@Test
public void testClose() throws Exception {
    File keystore = MavenTestingUtils.getTestResourceFile("keystore");
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStoreResource(Resource.newResource(keystore));
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server, sslContextFactory);
    connector.setPort(0);
    server.addConnector(connector);
    server.setHandler(new WriteHandler());
    server.start();
    SSLContext ctx = SSLContext.getInstance("TLSv1.2");
    ctx.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
    int port = connector.getLocalPort();
    Socket socket = ctx.getSocketFactory().createSocket("localhost", port);
    OutputStream os = socket.getOutputStream();
    os.write(("GET /test HTTP/1.1\r\n" + "Host:test\r\n" + "Connection:close\r\n\r\n").getBytes());
    os.flush();
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    String line;
    while ((line = in.readLine()) != null) {
        if (line.trim().length() == 0)
            break;
    }
    Thread.sleep(2000);
    while (in.readLine() != null) Thread.yield();
}
Also used : Server(org.eclipse.jetty.server.Server) InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) SSLContext(javax.net.ssl.SSLContext) ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) BufferedReader(java.io.BufferedReader) File(java.io.File) Socket(java.net.Socket) Test(org.junit.Test)

Example 38 with ServerConnector

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

the class SSLEngineTest method startServer.

@Before
public void startServer() throws Exception {
    String keystore = MavenTestingUtils.getTestResourceFile("keystore").getAbsolutePath();
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystore);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    server = new Server();
    HttpConnectionFactory http = new HttpConnectionFactory();
    http.setInputBufferSize(512);
    http.getHttpConfiguration().setRequestHeaderSize(512);
    connector = new ServerConnector(server, sslContextFactory, http);
    connector.setPort(0);
    connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setSendDateHeader(false);
    server.addConnector(connector);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) Before(org.junit.Before)

Example 39 with ServerConnector

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

the class SSLSelectChannelConnectorLoadTest method startServer.

@BeforeClass
public static void startServer() throws Exception {
    String keystorePath = System.getProperty("basedir", ".") + "/src/test/resources/keystore";
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystorePath);
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystorePath);
    sslContextFactory.setTrustStorePassword("storepwd");
    server = new Server();
    connector = new ServerConnector(server, sslContextFactory);
    server.addConnector(connector);
    server.setHandler(new EmptyHandler());
    server.start();
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = new FileInputStream(keystorePath)) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) BeforeClass(org.junit.BeforeClass)

Example 40 with ServerConnector

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

the class AsyncContextListenersTest method prepare.

public void prepare(String path, HttpServlet servlet) throws Exception {
    _server = new Server();
    _connector = new ServerConnector(_server);
    _server.addConnector(_connector);
    ServletContextHandler context = new ServletContextHandler(_server, "/", false, false);
    context.addServlet(new ServletHolder(servlet), path);
    _server.start();
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Server(org.eclipse.jetty.server.Server)

Aggregations

ServerConnector (org.eclipse.jetty.server.ServerConnector)287 Server (org.eclipse.jetty.server.Server)211 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)87 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)80 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)66 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)61 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)52 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)52 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)44 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)43 URI (java.net.URI)37 Test (org.junit.Test)32 File (java.io.File)29 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