Search in sources :

Example 11 with DefaultByteBufferPool

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

the class MimeDecodingTestCase method testBase64MimeDecodingWithSmallBuffers.

@Test
public void testBase64MimeDecodingWithSmallBuffers() throws IOException {
    final String data = fixLineEndings(FileUtils.readFile(MimeDecodingTestCase.class, "mime3.txt"));
    TestPartHandler handler = new TestPartHandler();
    MultipartParser.ParseState parser = MultipartParser.beginParse(new DefaultByteBufferPool(true, 6, 100, 0), handler, "unique-boundary-1".getBytes(), "ISO-8859-1");
    ByteBuffer buf = ByteBuffer.wrap(data.getBytes(StandardCharsets.UTF_8));
    parser.parse(buf);
    Assert.assertTrue(parser.isComplete());
    Assert.assertEquals(2, handler.parts.size());
    Assert.assertEquals("This is some base64 text.", handler.parts.get(0).data.toString());
    Assert.assertEquals("This is some more base64 text.", handler.parts.get(1).data.toString());
    Assert.assertEquals("text/plain", handler.parts.get(0).map.getFirst(Headers.CONTENT_TYPE));
}
Also used : DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) ByteBuffer(java.nio.ByteBuffer) UnitTest(io.undertow.testutils.category.UnitTest) Test(org.junit.Test)

Example 12 with DefaultByteBufferPool

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

the class AutobahnWebSocketServer 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());
        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)

Example 13 with DefaultByteBufferPool

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

the class ServletInitialHandler method dispatchMockRequest.

@Override
public void dispatchMockRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    final DefaultByteBufferPool bufferPool = new DefaultByteBufferPool(false, 1024, 0, 0);
    MockServerConnection connection = new MockServerConnection(bufferPool);
    HttpServerExchange exchange = new HttpServerExchange(connection);
    exchange.setRequestScheme(request.getScheme());
    exchange.setRequestMethod(new HttpString(request.getMethod()));
    exchange.setProtocol(Protocols.HTTP_1_0);
    exchange.setResolvedPath(request.getContextPath());
    String relative;
    if (request.getPathInfo() == null) {
        relative = request.getServletPath();
    } else {
        relative = request.getServletPath() + request.getPathInfo();
    }
    exchange.setRelativePath(relative);
    final ServletPathMatch info = paths.getServletHandlerByPath(request.getServletPath());
    final HttpServletResponseImpl oResponse = new HttpServletResponseImpl(exchange, servletContext);
    final HttpServletRequestImpl oRequest = new HttpServletRequestImpl(exchange, servletContext);
    final ServletRequestContext servletRequestContext = new ServletRequestContext(servletContext.getDeployment(), oRequest, oResponse, info);
    servletRequestContext.setServletRequest(request);
    servletRequestContext.setServletResponse(response);
    //set the max request size if applicable
    if (info.getServletChain().getManagedServlet().getMaxRequestSize() > 0) {
        exchange.setMaxEntitySize(info.getServletChain().getManagedServlet().getMaxRequestSize());
    }
    exchange.putAttachment(ServletRequestContext.ATTACHMENT_KEY, servletRequestContext);
    exchange.startBlocking(new ServletBlockingHttpExchange(exchange));
    servletRequestContext.setServletPathMatch(info);
    try {
        dispatchRequest(exchange, servletRequestContext, info.getServletChain(), DispatcherType.REQUEST);
    } catch (Exception e) {
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new ServletException(e);
    }
}
Also used : DefaultByteBufferPool(io.undertow.server.DefaultByteBufferPool) HttpString(io.undertow.util.HttpString) HttpServletResponseImpl(io.undertow.servlet.spec.HttpServletResponseImpl) ServletBlockingHttpExchange(io.undertow.servlet.core.ServletBlockingHttpExchange) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) HttpServerExchange(io.undertow.server.HttpServerExchange) ServletException(javax.servlet.ServletException) HttpServletRequestImpl(io.undertow.servlet.spec.HttpServletRequestImpl) HttpString(io.undertow.util.HttpString)

Aggregations

DefaultByteBufferPool (io.undertow.server.DefaultByteBufferPool)13 HttpOpenListener (io.undertow.server.protocol.http.HttpOpenListener)6 IOException (java.io.IOException)6 InetSocketAddress (java.net.InetSocketAddress)6 ChannelListener (org.xnio.ChannelListener)6 OptionMap (org.xnio.OptionMap)6 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)4 DeploymentManager (io.undertow.servlet.api.DeploymentManager)4 ServletContainer (io.undertow.servlet.api.ServletContainer)4 WebSocketDeploymentInfo (io.undertow.websockets.jsr.WebSocketDeploymentInfo)4 StreamConnection (org.xnio.StreamConnection)3 XnioWorker (org.xnio.XnioWorker)3 ByteBufferPool (io.undertow.connector.ByteBufferPool)2 FilterInfo (io.undertow.servlet.api.FilterInfo)2 PerMessageDeflateHandshake (io.undertow.websockets.extensions.PerMessageDeflateHandshake)2 ServletException (javax.servlet.ServletException)2 Xnio (org.xnio.Xnio)2 Undertow (io.undertow.Undertow)1 UndertowXnioSsl (io.undertow.protocols.ssl.UndertowXnioSsl)1 HttpHandler (io.undertow.server.HttpHandler)1