Package io.undertow.server

Examples of io.undertow.server.HttpHandler


            //because listeners can add other listeners
            ArrayList<Lifecycle> lifecycles = new ArrayList<Lifecycle>(deployment.getLifecycleObjects());
            for (Lifecycle object : lifecycles) {
                object.start();
            }
            HttpHandler root = deployment.getHandler();

            state = State.STARTED;
            return root;
        } finally {
            handle.tearDown();
View Full Code Here


            executor = servletContext.getDeployment().getExecutor();
        }

        if (exchange.isInIoThread() || executor != null) {
            //either the exchange has not been dispatched yet, or we need to use a special executor
            exchange.dispatch(executor, new HttpHandler() {
                @Override
                public void handleRequest(final HttpServerExchange exchange) throws Exception {
                    if(System.getSecurityManager() == null) {
                        dispatchRequest(exchange, servletRequestContext, info.getServletChain(), DispatcherType.REQUEST);
                    } else {
View Full Code Here

    private static volatile ServerConnection connection;

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

            @Override
            public void handleRequest(final HttpServerExchange exchange) throws Exception {
                if (connection == null) {
                    connection = exchange.getConnection();
View Full Code Here

public class PathTemplateHandlerTestCase {

    @BeforeClass
    public static void setup() {
        DefaultServer.setRootHandler(Handlers.pathTemplate()
                .add("/foo", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        exchange.getResponseSender().send("foo");
                    }
                })
                .add("/foo/{bar}", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        exchange.getResponseSender().send("foo-path" + exchange.getQueryParameters().get("bar"));
                    }
                }));
View Full Code Here

    public static void setupModCluster() {

        modCluster = ModCluster.builder(DefaultServer.getWorker(), undertowClient, xnioSsl).build();

        final int serverPort = getHostPort("default");
        final HttpHandler proxy = modCluster.getProxyHandler();
        final HttpHandler mcmp = MCMPConfig.webBuilder()
                .setManagementHost(getHostAddress("default"))
                .setManagementPort(serverPort)
                .create(modCluster, ResponseCodeHandler.HANDLE_404);

        DefaultServer.setRootHandler(path(proxy).addPrefixPath("manager", mcmp));
View Full Code Here

    @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);
                }
View Full Code Here

@RunWith(DefaultServer.class)
public class ExceptionHandlerTestCase {

    @Test
    public void testExceptionMappers() throws IOException {
        HttpHandler pathHandler = Handlers.path()
                .addExactPath("/", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        exchange.getResponseSender().send("expected");
                    }
                })
                .addExactPath("/exceptionParent", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        throw new ParentException();
                    }
                })
                .addExactPath("/exceptionChild", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        throw new ChildException();
                    }
                })
                .addExactPath("/exceptionAnotherChild", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        throw new AnotherChildException();
                    }
                })
                .addExactPath("/illegalArgumentException", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        throw new IllegalArgumentException();
                    }
                });

        HttpHandler exceptionHandler = Handlers.exceptionHandler(pathHandler)
                .addExceptionHandler(ChildException.class, new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        exchange.getResponseSender().send("child exception handled");
                    }
                })
                .addExceptionHandler(ParentException.class, new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        exchange.getResponseSender().send("parent exception handled");
                    }
                })
                .addExceptionHandler(Throwable.class, new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        exchange.getResponseSender().send("catch all throwables");
                    }
                });
View Full Code Here

        }
    }

    @Test
    public void testReThrowUnmatchedException() throws IOException {
        HttpHandler pathHandler = Handlers.path()
                .addExactPath("/", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        throw new IllegalArgumentException();
                    }
                });

        // intentionally not adding any exception handlers
        final HttpHandler exceptionHandler = Handlers.exceptionHandler(pathHandler);
        DefaultServer.setRootHandler(exceptionHandler);

        TestHttpClient client = new TestHttpClient();
        try {
            HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/");
View Full Code Here

        }
    }

    @Test
    public void testAttachException() throws IOException {
        HttpHandler pathHandler = Handlers.path()
                .addExactPath("/", new HttpHandler() {
                    @Override
                    public void handleRequest(HttpServerExchange exchange) throws Exception {
                        throw new IllegalArgumentException();
                    }
                });

        final HttpHandler exceptionHandler = Handlers.exceptionHandler(pathHandler)
            .addExceptionHandler(IllegalArgumentException.class, new HttpHandler() {
                @Override
                public void handleRequest(HttpServerExchange exchange) throws Exception {
                    exchange.getResponseSender().send("exception handled");
                }
            });

        DefaultServer.setRootHandler(new HttpHandler() {
            @Override
            public void handleRequest(HttpServerExchange exchange) throws Exception {
                Throwable throwable = exchange.getAttachment(ExceptionHandler.THROWABLE);
                Assert.assertNull(throwable);
                exceptionHandler.handleRequest(exchange);
                throwable = exchange.getAttachment(ExceptionHandler.THROWABLE);
                Assert.assertTrue(throwable instanceof IllegalArgumentException);
            }
        });
View Full Code Here

        TestHttpClient client = new TestHttpClient();
        client.setCookieStore(new BasicCookieStore());
        try {
            final SessionCookieConfig sessionConfig = new SessionCookieConfig();
            final SessionAttachmentHandler handler = new SessionAttachmentHandler(new InMemorySessionManager(""), sessionConfig);
            handler.setNext(new HttpHandler() {
                @Override
                public void handleRequest(final HttpServerExchange exchange) throws Exception {
                    final SessionManager manager = exchange.getAttachment(SessionManager.ATTACHMENT_KEY);
                    Session session = manager.getSession(exchange, sessionConfig);
                    if (session == null) {
View Full Code Here

TOP

Related Classes of io.undertow.server.HttpHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.