io.undertow.servlet.api.FilterInfo Java Examples

The following examples show how to use io.undertow.servlet.api.FilterInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public FilterRegistration.Dynamic addFilter(final String filterName, final Class<? extends Filter> filterClass) {
    ensureNotProgramaticListener();
    ensureNotInitialized();
    if (deploymentInfo.getFilters().containsKey(filterName)) {
        return null;
    }
    try {
        FilterInfo filter = new FilterInfo(filterName, filterClass,deploymentInfo.getClassIntrospecter().createInstanceFactory(filterClass));
        deploymentInfo.addFilter(filter);
        deployment.getFilters().addFilter(filter);
        return new FilterRegistrationImpl(filter, deployment, this);
    } catch (NoSuchMethodException e) {
        throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(filterClass.getName(),e);
    }
}
 
Example #2
Source File: SparkBenchmarks.java    From brave with Apache License 2.0 6 votes vote down vote up
@Override protected void init(DeploymentInfo servletBuilder) {
  servletBuilder
    .addFilter(new FilterInfo("NotTraced", SparkFilter.class)
      .addInitParam("applicationClass", NotTraced.class.getName()))
    .addFilterUrlMapping("NotTraced", "/*", REQUEST)
    .addFilter(new FilterInfo("Unsampled", SparkFilter.class)
      .addInitParam("applicationClass", Unsampled.class.getName()))
    .addFilterUrlMapping("Unsampled", "/unsampled", REQUEST)
    .addFilter(new FilterInfo("Traced", SparkFilter.class)
      .addInitParam("applicationClass", Traced.class.getName()))
    .addFilterUrlMapping("Traced", "/traced", REQUEST)
    .addFilter(new FilterInfo("TracedBaggage", SparkFilter.class)
      .addInitParam("applicationClass", TracedBaggage.class.getName()))
    .addFilterUrlMapping("TracedBaggage", "/tracedBaggage", REQUEST)
    .addFilter(new FilterInfo("Traced128", SparkFilter.class)
      .addInitParam("applicationClass", Traced128.class.getName()))
    .addFilterUrlMapping("Traced128", "/traced128", REQUEST);
}
 
Example #3
Source File: EndToEndBenchmarks.java    From brave with Apache License 2.0 6 votes vote down vote up
@Override protected void init(DeploymentInfo servletBuilder) {
  servletBuilder.addFilter(new FilterInfo("Unsampled", Unsampled.class))
    .addFilterUrlMapping("Unsampled", "/unsampled", REQUEST)
    .addFilterUrlMapping("Unsampled", "/unsampled/api", REQUEST)
    .addFilter(new FilterInfo("OnlySampledLocal", OnlySampledLocal.class))
    .addFilterUrlMapping("OnlySampledLocal", "/onlysampledlocal", REQUEST)
    .addFilterUrlMapping("OnlySampledLocal", "/onlysampledlocal/api", REQUEST)
    .addFilter(new FilterInfo("Traced", Traced.class))
    .addFilterUrlMapping("Traced", "/traced", REQUEST)
    .addFilterUrlMapping("Traced", "/traced/api", REQUEST)
    .addFilter(new FilterInfo("TracedBaggage", TracedBaggage.class))
    .addFilterUrlMapping("TracedBaggage", "/tracedBaggage", REQUEST)
    .addFilterUrlMapping("TracedBaggage", "/tracedBaggage/api", REQUEST)
    .addFilter(new FilterInfo("TracedCorrelated", TracedCorrelated.class))
    .addFilterUrlMapping("TracedCorrelated", "/tracedcorrelated", REQUEST)
    .addFilterUrlMapping("TracedCorrelated", "/tracedcorrelated/api", REQUEST)
    .addFilter(new FilterInfo("Traced128", Traced128.class))
    .addFilterUrlMapping("Traced128", "/traced128", REQUEST)
    .addFilterUrlMapping("Traced128", "/traced128/api", REQUEST)
    .addServlets(Servlets.servlet("HelloServlet", HelloServlet.class).addMapping("/*"));
}
 
