Search in sources :

Example 11 with HttpHandler

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

the class UndertowSubsystem12TestCase method testCustomFilters.

private void testCustomFilters(KernelServices mainServices) {
    ServiceController<FilterService> customFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("custom-filter"));
    customFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = customFilter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
}
Also used : HttpHandler(io.undertow.server.HttpHandler) FilterService(org.wildfly.extension.undertow.filters.FilterService) PathHandler(io.undertow.server.handlers.PathHandler) ServiceController(org.jboss.msc.service.ServiceController)

Example 12 with HttpHandler

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

the class UndertowDeploymentService method startContext.

public void startContext() throws ServletException {
    final ClassLoader old = Thread.currentThread().getContextClassLoader();
    DeploymentInfo deploymentInfo = deploymentInfoInjectedValue.getValue();
    Thread.currentThread().setContextClassLoader(deploymentInfo.getClassLoader());
    try {
        StartupContext.setInjectionContainer(webInjectionContainer);
        try {
            deploymentManager = container.getValue().getServletContainer().addDeployment(deploymentInfo);
            deploymentManager.deploy();
            HttpHandler handler = deploymentManager.start();
            Deployment deployment = deploymentManager.getDeployment();
            host.getValue().registerDeployment(deployment, handler);
        } finally {
            StartupContext.setInjectionContainer(null);
        }
    } finally {
        Thread.currentThread().setContextClassLoader(old);
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) Deployment(io.undertow.servlet.api.Deployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 13 with HttpHandler

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

the class ModClusterService method createHttpHandler.

@Override
public HttpHandler createHttpHandler(Predicate predicate, final HttpHandler next) {
    //this is a bit of a hack at the moment. Basically we only want to create a single mod_cluster instance
    //not matter how many filter refs use it, also mod_cluster at this point has no way
    //to specify the next handler. To get around this we invoke the mod_proxy handler
    //and then if it has not dispatched or handled the request then we know that we can
    //just pass it on to the next handler
    final HttpHandler proxyHandler = modCluster.createProxyHandler(next);
    final HttpHandler realNext = new HttpHandler() {

        @Override
        public void handleRequest(HttpServerExchange exchange) throws Exception {
            proxyHandler.handleRequest(exchange);
            if (!exchange.isDispatched() && !exchange.isComplete()) {
                exchange.setStatusCode(200);
                next.handleRequest(exchange);
            }
        }
    };
    final HttpHandler mcmp = managementAccessPredicate != null ? Handlers.predicate(managementAccessPredicate, config.create(modCluster, realNext), next) : config.create(modCluster, realNext);
    UndertowLogger.ROOT_LOGGER.debug("HttpHandler for mod_cluster MCMP created.");
    if (predicate != null) {
        return new PredicateHandler(predicate, mcmp, next);
    } else {
        return mcmp;
    }
}
Also used : HttpServerExchange(io.undertow.server.HttpServerExchange) HttpHandler(io.undertow.server.HttpHandler) PredicateHandler(io.undertow.server.handlers.PredicateHandler)

Example 14 with HttpHandler

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

the class Filter method createHttpHandler.

public HttpHandler createHttpHandler(final Predicate predicate, final ModelNode model, HttpHandler next) {
    List<AttributeDefinition> attributes = new ArrayList<>(getAttributes());
    HttpHandler handler = createHandler(getHandlerClass(), model, attributes, next);
    if (predicate != null) {
        return Handlers.predicate(predicate, handler, next);
    } else {
        return handler;
    }
}
Also used : HttpHandler(io.undertow.server.HttpHandler) ArrayList(java.util.ArrayList) AttributeDefinition(org.jboss.as.controller.AttributeDefinition)

Example 15 with HttpHandler

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

the class UndertowSubsystem31TestCase method testRuntime.

@Test
public void testRuntime() throws Exception {
    System.setProperty("server.data.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.home.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.home.dir", System.getProperty("java.io.tmpdir"));
    System.setProperty("jboss.server.server.dir", System.getProperty("java.io.tmpdir"));
    KernelServicesBuilder builder = createKernelServicesBuilder(RUNTIME).setSubsystemXml(getSubsystemXml());
    KernelServices mainServices = builder.build();
    if (!mainServices.isSuccessfulBoot()) {
        Assert.fail(mainServices.getBootError().toString());
    }
    ServiceController<FilterService> connectionLimiter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("limit-connections"));
    connectionLimiter.setMode(ServiceController.Mode.ACTIVE);
    FilterService connectionLimiterService = connectionLimiter.getService().getValue();
    HttpHandler result = connectionLimiterService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", result);
    ServiceController<FilterService> headersFilter = (ServiceController<FilterService>) mainServices.getContainer().getService(UndertowService.FILTER.append("headers"));
    headersFilter.setMode(ServiceController.Mode.ACTIVE);
    FilterService headersService = headersFilter.getService().getValue();
    HttpHandler headerHandler = headersService.createHttpHandler(Predicates.truePredicate(), new PathHandler());
    Assert.assertNotNull("handler should have been created", headerHandler);
    final ServiceName hostServiceName = UndertowService.virtualHostName("some-server", "other-host");
    ServiceController<Host> hostSC = (ServiceController<Host>) mainServices.getContainer().getService(hostServiceName);
    Assert.assertNotNull(hostSC);
    hostSC.setMode(ServiceController.Mode.ACTIVE);
    Host host = hostSC.getValue();
    Assert.assertEquals(1, host.getFilters().size());
    Assert.assertEquals(3, host.getAllAliases().size());
    Assert.assertEquals("default-alias", new ArrayList<>(host.getAllAliases()).get(1));
    final ServiceName locationServiceName = UndertowService.locationServiceName("some-server", "default-host", "/");
    ServiceController<LocationService> locationSC = (ServiceController<LocationService>) mainServices.getContainer().getService(locationServiceName);
    Assert.assertNotNull(locationSC);
    locationSC.setMode(ServiceController.Mode.ACTIVE);
    LocationService locationService = locationSC.getValue();
    Assert.assertNotNull(locationService);
    connectionLimiter.setMode(ServiceController.Mode.REMOVE);
    final ServiceName jspServiceName = UndertowService.SERVLET_CONTAINER.append("myContainer");
    ServiceController<ServletContainerService> jspServiceServiceController = (ServiceController<ServletContainerService>) mainServices.getContainer().getService(jspServiceName);
    Assert.assertNotNull(jspServiceServiceController);
    JSPConfig jspConfig = jspServiceServiceController.getService().getValue().getJspConfig();
    Assert.assertNotNull(jspConfig);
    Assert.assertNotNull(jspConfig.createJSPServletInfo());
    final ServiceName filterRefName = UndertowService.filterRefName("some-server", "other-host", "/", "static-gzip");
    ServiceController<FilterRef> gzipFilterController = (ServiceController<FilterRef>) mainServices.getContainer().getService(filterRefName);
    gzipFilterController.setMode(ServiceController.Mode.ACTIVE);
    FilterRef gzipFilterRef = gzipFilterController.getService().getValue();
    HttpHandler gzipHandler = gzipFilterRef.createHttpHandler(new PathHandler());
    Assert.assertNotNull("handler should have been created", gzipHandler);
    //testCustomFilters(mainServices);
    ServiceController<Host> defaultHostSC = (ServiceController<Host>) mainServices.getContainer().getService(UndertowService.DEFAULT_HOST);
    defaultHostSC.setMode(ServiceController.Mode.ACTIVE);
    Host defaultHost = defaultHostSC.getValue();
    Assert.assertNotNull("Default host should exist", defaultHost);
    ServiceController<Server> defaultServerSC = (ServiceController<Server>) mainServices.getContainer().getService(UndertowService.DEFAULT_SERVER);
    defaultServerSC.setMode(ServiceController.Mode.ACTIVE);
    Server defaultServer = defaultServerSC.getValue();
    Assert.assertNotNull("Default host should exist", defaultServer);
    final ServiceName accessLogServiceName = UndertowService.accessLogServiceName("some-server", "default-host");
    ServiceController<AccessLogService> accessLogSC = (ServiceController<AccessLogService>) mainServices.getContainer().getService(accessLogServiceName);
    Assert.assertNotNull(accessLogSC);
    accessLogSC.setMode(ServiceController.Mode.ACTIVE);
    AccessLogService accessLogService = accessLogSC.getValue();
    Assert.assertNotNull(accessLogService);
    Assert.assertFalse(accessLogService.isRotate());
}
Also used : HttpHandler(io.undertow.server.HttpHandler) KernelServices(org.jboss.as.subsystem.test.KernelServices) FilterService(org.wildfly.extension.undertow.filters.FilterService) ArrayList(java.util.ArrayList) PathHandler(io.undertow.server.handlers.PathHandler) FilterRef(org.wildfly.extension.undertow.filters.FilterRef) ServiceName(org.jboss.msc.service.ServiceName) ServiceController(org.jboss.msc.service.ServiceController) KernelServicesBuilder(org.jboss.as.subsystem.test.KernelServicesBuilder) AbstractSubsystemBaseTest(org.jboss.as.subsystem.test.AbstractSubsystemBaseTest) Test(org.junit.Test)

Aggregations

HttpHandler (io.undertow.server.HttpHandler)117 HttpServerExchange (io.undertow.server.HttpServerExchange)71 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)16 HttpString (io.undertow.util.HttpString)14 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)11 ArrayList (java.util.ArrayList)11 Undertow (io.undertow.Undertow)10 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 OutputStream (java.io.OutputStream)7 ServiceController (org.jboss.msc.service.ServiceController)7