Example usage for javax.servlet DispatcherType REQUEST

List of usage examples for javax.servlet DispatcherType REQUEST

Introduction

In this page you can find the example usage for javax.servlet DispatcherType REQUEST.

Prototype

DispatcherType REQUEST

To view the source code for javax.servlet DispatcherType REQUEST.

Click Source Link

Usage

From source file:com.indeed.imhotep.web.config.WebApp.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    if (WebApp.started) {
        return; // avoid double initialization when a subclass exists
    }//  ww  w .jav  a 2s .  co m
    WebApp.started = true;

    initWebapp(servletContext);

    initCharacterEncodingFilter(servletContext);

    super.onStartup(servletContext);

    FilterRegistration.Dynamic noCacheFilter = servletContext.addFilter("nocache", NoCacheFilter.class);
    noCacheFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*");

    cleanupTempFiles();
}

From source file:io.undertow.servlet.test.lifecycle.ServletLifecycleTestCase.java

@Test
public void testServletLifecycle() throws Exception {

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

    ServletInfo s = new ServletInfo("servlet", LifeCycleServlet.class).addMapping("/aa");
    FilterInfo f = new FilterInfo("filter", LifecycleFilter.class);

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

    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();/*from  ww  w. j ava2 s  .  c o m*/
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);

    TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/aa");
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        final String response = HttpClientUtils.readResponse(result);

        manager.stop();
        manager.undeploy();

        Assert.assertTrue(LifeCycleServlet.initCalled);
        Assert.assertTrue(LifeCycleServlet.destroyCalled);
        Assert.assertTrue(LifecycleFilter.initCalled);
        Assert.assertTrue(LifecycleFilter.destroyCalled);

    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:io.undertow.servlet.test.request.RequestPathTestCase.java

@BeforeClass
public static void setup() throws ServletException {

    final PathHandler pathHandler = new PathHandler();
    final ServletContainer container = ServletContainer.Factory.newInstance();
    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .addServlets(new ServletInfo("request", RequestPathServlet.class).addMapping("/req/*"),
                    new ServletInfo("DefaultServlet", RequestPathServlet.class).addMapping("/"),
                    new ServletInfo("ExactServlet", RequestPathServlet.class).addMapping("/exact"),
                    new ServletInfo("ExactTxtServlet", RequestPathServlet.class).addMapping("/exact.txt"),
                    new ServletInfo("HtmlServlet", RequestPathServlet.class).addMapping("*.html"))
            .addFilters(//w w  w  .jav  a  2s . c o m
                    new FilterInfo("header", SetHeaderFilter.class).addInitParam("header", "Filter")
                            .addInitParam("value", "true"),
                    new FilterInfo("all", SetHeaderFilter.class).addInitParam("header", "all")
                            .addInitParam("value", "true"))
            .addFilterUrlMapping("header", "*.txt", DispatcherType.REQUEST)
            .addFilterUrlMapping("all", "/*", DispatcherType.REQUEST);
    DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();
    try {
        pathHandler.addPrefixPath(builder.getContextPath(), manager.start());
    } catch (ServletException e) {
        throw new RuntimeException(e);
    }
    DefaultServer.setRootHandler(pathHandler);

}

From source file:fr.treeptik.cloudunit.initializer.ApplicationConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(CloudUnitApplicationContext.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);//from w  w  w. j  a  v a2s.com
    dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);
    dispatcher.setAsyncSupported(true);

    FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain",
            new DelegatingFilterProxy());
    EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
            DispatcherType.ASYNC);

    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/nopublic/*");

    security.setAsyncSupported(true);

    servletContext.addListener(new ContextLoaderListener(rootContext));
}

From source file:cn.org.once.cstack.initializer.ApplicationConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(CloudUnitApplicationContext.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME,
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);//w  ww .ja  v a2 s. co m
    dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);
    dispatcher.setAsyncSupported(true);

    FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain",
            new DelegatingFilterProxy());
    EnumSet<DispatcherType> securityDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
            DispatcherType.ASYNC);

    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/user/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/file/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/logs/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/messages/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/application/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/server/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/snapshot/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/module/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/admin/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/image/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/scripting/*");
    security.addMappingForUrlPatterns(securityDispatcherTypes, false, "/gitlab/*");

    security.setAsyncSupported(true);

    servletContext.addListener(new ContextLoaderListener(rootContext));

}

From source file:com.github.sshw.config.RootApplicationConfig.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(RootApplicationContext.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);/*from w  w  w. j  av a  2 s . c  o m*/
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain",
            new DelegatingFilterProxy());
    security.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    servletContext.addListener(new ContextLoaderListener(rootContext));
}

From source file:com.rakesh.rp3599.config.WebAppInitializer.java

public void onStartup(ServletContext container) throws ServletException {

    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(AppContext.class);

    /** Dispatcher Servlet **/
    ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher",
            new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);//from  w w  w. j a v a 2 s  .c  om
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");

    /** Dispatcher Types Enum **/
    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    /** UTF-8 Filter **/
    FilterRegistration.Dynamic characterEncoding = container.addFilter("characterEncoding",
            characterEncodingFilter);
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    /** Context Listener **/
    container.addListener(new ContextLoaderListener(rootContext));

}

From source file:org.ameba.http.MultiTenancyConfiguration.java

/**
 * Registers the SLF4JMappedDiagnosticContextFilter filter.
 *
 * @return The registration bean instance
 *///  www .j  av a  2s . c  o m
public @Bean FilterRegistrationBean slf4JMappedDiagnosticContextFilter() {
    FilterRegistrationBean registration = new FilterRegistrationBean(new SLF4JMappedDiagnosticContextFilter());
    registration.setDispatcherTypes(DispatcherType.REQUEST);
    registration.addInitParameter(org.ameba.Constants.PARAM_MULTI_TENANCY_ENABLED, String.valueOf(enabled));
    registration.addInitParameter(org.ameba.Constants.PARAM_MULTI_TENANCY_THROW_IF_NOT_PRESENT,
            String.valueOf(throwIfNotPresent));
    return registration;
}

From source file:net.rgielen.actionframeworks.struts2.ApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(ApplicationConfig.class);
    servletContext.addListener(new ContextLoaderListener(context));

    CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
    characterEncodingFilter.setEncoding("UTF-8");
    characterEncodingFilter.setForceEncoding(true);

    EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);

    FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding",
            characterEncodingFilter);/*  w w w.  j ava  2  s . c om*/
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*");

    final FilterRegistration.Dynamic struts = servletContext.addFilter("struts",
            new StrutsPrepareAndExecuteFilter());
    struts.addMappingForUrlPatterns(dispatcherTypes, false, "/*");
}

From source file:org.uoiu.platform.web.DefaultWebApplicationInitializer.java

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
    //    appContext.register(AppConfig.class);
    appContext.getEnvironment().setActiveProfiles("webapp");
    servletContext.addListener(new ContextLoaderListener(appContext));

    AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
    mvcContext.register(MvcConfig.class);

    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher",
            new DispatcherServlet(mvcContext));
    dispatcher.setLoadOnStartup(1);//  ww  w .ja v a2s.  c  o m
    dispatcher.addMapping("/");

    FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter",
            characterEncodingFilter());
    encodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*");
}