Example #4
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public FilterRegistration.Dynamic addFilter(final String filterName, final Class<? extends Filter> filterClass) {
    ensureNotProgramaticListener();
    ensureNotInitialized();
    if (deploymentInfo.getFilters().containsKey(filterName)) {
        return null;
    }
    try {
        FilterInfo filter = new FilterInfo(filterName, filterClass,deploymentInfo.getClassIntrospecter().createInstanceFactory(filterClass));
        deploymentInfo.addFilter(filter);
        deployment.getFilters().addFilter(filter);
        return new FilterRegistrationImpl(filter, deployment, this);
    } catch (NoSuchMethodException e) {
        throw UndertowServletMessages.MESSAGES.couldNotCreateFactory(filterClass.getName(),e);
    }
}
 
Example #5
Source File: JsrWebSocketServerTest.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
private ServletContext deployServlet(final ServerWebSocketContainer deployment) throws ServletException {

        final DeploymentInfo builder;
        builder = new DeploymentInfo()
                .setClassLoader(getClass().getClassLoader())
                .setContextPath("/")
                .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                .setDeploymentName("websocket.war")
                .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class))
                .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST)
                .addServletContextAttribute(javax.websocket.server.ServerContainer.class.getName(), deployment);

        final PathHandler root = new PathHandler();
        final ServletContainer container = ServletContainer.Factory.newInstance();
        DeploymentManager manager = container.addDeployment(builder);
        manager.deploy();
        root.addPrefixPath(builder.getContextPath(), manager.start());

        DefaultServer.setRootHandler(root);
        return manager.getDeployment().getServletContext();
    }
 
Example #6
Source File: EagerServletLifecycleTestCase.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Test
public void testServletLifecycle() throws Exception {


    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);

    DeploymentInfo builder = new DeploymentInfo()
            .setClassLoader(EagerServletLifecycleTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setEagerFilterInit(true)
            .addFilter(f)
            .addFilterUrlMapping("filter", "/aa", DispatcherType.REQUEST);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);

    Assert.assertTrue(LifecycleFilter.initCalled);
}
 
Example #7
Source File: LifecyleInterceptorInvocation.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, FilterInfo filterInfo, Filter filter) {
    this.list = list;
    this.servlet = null;
    this.servletConfig = null;
    this.filter = filter;
    this.filterConfig = null;
    this.filterInfo = filterInfo;
    this.servletInfo = null;
    i = list.size();
}
 
Example #8
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
    ensureNotProgramaticListener();
    final Map<String, FilterRegistration> ret = new HashMap<>();
    for (Map.Entry<String, FilterInfo> entry : deploymentInfo.getFilters().entrySet()) {
        ret.put(entry.getKey(), new FilterRegistrationImpl(entry.getValue(), deployment, this));
    }
    return ret;
}
 
Example #9
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FilterRegistration getFilterRegistration(final String filterName) {
    ensureNotProgramaticListener();
    final FilterInfo filterInfo = deploymentInfo.getFilters().get(filterName);
    if (filterInfo == null) {
        return null;
    }
    return new FilterRegistrationImpl(filterInfo, deployment, this);
}
 
Example #10
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, ? extends FilterRegistration> getFilterRegistrations() {
    ensureNotProgramaticListener();
    final Map<String, FilterRegistration> ret = new HashMap<>();
    for (Map.Entry<String, FilterInfo> entry : deploymentInfo.getFilters().entrySet()) {
        ret.put(entry.getKey(), new FilterRegistrationImpl(entry.getValue(), deployment, this));
    }
    return ret;
}
 
Example #11
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public FilterRegistration.Dynamic addFilter(final String filterName, final Filter filter) {
    ensureNotProgramaticListener();
    ensureNotInitialized();

    if (deploymentInfo.getFilters().containsKey(filterName)) {
        return null;
    }
    FilterInfo f = new FilterInfo(filterName, filter.getClass(), new ImmediateInstanceFactory<>(filter));
    deploymentInfo.addFilter(f);
    deployment.getFilters().addFilter(f);
    return new FilterRegistrationImpl(f, deployment, this);

}
 
