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();
}
}
use of org.xnio.OptionMap in project undertow by undertow-io.
the class LotsOfQueryParametersTestCase method testLotsOfQueryParameters_MaxParameters_BadRequest.
@Test
@AjpIgnore
public void testLotsOfQueryParameters_MaxParameters_BadRequest() throws IOException {
OptionMap existing = DefaultServer.getUndertowOptions();
TestHttpClient client = new TestHttpClient();
try {
StringBuilder qs = new StringBuilder();
// add query parameters more than specified MAX_PARAMETERS
for (int i = 0; i < (TEST_MAX_PARAMETERS + 1); ++i) {
qs.append(QUERY + i);
qs.append("=");
qs.append(URLEncoder.encode(MESSAGE + i, "UTF-8"));
qs.append("&");
}
// delete last useless '&'
qs.deleteCharAt(qs.length() - 1);
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path?" + qs.toString());
DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_PARAMETERS, TEST_MAX_PARAMETERS));
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.BAD_REQUEST, result.getStatusLine().getStatusCode());
} finally {
DefaultServer.setUndertowOptions(existing);
client.getConnectionManager().shutdown();
}
}
use of org.xnio.OptionMap in project undertow by undertow-io.
the class LotsOfQueryParametersTestCase method testLotsOfQueryParameters_MaxParameters_Ok.
@Test
@AjpIgnore
public void testLotsOfQueryParameters_MaxParameters_Ok() throws IOException {
OptionMap existing = DefaultServer.getUndertowOptions();
TestHttpClient client = new TestHttpClient();
try {
StringBuilder qs = new StringBuilder();
for (int i = 0; i < TEST_MAX_PARAMETERS; ++i) {
qs.append(QUERY + i);
qs.append("=");
qs.append(URLEncoder.encode(MESSAGE + i, "UTF-8"));
qs.append("&");
}
// delete last useless '&'
qs.deleteCharAt(qs.length() - 1);
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path?" + qs.toString());
DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_PARAMETERS, TEST_MAX_PARAMETERS));
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
for (int i = 0; i < TEST_MAX_PARAMETERS; ++i) {
Header[] header = result.getHeaders(QUERY + i);
Assert.assertEquals(MESSAGE + i, header[0].getValue());
}
} finally {
DefaultServer.setUndertowOptions(existing);
client.getConnectionManager().shutdown();
}
}
use of org.xnio.OptionMap in project undertow by undertow-io.
the class AutobahnExtensionCustomReceiverServer method run.
public void run() {
xnio = Xnio.getInstance();
try {
worker = xnio.createWorker(OptionMap.builder().set(Options.WORKER_WRITE_THREADS, 4).set(Options.WORKER_READ_THREADS, 4).set(Options.CONNECTION_HIGH_WATER, 1000000).set(Options.CONNECTION_LOW_WATER, 1000000).set(Options.WORKER_TASK_CORE_THREADS, 10).set(Options.WORKER_TASK_MAX_THREADS, 12).set(Options.TCP_NODELAY, true).set(Options.CORK, true).getMap());
OptionMap serverOptions = OptionMap.builder().set(Options.WORKER_ACCEPT_THREADS, 4).set(Options.TCP_NODELAY, true).set(Options.REUSE_ADDRESSES, true).getMap();
openListener = new HttpOpenListener(new DefaultByteBufferPool(false, 8192));
ChannelListener acceptListener = ChannelListeners.openListenerAdapter(openListener);
server = worker.createStreamConnectionServer(new InetSocketAddress(port), acceptListener, serverOptions);
setRootHandler(getRootHandler().addExtension(new PerMessageDeflateHandshake()));
server.resumeAccepts();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Aggregations