use of org.wildfly.extension.undertow.filters.FilterService in project wildfly by wildfly.
the class AbstractUndertowSubsystemTestCase method testRuntime.
public static void testRuntime(KernelServices mainServices, final String virtualHostName, int flag) throws Exception {
if (!mainServices.isSuccessfulBoot()) {
Throwable t = mainServices.getBootError();
Assert.fail("Boot unsuccessful: " + (t != null ? t.toString() : "no boot error provided"));
}
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(virtualHostName, "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());
if (flag == 1) {
Assert.assertEquals(3, host.getAllAliases().size());
Assert.assertEquals("default-alias", new ArrayList<>(host.getAllAliases()).get(1));
}
final ServiceName locationServiceName = UndertowService.locationServiceName(virtualHostName, "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(virtualHostName, "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);
}
use of org.wildfly.extension.undertow.filters.FilterService 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);
}
use of org.wildfly.extension.undertow.filters.FilterService 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());
}
use of org.wildfly.extension.undertow.filters.FilterService in project wildfly by wildfly.
the class UndertowSubsystem30TestCase 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);
}
use of org.wildfly.extension.undertow.filters.FilterService in project wildfly by wildfly.
the class UndertowSubsystem31TestCase 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);
}
Aggregations