Example #12
Source File: Main.java    From zooadmin with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    DeploymentInfo servletBuilder = Servlets.deployment()
            .setContextPath("/")
            .setClassLoader(Main.class.getClassLoader())
            .setDeploymentName("zooadmin.war")
            ;
    Integer port= PropUtil.getInt("port");
    String host=PropUtil.getString("host");
    String resource=PropUtil.getString("resource");
    FilterInfo jfinalFilter=new FilterInfo("jfinal",JFinalFilter.class);
    jfinalFilter.addInitParam("configClass","com.baicai.core.Config");
    servletBuilder.addFilter(jfinalFilter);
    servletBuilder.addFilterUrlMapping("jfinal","/*", DispatcherType.REQUEST);
    servletBuilder.addFilterUrlMapping("jfinal","/*", DispatcherType.FORWARD);
    servletBuilder.setResourceManager(new FileResourceManager(new File(resource), 1024));


    DeploymentManager manager = Servlets.defaultContainer().addDeployment(servletBuilder);
    manager.deploy();
    PathHandler path = Handlers.path(Handlers.redirect("/"))
           .addPrefixPath("/", manager.start());
    Undertow server = Undertow.builder()
            .addHttpListener(port, host)
            .setHandler(path)
            .build();
    // start server
    server.start();
    log.info("http://"+host+":"+port);
}
 
Example #13
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<FilterInfo> registerFilter(RuntimeValue<DeploymentInfo> info,
        String name, Class<?> filterClass,
        boolean asyncSupported,
        BeanContainer beanContainer,
        InstanceFactory<? extends Filter> instanceFactory) throws Exception {

    InstanceFactory<? extends Filter> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(filterClass));
    FilterInfo filterInfo = new FilterInfo(name, (Class<? extends Filter>) filterClass, factory);
    info.getValue().addFilter(filterInfo);
    filterInfo.setAsyncSupported(asyncSupported);
    return new RuntimeValue<>(filterInfo);
}
 
Example #14
Source File: AnnotatedAutobahnServer.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public void run() {


        try {
            final ServletContainer container = ServletContainer.Factory.newInstance();

            DeploymentInfo builder = new DeploymentInfo()
                    .setClassLoader(AnnotatedAutobahnServer.class.getClassLoader())
                    .setContextPath("/")
                    .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                    .setDeploymentName("servletContext.war")
                    .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME,
                            new WebSocketDeploymentInfo()
                                    .addEndpoint(AutobahnAnnotatedEndpoint.class)
                                    .setDispatchToWorkerThread(true)
                    )
                    .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class))
                    .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST);

            DeploymentManager manager = container.addDeployment(builder);
            manager.deploy();

            Undertow.builder().addHttpListener(port, "localhost")
                    .setHandler(manager.start())
                    .build();

        } catch (Exception e) {
            log.error("failed to start server", e);
        }
    }
 
Example #15
Source File: ProgramaticAutobahnServer.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public void run() {

        try {

            final ServletContainer container = ServletContainer.Factory.newInstance();
            DeploymentInfo builder = new DeploymentInfo()
                    .setClassLoader(ProgramaticAutobahnServer.class.getClassLoader())
                    .setContextPath("/")
                    .setClassIntrospecter(TestClassIntrospector.INSTANCE)
                    .setDeploymentName("servletContext.war")
                    .addFilter(new FilterInfo("filter", JsrWebSocketFilter.class))
                    .addFilterUrlMapping("filter", "/*", DispatcherType.REQUEST)

                    .addServletContextAttribute(WebSocketDeploymentInfo.ATTRIBUTE_NAME,
                            new WebSocketDeploymentInfo()
                                    .setDispatchToWorkerThread(true)
                                    .addEndpoint(new ServerEndpointConfigImpl(ProgramaticAutobahnEndpoint.class, "/"))
                    );

            DeploymentManager manager = container.addDeployment(builder);
            manager.deploy();


            Undertow.builder().addHttpListener(port, "localhost")
                    .setHandler(manager.start())
                    .build();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
 
Example #16
Source File: FilterPathMappingTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Test
public void test_WFLY_1935() throws IOException, ServletException {

    DeploymentInfo builder = new DeploymentInfo();

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    builder.addServlet(new ServletInfo("*.a", PathMappingServlet.class)
            .addMapping("*.a"));

    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);

    //non standard, but we still support it
    builder.addFilter(new FilterInfo("/SimpleServlet.a", PathFilter.class));
    builder.addFilterUrlMapping("/SimpleServlet.a", "/SimpleServlet.a", DispatcherType.REQUEST);

    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(FilterPathMappingTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war");

    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);


    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "SimpleServlet.a", "*.a - /SimpleServlet.a - null", "/*", "/SimpleServlet.a");

    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
Example #17
Source File: FilterPathMappingTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Test
public void testExtensionMatchServletWithGlobalFilter() throws IOException, ServletException {

    DeploymentInfo builder = new DeploymentInfo();

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class)
            .addMapping("*.jsp"));

    builder.addFilter(new FilterInfo("/*", PathFilter.class));
    builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST);

    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(FilterPathMappingTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war");

    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);


    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "aa.jsp", "*.jsp - /aa.jsp - null", "/*");

    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
