Search in sources :

Example 1 with SslContextFactory

use of org.eclipse.jetty.util.ssl.SslContextFactory in project camel by apache.

the class CometdComponent method getSslSocketConnector.

protected ServerConnector getSslSocketConnector(Server server) throws Exception {
    ServerConnector sslSocketConnector = null;
    if (sslContextParameters != null) {
        SslContextFactory sslContextFactory = new CometdComponentSslContextFactory();
        sslContextFactory.setSslContext(sslContextParameters.createSSLContext(getCamelContext()));
        sslSocketConnector = new ServerConnector(server, sslContextFactory);
    } else {
        SslContextFactory sslContextFactory = new SslContextFactory();
        sslContextFactory.setKeyStorePassword(sslKeyPassword);
        sslContextFactory.setKeyManagerPassword(sslPassword);
        if (sslKeystore != null) {
            sslContextFactory.setKeyStorePath(sslKeystore);
        }
        sslSocketConnector = new ServerConnector(server, sslContextFactory);
    }
    return sslSocketConnector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory)

Example 2 with SslContextFactory

use of org.eclipse.jetty.util.ssl.SslContextFactory in project camel by apache.

the class WssProducerTest method getConnector.

@Override
protected Connector getConnector() throws Exception {
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setSslContext(defineSSLContextServerParameters().createSSLContext(camelContext));
    ServerConnector https = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, null));
    return https;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory)

Example 3 with SslContextFactory

use of org.eclipse.jetty.util.ssl.SslContextFactory in project camel by apache.

the class JettyHttpComponent method createHttpClient.

/**
     * Creates a new {@link HttpClient} and configures its proxy/thread pool and SSL based on this
     * component settings.
     *
     * @param endpoint   the instance of JettyHttpEndpoint
     * @param minThreads optional minimum number of threads in client thread pool
     * @param maxThreads optional maximum number of threads in client thread pool
     * @param ssl        option SSL parameters
     */
public CamelHttpClient createHttpClient(JettyHttpEndpoint endpoint, Integer minThreads, Integer maxThreads, SSLContextParameters ssl) throws Exception {
    SslContextFactory sslContextFactory = createSslContextFactory(ssl);
    HttpClientTransport transport = createHttpClientTransport(maxThreads);
    CamelHttpClient httpClient = createCamelHttpClient(transport, sslContextFactory);
    CamelContext context = endpoint.getCamelContext();
    if (context != null && ObjectHelper.isNotEmpty(context.getProperty("http.proxyHost")) && ObjectHelper.isNotEmpty(context.getProperty("http.proxyPort"))) {
        String host = context.getProperty("http.proxyHost");
        int port = Integer.parseInt(context.getProperty("http.proxyPort"));
        LOG.debug("CamelContext properties http.proxyHost and http.proxyPort detected. Using http proxy host: {} port: {}", host, port);
        httpClient.setProxy(host, port);
    }
    if (ObjectHelper.isNotEmpty(endpoint.getProxyHost()) && endpoint.getProxyPort() > 0) {
        String host = endpoint.getProxyHost();
        int port = endpoint.getProxyPort();
        LOG.debug("proxyHost and proxyPort options detected. Using http proxy host: {} port: {}", host, port);
        httpClient.setProxy(host, port);
    }
    // must have both min and max
    if (minThreads != null || maxThreads != null) {
        // must have both options
        if (minThreads == null || maxThreads == null) {
            throw new IllegalArgumentException("Both min and max thread pool sizes must be provided.");
        }
        // use QueueThreadPool as the default bounded is deprecated (see SMXCOMP-157)
        QueuedThreadPool qtp = new QueuedThreadPool();
        qtp.setMinThreads(minThreads.intValue());
        qtp.setMaxThreads(maxThreads.intValue());
        // and we want to use daemon threads
        qtp.setDaemon(true);
        // let the thread names indicate they are from the client
        qtp.setName("CamelJettyClient(" + ObjectHelper.getIdentityHashCode(httpClient) + ")");
        httpClient.setThreadPoolOrExecutor(qtp);
    }
    if (LOG.isDebugEnabled()) {
        if (minThreads != null) {
            LOG.debug("Created HttpClient with thread pool {}-{} -> {}", new Object[] { minThreads, maxThreads, httpClient });
        } else {
            LOG.debug("Created HttpClient with default thread pool size -> {}", httpClient);
        }
    }
    return httpClient;
}
Also used : CamelContext(org.apache.camel.CamelContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpClientTransport(org.eclipse.jetty.client.HttpClientTransport) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) Endpoint(org.apache.camel.Endpoint) HttpCommonEndpoint(org.apache.camel.http.common.HttpCommonEndpoint)

Example 4 with SslContextFactory

use of org.eclipse.jetty.util.ssl.SslContextFactory in project camel by apache.

the class JettyHttpComponent method createConnector.

