Search in sources :

Example 11 with ConnectionFactory

use of org.eclipse.jetty.server.ConnectionFactory in project spark by perwendel.

the class SocketConnectorFactoryTest method testCreateSecureSocketConnector.

@Test
@PrepareForTest({ ServerConnector.class })
public void testCreateSecureSocketConnector() throws Exception {
    final String host = "localhost";
    final int port = 8888;
    final String keystoreFile = "keystoreFile.jks";
    final String keystorePassword = "keystorePassword";
    final String truststoreFile = "truststoreFile.jks";
    final String trustStorePassword = "trustStorePassword";
    SslStores sslStores = SslStores.create(keystoreFile, keystorePassword, truststoreFile, trustStorePassword);
    Server server = new Server();
    ServerConnector serverConnector = SocketConnectorFactory.createSecureSocketConnector(server, host, port, sslStores);
    String internalHost = Whitebox.getInternalState(serverConnector, "_host");
    int internalPort = Whitebox.getInternalState(serverConnector, "_port");
    assertEquals("Server Connector Host should be set to the specified server", host, internalHost);
    assertEquals("Server Connector Port should be set to the specified port", port, internalPort);
    Map<String, ConnectionFactory> factories = Whitebox.getInternalState(serverConnector, "_factories");
    assertTrue("Should return true because factory for SSL should have been set", factories.containsKey("ssl") && factories.get("ssl") != null);
    SslConnectionFactory sslConnectionFactory = (SslConnectionFactory) factories.get("ssl");
    SslContextFactory sslContextFactory = sslConnectionFactory.getSslContextFactory();
    assertEquals("Should return the Keystore file specified", keystoreFile, sslContextFactory.getKeyStoreResource().getFile().getName());
    assertEquals("Should return the Truststore file specified", truststoreFile, sslContextFactory.getTrustStoreResource().getFile().getName());
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Server(org.eclipse.jetty.server.Server) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) SslStores(spark.ssl.SslStores) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 12 with ConnectionFactory

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

the class JettyHTTPServerEngineFactoryTest method testMakeSureJetty9ConnectorConfigured.

@Test
public void testMakeSureJetty9ConnectorConfigured() throws Exception {
    URL config = getClass().getResource("server-engine-factory-jetty9-connector.xml");
    bus = new SpringBusFactory().createBus(config, true);
    JettyHTTPServerEngineFactory factory = bus.getExtension(JettyHTTPServerEngineFactory.class);
    assertNotNull("EngineFactory is not configured.", factory);
    JettyHTTPServerEngine engine = null;
    engine = factory.createJettyHTTPServerEngine(1234, "http");
    assertNotNull("Engine is not available.", engine);
    assertEquals(1234, engine.getPort());
    assertEquals("Not http", "http", engine.getProtocol());
    Connector connector = engine.getConnector();
    Collection<ConnectionFactory> connectionFactories = connector.getConnectionFactories();
    assertEquals("Has one HttpConnectionFactory", 1, connectionFactories.size());
    ConnectionFactory connectionFactory = connectionFactories.iterator().next();
    assertTrue(connectionFactory instanceof HttpConnectionFactory);
    HttpConfiguration httpConfiguration = ((HttpConnectionFactory) connectionFactory).getHttpConfiguration();
    assertEquals("Has one ForwardedRequestCustomizer", 1, httpConfiguration.getCustomizers().size());
    assertTrue(httpConfiguration.getCustomizers().iterator().next() instanceof org.eclipse.jetty.server.ForwardedRequestCustomizer);
}
Also used : Connector(org.eclipse.jetty.server.Connector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 13 with ConnectionFactory

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

the class JettyHTTPServerEngine method createConnectorJetty.

AbstractConnector createConnectorJetty(SslContextFactory sslcf, String hosto, int porto, int major, int minor) {
    AbstractConnector result = null;
    try {
        HttpConfiguration httpConfig = new HttpConfiguration();
        httpConfig.setSendServerVersion(getSendServerVersion());
        HttpConnectionFactory httpFactory = new HttpConnectionFactory(httpConfig);
        Collection<ConnectionFactory> connectionFactories = new ArrayList<>();
        result = new org.eclipse.jetty.server.ServerConnector(server);
        if (tlsServerParameters != null) {
            httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
            SslConnectionFactory scf = new SslConnectionFactory(sslcf, "HTTP/1.1");
            connectionFactories.add(scf);
            String proto = (major > 9 || (major == 9 && minor >= 3)) ? "SSL" : "SSL-HTTP/1.1";
            result.setDefaultProtocol(proto);
        }
        connectionFactories.add(httpFactory);
        result.setConnectionFactories(connectionFactories);
        if (getMaxIdleTime() > 0) {
            result.setIdleTimeout(Long.valueOf(getMaxIdleTime()));
        }
    } catch (RuntimeException rex) {
        throw rex;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
    return result;
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) ServerConnector(org.eclipse.jetty.server.ServerConnector) AbstractConnector(org.eclipse.jetty.server.AbstractConnector)

Aggregations

ConnectionFactory (org.eclipse.jetty.server.ConnectionFactory)13 ServerConnector (org.eclipse.jetty.server.ServerConnector)10 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)8 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)7 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)7 Server (org.eclipse.jetty.server.Server)6 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)3 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)3 URI (java.net.URI)2 URL (java.net.URL)2 Connector (org.eclipse.jetty.server.Connector)2 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 File (java.io.File)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 MalformedURLException (java.net.MalformedURLException)1 ServerSocket (java.net.ServerSocket)1