use of org.xnio.ssl.XnioSsl in project wildfly by wildfly.
the class ModClusterService method start.
@Override
public synchronized void start(StartContext context) throws StartException {
super.start(context);
SSLContext sslContext = this.sslContext.getOptionalValue();
if (sslContext == null) {
SecurityRealm realm = securityRealm.getOptionalValue();
if (realm != null) {
sslContext = realm.getSSLContext();
}
}
//TODO: SSL support for the client
//TODO: wire up idle timeout when new version of undertow arrives
final ModCluster.Builder modClusterBuilder;
final XnioWorker worker = workerInjectedValue.getValue();
if (sslContext == null) {
modClusterBuilder = ModCluster.builder(worker);
} else {
OptionMap.Builder builder = OptionMap.builder();
builder.set(Options.USE_DIRECT_BUFFERS, true);
OptionMap combined = builder.getMap();
XnioSsl xnioSsl = new UndertowXnioSsl(worker.getXnio(), combined, sslContext);
modClusterBuilder = ModCluster.builder(worker, UndertowClient.getInstance(), xnioSsl);
}
modClusterBuilder.setMaxRetries(maxRetries).setClientOptions(clientOptions).setHealthCheckInterval(healthCheckInterval).setMaxRequestTime(maxRequestTime).setCacheConnections(cachedConnections).setQueueNewRequests(requestQueueSize > 0).setRequestQueueSize(requestQueueSize).setRemoveBrokenNodes(removeBrokenNodes).setTtl(connectionIdleTimeout).setMaxConnections(connectionsPerThread).setUseAlias(useAlias);
if (FailoverStrategy.DETERMINISTIC.equals(failoverStrategy)) {
modClusterBuilder.setDeterministicFailover(true);
}
modCluster = modClusterBuilder.build();
MCMPConfig.Builder builder = MCMPConfig.builder();
final SocketBinding advertiseBinding = advertiseSocketBinding.getOptionalValue();
if (advertiseBinding != null) {
InetAddress multicastAddress = advertiseBinding.getMulticastAddress();
if (multicastAddress == null) {
throw UndertowLogger.ROOT_LOGGER.advertiseSocketBindingRequiresMulticastAddress();
}
if (advertiseFrequency > 0) {
builder.enableAdvertise().setAdvertiseAddress(advertiseBinding.getSocketAddress().getAddress().getHostAddress()).setAdvertiseGroup(multicastAddress.getHostAddress()).setAdvertisePort(advertiseBinding.getMulticastPort()).setAdvertiseFrequency(advertiseFrequency).setPath(advertisePath).setProtocol(advertiseProtocol).setSecurityKey(securityKey);
}
}
builder.setManagementHost(managementSocketBinding.getValue().getSocketAddress().getHostString());
builder.setManagementPort(managementSocketBinding.getValue().getSocketAddress().getPort());
config = builder.build();
if (advertiseBinding != null && advertiseFrequency > 0) {
try {
modCluster.advertise(config);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
modCluster.start();
}
use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.
the class HttpClientTestCase method testSsl.
@Test
public void testSsl() throws Exception {
//
DefaultServer.setRootHandler(SIMPLE_MESSAGE_HANDLER);
final UndertowClient client = createClient();
final List<ClientResponse> responses = new CopyOnWriteArrayList<>();
final CountDownLatch latch = new CountDownLatch(10);
DefaultServer.startSSLServer();
SSLContext context = DefaultServer.getClientSSLContext();
XnioSsl ssl = new UndertowXnioSsl(DefaultServer.getWorker().getXnio(), OptionMap.EMPTY, DefaultServer.SSL_BUFFER_POOL, context);
final ClientConnection connection = client.connect(new URI(DefaultServer.getDefaultServerSSLAddress()), worker, ssl, DefaultServer.getBufferPool(), OptionMap.EMPTY).get();
try {
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
final ClientRequest request = new ClientRequest().setMethod(Methods.GET).setPath("/");
request.getRequestHeaders().put(Headers.HOST, DefaultServer.getHostAddress());
connection.sendRequest(request, createClientCallback(responses, latch));
}
}
});
latch.await(10, TimeUnit.SECONDS);
Assert.assertEquals(10, responses.size());
for (final ClientResponse response : responses) {
Assert.assertEquals(message, response.getAttachment(RESPONSE_BODY));
}
} finally {
connection.getIoThread().execute(new Runnable() {
@Override
public void run() {
IoUtils.safeClose(connection);
}
});
DefaultServer.stopSSLServer();
}
}
use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.
the class DefaultWebSocketClientSslProvider method getSsl.
@Override
public XnioSsl getSsl(XnioWorker worker, Endpoint endpoint, ClientEndpointConfig cec, URI uri) {
XnioSsl ssl = getThreadLocalSsl(worker);
if (ssl != null) {
return ssl;
}
//look for some SSL config
SSLContext sslContext = (SSLContext) cec.getUserProperties().get(SSL_CONTEXT);
if (sslContext != null) {
return new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, sslContext);
}
return null;
}
use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.
the class ServerWebSocketContainer method connectToServer.
@Override
public Session connectToServer(final Object annotatedEndpointInstance, final URI path) throws DeploymentException, IOException {
if (closed) {
throw new ClosedChannelException();
}
ConfiguredClientEndpoint config = getClientEndpoint(annotatedEndpointInstance.getClass(), false);
if (config == null) {
throw JsrWebSocketMessages.MESSAGES.notAValidClientEndpointType(annotatedEndpointInstance.getClass());
}
Endpoint instance = config.getFactory().createInstance(new ImmediateInstanceHandle<>(annotatedEndpointInstance));
XnioSsl ssl = null;
for (WebsocketClientSslProvider provider : clientSslProviders) {
ssl = provider.getSsl(xnioWorker, annotatedEndpointInstance, path);
if (ssl != null) {
break;
}
}
return connectToServerInternal(instance, ssl, config, path);
}
use of org.xnio.ssl.XnioSsl in project undertow by undertow-io.
the class ServerWebSocketContainer method connectToServer.
@Override
public Session connectToServer(Class<?> aClass, URI uri) throws DeploymentException, IOException {
if (closed) {
throw new ClosedChannelException();
}
ConfiguredClientEndpoint config = getClientEndpoint(aClass, true);
if (config == null) {
throw JsrWebSocketMessages.MESSAGES.notAValidClientEndpointType(aClass);
}
try {
AnnotatedEndpointFactory factory = config.getFactory();
InstanceHandle<?> instance = config.getInstanceFactory().createInstance();
XnioSsl ssl = null;
for (WebsocketClientSslProvider provider : clientSslProviders) {
ssl = provider.getSsl(xnioWorker, aClass, uri);
if (ssl != null) {
break;
}
}
return connectToServerInternal(factory.createInstance(instance), ssl, config, uri);
} catch (InstantiationException e) {
throw new RuntimeException(e);
}
}
Aggregations