Example #18
Source File: LifecyleInterceptorInvocation.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, FilterInfo filterInfo, Filter filter,  FilterConfig filterConfig) {
    this.list = list;
    this.servlet = null;
    this.servletConfig = null;
    this.filter = filter;
    this.filterConfig = filterConfig;
    this.filterInfo = filterInfo;
    this.servletInfo = null;
    i = list.size();
}
 
Example #19
Source File: AbstractResponseWrapperTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws ServletException {
    DeploymentInfo builder = new DeploymentInfo();
    builder.setExceptionHandler(LoggingExceptionHandler.builder().add(IllegalArgumentException.class, "io.undertow", Logger.Level.DEBUG).build());

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    builder.addServlet(new ServletInfo("wrapperServlet", WrapperServlet.class)
            .addMapping("/*"));


    builder.addFilter(new FilterInfo("standard", StandardRequestWrappingFilter.class));
    builder.addFilterUrlMapping("standard", "/standard", DispatcherType.REQUEST);

    builder.addFilter(new FilterInfo("nonstandard", NonStandardRequestWrappingFilter.class));
    builder.addFilterUrlMapping("nonstandard", "/nonstandard", DispatcherType.REQUEST);

    builder.setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(AbstractResponseWrapperTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setAllowNonStandardWrappers(isNonStandardAllowed());

    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #20
Source File: DefaultServletTestCase.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws ServletException {

    final PathHandler root = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();

    DeploymentInfo builder = new DeploymentInfo()
            .setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setClassLoader(ServletPathMappingTestCase.class.getClassLoader())
            .setContextPath("/servletContext")
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(DefaultServletTestCase.class));

    builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class)
            .addMapping("/path/default"));

    builder.addServlet(new ServletInfo("default", DefaultServlet.class)
            .addInitParam("directory-listing", "true")
            .addMapping("/*"));

    //see UNDERTOW-458
    builder.addFilter(new FilterInfo("date-header", GetDateFilter.class));
    builder.addFilterUrlMapping("date-header", "/*", DispatcherType.REQUEST);


    builder.addFilter(new FilterInfo("Filter", HelloFilter.class));
    builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST);

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);
}
 
Example #21
Source File: ManagedFilters.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public ManagedFilter addFilter(final FilterInfo filterInfo) {
    ManagedFilter managedFilter = new ManagedFilter(filterInfo, deployment.getServletContext());
    managedFilterMap.put(filterInfo.getName(),managedFilter);
    deployment.addLifecycleObjects(managedFilter);
    servletPathMatches.invalidate();
    return managedFilter;
}
 
Example #22
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public FilterRegistration.Dynamic addFilter(final String filterName, final Filter filter) {
    ensureNotProgramaticListener();
    ensureNotInitialized();

    if (deploymentInfo.getFilters().containsKey(filterName)) {
        return null;
    }
    FilterInfo f = new FilterInfo(filterName, filter.getClass(), new ImmediateInstanceFactory<>(filter));
    deploymentInfo.addFilter(f);
    deployment.getFilters().addFilter(f);
    return new FilterRegistrationImpl(f, deployment, this);

}
 
Example #23
Source File: ServletBenchmarks.java    From brave with Apache License 2.0 5 votes vote down vote up
public static void addFilterMappings(DeploymentInfo servletBuilder) {
  servletBuilder.addFilter(new FilterInfo("Unsampled", Unsampled.class))
    .addFilterUrlMapping("Unsampled", "/unsampled", REQUEST)
    .addFilter(new FilterInfo("Traced", Traced.class))
    .addFilterUrlMapping("Traced", "/traced", REQUEST)
    .addFilter(new FilterInfo("TracedBaggage", TracedBaggage.class))
    .addFilterUrlMapping("TracedBaggage", "/tracedBaggage", REQUEST)
    .addFilter(new FilterInfo("Traced128", Traced128.class))
    .addFilterUrlMapping("Traced128", "/traced128", REQUEST);
}
 
