Search in sources :

Example 21 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class LotsOfHeadersRequestTestCase method testLotsOfHeadersInRequest_MaxHeaders_Ok.

@Test
@AjpIgnore
public void testLotsOfHeadersInRequest_MaxHeaders_Ok() throws IOException {
    OptionMap existing = DefaultServer.getUndertowOptions();
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        for (int i = 0; i < getTestMaxHeaders(); ++i) {
            get.addHeader(HEADER + i, MESSAGE + i);
        }
        DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_HEADERS, TEST_MAX_HEADERS));
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        for (int i = 0; i < getTestMaxHeaders(); ++i) {
            Header[] header = result.getHeaders(HEADER + 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 22 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class LotsOfHeadersRequestTestCase method testLotsOfHeadersInRequest_MaxHeaders_BadRequest.

@Test
public void testLotsOfHeadersInRequest_MaxHeaders_BadRequest() throws IOException {
    OptionMap existing = DefaultServer.getUndertowOptions();
    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        // add request headers more than MAX_HEADERS
        for (int i = 0; i < (getTestMaxHeaders() + 1); ++i) {
            get.addHeader(HEADER + i, MESSAGE + i);
        }
        DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.MAX_HEADERS, TEST_MAX_HEADERS));
        HttpResponse result = client.execute(get);
        Assert.assertEquals(DefaultServer.isH2() ? StatusCodes.SERVICE_UNAVAILABLE : 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)

Example 23 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class QueryParameterUtils method getQueryParamEncoding.

public static String getQueryParamEncoding(HttpServerExchange exchange) {
    String encoding = null;
    OptionMap undertowOptions = exchange.getConnection().getUndertowOptions();
    if (undertowOptions.get(UndertowOptions.DECODE_URL, true)) {
        encoding = undertowOptions.get(UndertowOptions.URL_CHARSET, StandardCharsets.UTF_8.name());
    }
    return encoding;
}
Also used : OptionMap(org.xnio.OptionMap)

Example 24 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class QueryParametersTestCase method testQueryParametersShiftJIS.

@Test
@ProxyIgnore
public void testQueryParametersShiftJIS() throws IOException {
    OptionMap old = DefaultServer.getUndertowOptions();
    try {
        DefaultServer.setUndertowOptions(OptionMap.create(UndertowOptions.URL_CHARSET, "Shift_JIS"));
        TestHttpClient client = new TestHttpClient();
        try {
            runTest(client, "{unicode=>ใƒ†ใ‚นใƒˆ}", "/path?unicode=%83e%83X%83g");
        } finally {
            client.getConnectionManager().shutdown();
        }
    } finally {
        DefaultServer.setUndertowOptions(old);
    }
}
Also used : OptionMap(org.xnio.OptionMap) TestHttpClient(io.undertow.testutils.TestHttpClient) Test(org.junit.Test) ProxyIgnore(io.undertow.testutils.ProxyIgnore)

Example 25 with OptionMap

use of org.xnio.OptionMap in project undertow by undertow-io.

the class DefaultServer method startSSLServer.

/**
     * Start the SSL server using a custom SSLContext with additional options to pass to the JsseXnioSsl instance.
     *
     * @param context - The SSLContext to use for JsseXnioSsl initialisation.
     * @param options - Additional options to be passed to the JsseXnioSsl, this will be merged with the default options where
     *                applicable.
     */
public static void startSSLServer(final SSLContext context, final OptionMap options, ChannelListener openListener, int port) throws IOException {
    if (isApacheTest()) {
        return;
    }
    OptionMap combined = OptionMap.builder().addAll(serverOptions).addAll(options).set(Options.USE_DIRECT_BUFFERS, true).getMap();
    UndertowXnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, SSL_BUFFER_POOL, context);
    sslServer = ssl.createSslConnectionServer(worker, new InetSocketAddress(getHostAddress("default"), port), openListener, combined);
    sslServer.getAcceptSetter().set(openListener);
    sslServer.resumeAccepts();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) OptionMap(org.xnio.OptionMap) UndertowXnioSsl(io.undertow.protocols.ssl.UndertowXnioSsl)

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