Search in sources :

Example 76 with HttpHandler

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

the class HeadTestCase method setup.

@BeforeClass
public static void setup() {
    DefaultServer.setRootHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) throws Exception {
            if (connection == null) {
                connection = exchange.getConnection();
            } else if (!DefaultServer.isAjp() && !DefaultServer.isProxy() && connection != exchange.getConnection()) {
                Sender sender = exchange.getResponseSender();
                sender.send("Connection not persistent");
                return;
            }
            exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, message.length() + "");
            final Sender sender = exchange.getResponseSender();
            sender.send(message);
        }
    });
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) Sender(io.undertow.io.Sender) HttpHandler(io.undertow.server.HttpHandler) IOException(java.io.IOException) BeforeClass(org.junit.BeforeClass)

Example 77 with HttpHandler

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

the class HttpContinueAcceptingHandlerTestCase method setup.

@BeforeClass
public static void setup() {
    final BlockingHandler blockingHandler = new BlockingHandler();
    final HttpContinueAcceptingHandler handler = new HttpContinueAcceptingHandler(blockingHandler, new Predicate() {

        @Override
        public boolean resolve(HttpServerExchange value) {
            return accept;
        }
    });
    DefaultServer.setRootHandler(handler);
    blockingHandler.setRootHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) {
            try {
                byte[] buffer = new byte[1024];
                final ByteArrayOutputStream b = new ByteArrayOutputStream();
                int r = 0;
                final OutputStream outputStream = exchange.getOutputStream();
                final InputStream inputStream = exchange.getInputStream();
                while ((r = inputStream.read(buffer)) > 0) {
                    b.write(buffer, 0, r);
                }
                outputStream.write(b.toByteArray());
                outputStream.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Predicate(io.undertow.predicate.Predicate) BeforeClass(org.junit.BeforeClass)

Example 78 with HttpHandler

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

the class LongURLTestCase method setup.

@BeforeClass
public static void setup() {
    final BlockingHandler blockingHandler = new BlockingHandler();
    DefaultServer.setRootHandler(blockingHandler);
    blockingHandler.setRootHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) {
            exchange.getResponseSender().send(exchange.getRelativePath());
        }
    });
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) BeforeClass(org.junit.BeforeClass)

Example 79 with HttpHandler

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

the class LotsOfHeadersResponseTestCase method setup.

@BeforeClass
public static void setup() {
    final BlockingHandler blockingHandler = new BlockingHandler();
    DefaultServer.setRootHandler(blockingHandler);
    blockingHandler.setRootHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) {
            for (int i = 0; i < COUNT; ++i) {
                exchange.getResponseHeaders().put(HttpString.tryFromString(HEADER + i), MESSAGE + i);
            }
        }
    });
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) BeforeClass(org.junit.BeforeClass)

Example 80 with HttpHandler

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

the class LotsOfQueryParametersTestCase method setup.

@BeforeClass
public static void setup() {
    final BlockingHandler blockingHandler = new BlockingHandler();
    DefaultServer.setRootHandler(blockingHandler);
    blockingHandler.setRootHandler(new HttpHandler() {

        @Override
        public void handleRequest(final HttpServerExchange exchange) {
            for (Map.Entry<String, Deque<String>> entry : exchange.getQueryParameters().entrySet()) {
                exchange.getResponseHeaders().put(HttpString.tryFromString(entry.getKey()), entry.getValue().getFirst());
            }
        }
    });
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) HttpString(io.undertow.util.HttpString) BeforeClass(org.junit.BeforeClass)

Aggregations

HttpHandler (io.undertow.server.HttpHandler)126 HttpServerExchange (io.undertow.server.HttpServerExchange)72 IOException (java.io.IOException)54 BeforeClass (org.junit.BeforeClass)35 Test (org.junit.Test)25 TestHttpClient (io.undertow.testutils.TestHttpClient)20 HttpResponse (org.apache.http.HttpResponse)20 HttpGet (org.apache.http.client.methods.HttpGet)19 PathHandler (io.undertow.server.handlers.PathHandler)17 HttpString (io.undertow.util.HttpString)15 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)13 Undertow (io.undertow.Undertow)12 ArrayList (java.util.ArrayList)11 HandlerWrapper (io.undertow.server.HandlerWrapper)9 InMemorySessionManager (io.undertow.server.session.InMemorySessionManager)9 SessionAttachmentHandler (io.undertow.server.session.SessionAttachmentHandler)9 Header (org.apache.http.Header)9 SessionCookieConfig (io.undertow.server.session.SessionCookieConfig)8 AuthenticationMechanism (io.undertow.security.api.AuthenticationMechanism)7 AuthenticationCallHandler (io.undertow.security.handlers.AuthenticationCallHandler)7