Example #24
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public FilterRegistration getFilterRegistration(final String filterName) {
    ensureNotProgramaticListener();
    final FilterInfo filterInfo = deploymentInfo.getFilters().get(filterName);
    if (filterInfo == null) {
        return null;
    }
    return new FilterRegistrationImpl(filterInfo, deployment, this);
}
 
Example #25
Source File: LifecyleInterceptorInvocation.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, FilterInfo filterInfo, Filter filter,  FilterConfig filterConfig) {
    this.list = list;
    this.servlet = null;
    this.servletConfig = null;
    this.filter = filter;
    this.filterConfig = filterConfig;
    this.filterInfo = filterInfo;
    this.servletInfo = null;
    i = list.size();
}
 
Example #26
Source File: LifecyleInterceptorInvocation.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
LifecyleInterceptorInvocation(List<LifecycleInterceptor> list, FilterInfo filterInfo, Filter filter) {
    this.list = list;
    this.servlet = null;
    this.servletConfig = null;
    this.filter = filter;
    this.filterConfig = null;
    this.filterInfo = filterInfo;
    this.servletInfo = null;
    i = list.size();
}
 
Example #27
Source File: DeploymentManagerImpl.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private void createServletsAndFilters(final DeploymentImpl deployment, final DeploymentInfo deploymentInfo) {
    for (Map.Entry<String, ServletInfo> servlet : deploymentInfo.getServlets().entrySet()) {
        deployment.getServlets().addServlet(servlet.getValue());
    }
    for (Map.Entry<String, FilterInfo> filter : deploymentInfo.getFilters().entrySet()) {
        deployment.getFilters().addFilter(filter.getValue());
    }
}
 
Example #28
Source File: DeploymentManagerImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void createServletsAndFilters(final DeploymentImpl deployment, final DeploymentInfo deploymentInfo) {
    for (Map.Entry<String, ServletInfo> servlet : deploymentInfo.getServlets().entrySet()) {
        deployment.getServlets().addServlet(servlet.getValue());
    }
    for (Map.Entry<String, FilterInfo> filter : deploymentInfo.getFilters().entrySet()) {
        deployment.getFilters().addFilter(filter.getValue());
    }
}
 
Example #29
Source File: KeycloakOnUndertow.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private DeploymentInfo createAuthServerDeploymentInfo() {
    ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplicationClass(KeycloakApplication.class.getName());

    // RESTEASY-2034
    deployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, true);

    DeploymentInfo di = undertow.undertowDeployment(deployment);
    di.setClassLoader(getClass().getClassLoader());
    di.setContextPath("/auth");
    di.setDeploymentName("Keycloak");
    if (configuration.getKeycloakConfigPropertyOverridesMap() != null) {
        try {
            di.addInitParameter(JsonConfigProviderFactory.SERVER_CONTEXT_CONFIG_PROPERTY_OVERRIDES,
              JsonSerialization.writeValueAsString(configuration.getKeycloakConfigPropertyOverridesMap()));
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }

    di.setDefaultServletConfig(new DefaultServletConfig(true));
    di.addWelcomePage("theme/keycloak/welcome/resources/index.html");

    FilterInfo filter = Servlets.filter("SessionFilter", TestKeycloakSessionServletFilter.class);
    di.addFilter(filter);
    di.addFilterUrlMapping("SessionFilter", "/*", DispatcherType.REQUEST);
    filter.setAsyncSupported(true);

    return di;
}
 
Example #30
Source File: UndertowServer.java    From pippo with Apache License 2.0 5 votes vote down vote up
private void addPippoFilter(DeploymentInfo info) {
    if (pippoFilterPath == null) {
        pippoFilterPath = "/*"; // default value
    }

    info.addFilter(new FilterInfo("PippoFilter", PippoFilter.class, new ImmediateInstanceFactory<>(getPippoFilter())));
    info.addFilterUrlMapping("PippoFilter", pippoFilterPath, DispatcherType.REQUEST);
    log.debug("Using pippo filter for path '{}'", pippoFilterPath);
}