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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations