use of org.xnio.OptionMap in project camel by apache.
the class UndertowEndpoint method doStart.
@Override
protected void doStart() throws Exception {
super.doStart();
if (sslContextParameters != null) {
sslContext = sslContextParameters.createSSLContext(getCamelContext());
}
// create options map
if (options != null && !options.isEmpty()) {
// favor to use the classloader that loaded the user application
ClassLoader cl = getComponent().getCamelContext().getApplicationContextClassLoader();
if (cl == null) {
cl = Options.class.getClassLoader();
}
OptionMap.Builder builder = OptionMap.builder();
for (Map.Entry<String, Object> entry : options.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (key != null && value != null) {
// upper case and dash as underscore
key = key.toUpperCase(Locale.ENGLISH).replace('-', '_');
// must be field name
key = Options.class.getName() + "." + key;
Option option = Option.fromString(key, cl);
value = option.parseValue(value.toString(), cl);
LOG.trace("Parsed option {}={}", option.getName(), value);
builder.set(option, value);
}
}
optionMap = builder.getMap();
} else {
// use an empty map
optionMap = OptionMap.EMPTY;
}
// and then configure these default options if they have not been explicit configured
if (keepAlive != null && !optionMap.contains(Options.KEEP_ALIVE)) {
// rebuild map
OptionMap.Builder builder = OptionMap.builder();
builder.addAll(optionMap).set(Options.KEEP_ALIVE, keepAlive);
optionMap = builder.getMap();
}
if (tcpNoDelay != null && !optionMap.contains(Options.TCP_NODELAY)) {
// rebuild map
OptionMap.Builder builder = OptionMap.builder();
builder.addAll(optionMap).set(Options.TCP_NODELAY, tcpNoDelay);
optionMap = builder.getMap();
}
if (reuseAddresses != null && !optionMap.contains(Options.REUSE_ADDRESSES)) {
// rebuild map
OptionMap.Builder builder = OptionMap.builder();
builder.addAll(optionMap).set(Options.REUSE_ADDRESSES, tcpNoDelay);
optionMap = builder.getMap();
}
}
use of org.xnio.OptionMap in project wildfly by wildfly.
the class ListenerService method start.
@Override
public void start(StartContext context) throws StartException {
started = true;
preStart(context);
serverService.getValue().registerListener(this);
try {
openListener = createOpenListener();
HttpHandler handler = serverService.getValue().getRoot();
for (HandlerWrapper wrapper : listenerHandlerWrappers) {
handler = wrapper.wrap(handler);
}
openListener.setRootHandler(handler);
if (enabled) {
final InetSocketAddress socketAddress = binding.getValue().getSocketAddress();
final ChannelListener<AcceptingChannel<StreamConnection>> acceptListener = ChannelListeners.openListenerAdapter(openListener);
startListening(worker.getValue(), socketAddress, acceptListener);
}
registerBinding();
} catch (IOException e) {
cleanFailedStart();
if (e instanceof BindException) {
final StringBuilder sb = new StringBuilder().append(e.getLocalizedMessage());
final InetSocketAddress socketAddress = binding.getValue().getSocketAddress();
if (socketAddress != null)
sb.append(" ").append(socketAddress);
throw new StartException(sb.toString());
} else {
throw UndertowLogger.ROOT_LOGGER.couldNotStartListener(name, e);
}
}
statisticsChangeListener = (enabled) -> {
OptionMap options = openListener.getUndertowOptions();
OptionMap.Builder builder = OptionMap.builder().addAll(options);
builder.set(UndertowOptions.ENABLE_STATISTICS, enabled);
openListener.setUndertowOptions(builder.getMap());
};
getUndertowService().registerStatisticsListener(statisticsChangeListener);
}
use of org.xnio.OptionMap in project wildfly by wildfly.
the class HttpsListenerAdd method createService.
@Override
ListenerService createService(String name, final String serverName, final OperationContext context, ModelNode model, OptionMap listenerOptions, OptionMap socketOptions) throws OperationFailedException {
OptionMap.Builder builder = OptionMap.builder().addAll(socketOptions);
HttpsListenerResourceDefinition.VERIFY_CLIENT.resolveOption(context, model, builder);
ModelNode value = HttpsListenerResourceDefinition.ENABLED_CIPHER_SUITES.resolveModelAttribute(context, model);
String cipherSuites = value.isDefined() ? value.asString() : null;
HttpsListenerResourceDefinition.ENABLED_PROTOCOLS.resolveOption(context, model, builder);
HttpsListenerResourceDefinition.SSL_SESSION_CACHE_SIZE.resolveOption(context, model, builder);
HttpsListenerResourceDefinition.SSL_SESSION_TIMEOUT.resolveOption(context, model, builder);
OptionMap.Builder listenerBuilder = OptionMap.builder().addAll(listenerOptions);
HttpsListenerResourceDefinition.ENABLE_HTTP2.resolveOption(context, model, listenerBuilder);
HttpListenerAdd.handleHttp2Options(context, model, listenerBuilder);
HttpListenerResourceDefinition.REQUIRE_HOST_HTTP11.resolveOption(context, model, listenerBuilder);
final boolean certificateForwarding = HttpListenerResourceDefinition.CERTIFICATE_FORWARDING.resolveModelAttribute(context, model).asBoolean();
final boolean proxyAddressForwarding = HttpListenerResourceDefinition.PROXY_ADDRESS_FORWARDING.resolveModelAttribute(context, model).asBoolean();
return new HttpsListenerService(name, serverName, listenerBuilder.getMap(), cipherSuites, builder.getMap(), certificateForwarding, proxyAddressForwarding);
}
use of org.xnio.OptionMap 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.OptionMap in project undertow by undertow-io.
the class ChunkedRequestTransferCodingTestCase method testMaxRequestSizeChunkedRequest.
@Test
@Ignore("sometimes the client attempts to re-use the same connection after the failure, but the server has already closed it")
public void testMaxRequestSizeChunkedRequest() throws IOException {
connection = null;
OptionMap existing = DefaultServer.getUndertowOptions();
HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
post.setHeader(HttpHeaders.CONNECTION, "close");
TestHttpClient client = new TestHttpClient();
try {
generateMessage(1);
post.setEntity(new StringEntity(message) {
@Override
public long getContentLength() {
return -1;
}
});
DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_ENTITY_SIZE, 3L));
HttpResponse result = client.execute(post);
Assert.assertEquals(StatusCodes.INTERNAL_SERVER_ERROR, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
connection = null;
DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_ENTITY_SIZE, (long) message.length()));
result = client.execute(post);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
} finally {
DefaultServer.setUndertowOptions(existing);
client.getConnectionManager().shutdown();
}
}
Aggregations