Search in sources :

Example 96 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class AjpParsingUnitTestCase method testInvalidQueryString.

@Test
public void testInvalidQueryString() throws Exception {
    ByteBuffer data = createAjpRequest("/hi".getBytes(StandardCharsets.UTF_8), "param=value%http".getBytes(StandardCharsets.UTF_8));
    HttpServerExchange result = new HttpServerExchange(null);
    AjpRequestParseState state = new AjpRequestParseState();
    AJP_REQUEST_PARSER.parse(data, state, result);
    Assert.assertTrue(state.badRequest);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) UnitTest(io.undertow.testutils.category.UnitTest)

Example 97 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class AjpParsingUnitTestCase method testByteByByteAjpParsing.

@Test
public void testByteByByteAjpParsing() throws IOException, BadRequestException {
    final ByteBuffer buffer = AjpParsingUnitTestCase.buffer.duplicate();
    HttpServerExchange result = new HttpServerExchange(null);
    final AjpRequestParseState state = new AjpRequestParseState();
    int limit = buffer.limit();
    for (int i = 1; i <= limit; ++i) {
        buffer.limit(i);
        AJP_REQUEST_PARSER.parse(buffer, state, result);
    }
    Assert.assertEquals(165, state.dataSize);
    Assert.assertTrue(state.isComplete());
    testResult(result);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) UnitTest(io.undertow.testutils.category.UnitTest)

Example 98 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class AjpParsingUnitTestCase method testCharsetHandling.

@Test
public void testCharsetHandling() throws Exception {
    ByteBuffer data = createAjpRequest("/hi".getBytes(StandardCharsets.UTF_8), "param=value".getBytes(StandardCharsets.UTF_8));
    HttpServerExchange result = new HttpServerExchange(null);
    AjpRequestParseState state = new AjpRequestParseState();
    AJP_REQUEST_PARSER.parse(data, state, result);
    Assert.assertFalse(state.badRequest);
    Assert.assertEquals("/hi", result.getRequestPath());
    Assert.assertEquals("/hi", result.getRequestURI());
    Assert.assertEquals("param=value", result.getQueryString());
    data = createAjpRequest("/한글이름".getBytes(StandardCharsets.UTF_8), "param=한글이름".getBytes(StandardCharsets.UTF_8));
    result = new HttpServerExchange(null);
    state = new AjpRequestParseState();
    AJP_REQUEST_PARSER.parse(data, state, result);
    Assert.assertFalse(state.badRequest);
    Assert.assertEquals("/한글이름", result.getRequestPath());
    Assert.assertEquals("/한글이름", result.getRequestURI());
    Assert.assertEquals("param=한글이름", result.getQueryString());
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test) UnitTest(io.undertow.testutils.category.UnitTest)

Example 99 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class AjpParsingUnitTestCase method testPathParamMatrixQueryString.

@Test
public void testPathParamMatrixQueryString() throws Exception {
    ByteBuffer data = createAjpRequest("/hi1;path1=param1;path2=param2/hi2;path3=param3/hi3/hi4/hi5;path4=param4;path5=param5/hi6".getBytes(StandardCharsets.UTF_8), "param=value".getBytes(StandardCharsets.UTF_8));
    HttpServerExchange result = new HttpServerExchange(null);
    AjpRequestParseState state = new AjpRequestParseState();
    AJP_REQUEST_PARSER.parse(data, state, result);
    Assert.assertFalse(state.badRequest);
    Assert.assertEquals("/hi1/hi2/hi3/hi4/hi5/hi6", result.getRequestPath());
    Assert.assertEquals("/hi1;path1=param1;path2=param2/hi2;path3=param3/hi3/hi4/hi5;path4=param4;path5=param5/hi6", result.getRequestURI());
    Assert.assertEquals("param=value", result.getQueryString());
    Map<String, Deque<String>> paramsMap = result.getPathParameters();
    Assert.assertNotNull(paramsMap);
    Assert.assertEquals(5, paramsMap.size());
    assertPathParamValue(paramsMap, "path1", "param1");
    assertPathParamValue(paramsMap, "path2", "param2");
    assertPathParamValue(paramsMap, "path3", "param3");
    assertPathParamValue(paramsMap, "path4", "param4");
    assertPathParamValue(paramsMap, "path5", "param5");
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) ByteBuffer(java.nio.ByteBuffer) Deque(java.util.Deque) Test(org.junit.Test) UnitTest(io.undertow.testutils.category.UnitTest)

Example 100 with HttpServerExchange

use of io.undertow.server.HttpServerExchange in project undertow by undertow-io.

the class ParserResumeTestCase method testOneCharacterAtATime.

@Test
public void testOneCharacterAtATime() throws BadRequestException {
    context.reset();
    byte[] in = DATA.getBytes();
    HttpServerExchange result = new HttpServerExchange(null);
    ByteBuffer buffer = ByteBuffer.wrap(in);
    int oldLimit = buffer.limit();
    buffer.limit(1);
    while (context.state != ParseState.PARSE_COMPLETE) {
        PARSER.handle(buffer, context, result);
        if (context.state != ParseState.PARSE_COMPLETE) {
            buffer.limit(buffer.limit() + 1);
        }
    }
    Assert.assertEquals(oldLimit, buffer.limit() + 4);
    runAssertions(result);
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) ByteBuffer(java.nio.ByteBuffer) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Aggregations

HttpServerExchange (io.undertow.server.HttpServerExchange)277 HttpHandler (io.undertow.server.HttpHandler)127 Test (org.junit.Test)109 IOException (java.io.IOException)90 UnitTest (io.undertow.testutils.category.UnitTest)45 BeforeClass (org.junit.BeforeClass)44 TestHttpClient (io.undertow.testutils.TestHttpClient)42 HttpGet (org.apache.http.client.methods.HttpGet)40 HttpResponse (org.apache.http.HttpResponse)37 HttpString (io.undertow.util.HttpString)36 Header (org.apache.http.Header)24 Undertow (io.undertow.Undertow)19 ByteBuffer (java.nio.ByteBuffer)19 SessionConfig (io.undertow.server.session.SessionConfig)16 Map (java.util.Map)16 Sender (io.undertow.io.Sender)15 ExchangeCompletionListener (io.undertow.server.ExchangeCompletionListener)14 HeaderMap (io.undertow.util.HeaderMap)13 URI (java.net.URI)13 HeaderValues (io.undertow.util.HeaderValues)12