Search in sources :

Example 6 with OptionMap

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();
}
Also used : SocketBinding(org.jboss.as.network.SocketBinding) XnioSsl(org.xnio.ssl.XnioSsl) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) XnioWorker(org.xnio.XnioWorker) SecurityRealm(org.jboss.as.domain.management.SecurityRealm) MCMPConfig(io.undertow.server.handlers.proxy.mod_cluster.MCMPConfig) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) ModCluster(io.undertow.server.handlers.proxy.mod_cluster.ModCluster) OptionMap(org.xnio.OptionMap) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl) InetAddress(java.net.InetAddress)

Example 7 with OptionMap

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();
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) OptionMap(org.xnio.OptionMap) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with OptionMap

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();
    }
}
Also used : OptionMap(org.xnio.OptionMap) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test) AjpIgnore(io.undertow.testutils.AjpIgnore)

Example 9 with OptionMap

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();
    }
}
Also used : Header(org.apache.http.Header) OptionMap(org.xnio.OptionMap) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test) AjpIgnore(io.undertow.testutils.AjpIgnore)

Example 10 with OptionMap

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);
    }
}
Also used : ChannelListener(org.xnio.ChannelListener) DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) InetSocketAddress(java.net.InetSocketAddress) OptionMap(org.xnio.OptionMap) HttpOpenListener(io.undertow.server.protocol.http.HttpOpenListener) IOException(java.io.IOException)

Aggregations

OptionMap (org.xnio.OptionMap)34 InetSocketAddress (java.net.InetSocketAddress)10 Test (org.junit.Test)10 TestHttpClient (io.undertow.testutils.TestHttpClient)9 HttpResponse (org.apache.http.HttpResponse)8 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)7 ChannelListener (org.xnio.ChannelListener)7 DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)6 IOException (java.io.IOException)6 ModelNode (org.jboss.dmr.ModelNode)5 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)4 HttpHandler (io.undertow.server.HttpHandler)4 HttpGet (org.apache.http.client.methods.HttpGet)4 StreamConnection (org.xnio.StreamConnection)4 XnioSsl (org.xnio.ssl.XnioSsl)4 AjpIgnore (io.undertow.testutils.AjpIgnore)3 HttpPost (org.apache.http.client.methods.HttpPost)3 StringEntity (org.apache.http.entity.StringEntity)3 ServiceName (org.jboss.msc.service.ServiceName)3 XnioWorker (org.xnio.XnioWorker)3