protected Connector createConnector(Server server, JettyHttpEndpoint endpoint) {
    // now we just use the SelectChannelConnector as the default connector
    SslContextFactory sslcf = null;
    // Note that this was set on the endpoint when it was constructed.  It was
    // either explicitly set at the component or on the endpoint, but either way,
    // the value is already set.  We therefore do not need to look at the component
    // level SSLContextParameters again in this method.
    SSLContextParameters endpointSslContextParameters = endpoint.getSslContextParameters();
    if (endpointSslContextParameters != null) {
        try {
            sslcf = createSslContextFactory(endpointSslContextParameters);
        } catch (Exception e) {
            throw new RuntimeCamelException(e);
        }
    } else if ("https".equals(endpoint.getProtocol())) {
        sslcf = new SslContextFactory();
        String keystoreProperty = System.getProperty(JETTY_SSL_KEYSTORE);
        if (keystoreProperty != null) {
            sslcf.setKeyStorePath(keystoreProperty);
        } else if (sslKeystore != null) {
            sslcf.setKeyStorePath(sslKeystore);
        }
        String keystorePassword = System.getProperty(JETTY_SSL_KEYPASSWORD);
        if (keystorePassword != null) {
            sslcf.setKeyManagerPassword(keystorePassword);
        } else if (sslKeyPassword != null) {
            sslcf.setKeyManagerPassword(sslKeyPassword);
        }
        String password = System.getProperty(JETTY_SSL_PASSWORD);
        if (password != null) {
            sslcf.setKeyStorePassword(password);
        } else if (sslPassword != null) {
            sslcf.setKeyStorePassword(sslPassword);
        }
    }
    return createConnectorJettyInternal(server, endpoint, sslcf);
}
Also used : SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) RuntimeCamelException(org.apache.camel.RuntimeCamelException) URISyntaxException(java.net.URISyntaxException) GeneralSecurityException(java.security.GeneralSecurityException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) SSLContextParameters(org.apache.camel.util.jsse.SSLContextParameters)

Example 5 with SslContextFactory

use of org.eclipse.jetty.util.ssl.SslContextFactory in project hadoop by apache.

the class TestJettyHelper method createJettyServer.

private Server createJettyServer() {
    try {
        InetAddress localhost = InetAddress.getByName("localhost");
        String host = "localhost";
        ServerSocket ss = new ServerSocket(0, 50, localhost);
        int port = ss.getLocalPort();
        ss.close();
        Server server = new Server();
        ServerConnector conn = new ServerConnector(server);
        HttpConfiguration http_config = new HttpConfiguration();
        http_config.setRequestHeaderSize(JettyUtils.HEADER_SIZE);
        http_config.setResponseHeaderSize(JettyUtils.HEADER_SIZE);
        http_config.setSecureScheme("https");
        http_config.addCustomizer(new SecureRequestCustomizer());
        ConnectionFactory connFactory = new HttpConnectionFactory(http_config);
        conn.addConnectionFactory(connFactory);
        conn.setHost(host);
        conn.setPort(port);
        if (ssl) {
            SslContextFactory sslContextFactory = new SslContextFactory();
            sslContextFactory.setNeedClientAuth(false);
            sslContextFactory.setKeyStorePath(keyStore);
            sslContextFactory.setKeyStoreType(keyStoreType);
            sslContextFactory.setKeyStorePassword(keyStorePassword);
            conn.addFirstConnectionFactory(new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()));
        }
        server.addConnector(conn);
        return server;
    } catch (Exception ex) {
        throw new RuntimeException("Could not start embedded servlet container, " + ex.getMessage(), ex);
    }
}
Also used : SecureRequestCustomizer(org.eclipse.jetty.server.SecureRequestCustomizer) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) ServerSocket(java.net.ServerSocket) HttpConfiguration(org.eclipse.jetty.server.HttpConfiguration) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) MalformedURLException(java.net.MalformedURLException) UnknownHostException(java.net.UnknownHostException) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) ConnectionFactory(org.eclipse.jetty.server.ConnectionFactory) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) InetAddress(java.net.InetAddress)

Aggregations

SslContextFactory (org.eclipse.jetty.util.ssl.SslContextFactory)139 ServerConnector (org.eclipse.jetty.server.ServerConnector)54 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)44 Server (org.eclipse.jetty.server.Server)43 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)43 Test (org.junit.Test)40 HttpConfiguration (org.eclipse.jetty.server.HttpConfiguration)37 SecureRequestCustomizer (org.eclipse.jetty.server.SecureRequestCustomizer)35 QueuedThreadPool (org.eclipse.jetty.util.thread.QueuedThreadPool)23 InputStream (java.io.InputStream)18 IOException (java.io.IOException)17 File (java.io.File)15 SSLContext (javax.net.ssl.SSLContext)15 ServletException (javax.servlet.ServletException)15 OutputStream (java.io.OutputStream)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)13 AbstractHandler (org.eclipse.jetty.server.handler.AbstractHandler)11 InetSocketAddress (java.net.InetSocketAddress)10