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:io.undertow.servlet.test.dispatcher.DispatcherForwardTestCase.java

@BeforeClass
public static void setup() throws ServletException {

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

    DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader())
            .setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE)
            .setDeploymentName("servletContext.war")
            .setResourceManager(new TestResourceLoader(DispatcherForwardTestCase.class))
            .addServlet(new ServletInfo("forward", MessageServlet.class)
                    .addInitParam(MessageServlet.MESSAGE, "forwarded").addMapping("/forward"))
            .addServlet(new ServletInfo("dispatcher", ForwardServlet.class).addMapping("/dispatch"))
            .addServlet(new ServletInfo("pathTest", PathTestServlet.class).addMapping("/path"))
            .addFilter(new FilterInfo("notforwarded", MessageFilter.class).addInitParam(MessageFilter.MESSAGE,
                    "Not forwarded"))
            .addFilter(new FilterInfo("inc", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Path!"))
            .addFilter(new FilterInfo("nameFilter", MessageFilter.class).addInitParam(MessageFilter.MESSAGE,
                    "Name!"))
            .addFilterUrlMapping("notforwarded", "/forward", DispatcherType.REQUEST)
            .addFilterUrlMapping("inc", "/forward", DispatcherType.FORWARD)
            .addFilterServletNameMapping("nameFilter", "forward", DispatcherType.FORWARD);

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

    DefaultServer.setRootHandler(
            new AccessLogHandler(root, RECEIVER, "%r %U %R", AccessLogFileTestCase.class.getClassLoader()));
}

From source file:de.interseroh.report.webapp.UiWebAppInitializer.java

private void addSecurityFilter(ServletContext servletContext) {
    servletContext.addFilter(SPRING_SECURITY_FILTER_NAME, DelegatingFilterProxy.class).addMappingForUrlPatterns(
            EnumSet.<DispatcherType>of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
}

From source file:io.undertow.servlet.test.path.FilterPathMappingTestCase.java

@Test
public void testBasicFilterMappings() 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.addServlet(new ServletInfo("/aa", PathMappingServlet.class).addMapping("/aa"));

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

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

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

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

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

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

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

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

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

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

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

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

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

    builder.addFilter(new FilterInfo("contextRoot", PathFilter.class));
    builder.addFilterServletNameMapping("contextRoot", "contextRoot", DispatcherType.REQUEST);

    builder.addFilter(new FilterInfo("defaultName", PathFilter.class));
    builder.addFilterServletNameMapping("defaultName", "/", DispatcherType.REQUEST);

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

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

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

    final DeploymentManager manager = container.addDeployment(builder);
    manager.deploy();/*from w  ww .  ja  v a 2 s .  c  om*/
    root.addPrefixPath(builder.getContextPath(), manager.start());

    DefaultServer.setRootHandler(root);

    TestHttpClient client = new TestHttpClient();
    try {
        runTest(client, "test", "/test/* - /test - null", "/*", "*", "/test");
        runTest(client, "aa", "/aa - /aa - null", "/*", "*", "/aa");
        runTest(client, "a/c", "/a/* - /a - /c", "/*", "*", "/a/*");
        runTest(client, "a", "/a/* - /a - null", "/*", "*", "/a/*");
        runTest(client, "aa/b", "/ - /aa/b - null", "/*", "*", "defaultName");
        runTest(client, "a/b/c/d", "/a/* - /a - /b/c/d", "/*", "*", "/a/*");
        runTest(client, "defaultStuff", "/ - /defaultStuff - null", "/*", "*", "defaultName");
        runTest(client, "", "contextRoot - / - null", "/*", "*", "contextRoot");
        runTest(client, "yyyy.bop", "/ - /yyyy.bop - null", "/*", "*", "*.bop", "defaultName");
        runTest(client, "a/yyyy.bop", "/a/* - /a - /yyyy.bop", "/*", "*", "*.bop", "/a/*");
        runTest(client, "myservlet/myfilter/file.dat", "/myservlet/* - /myservlet - /myfilter/file.dat", "/*",
                "*", "/myservlet/myfilter/*");
        runTest(client, "myservlet/myfilter/file.jsp", "/myservlet/* - /myservlet - /myfilter/file.jsp", "/*",
                "*", "/myservlet/myfilter/*");
        runTest(client, "otherservlet/myfilter/file.jsp", "*.jsp - /otherservlet/myfilter/file.jsp - null",
                "/*", "*");
        runTest(client, "myfilter/file.jsp", "*.jsp - /myfilter/file.jsp - null", "/*", "*", "/myfilter/*");
        runTest(client, "helloworld/index.html", "/ - /helloworld/index.html - null", "/*", "*",
                "/helloworld/index.html", "defaultName");

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

From source file:io.gumga.security.WebConfigForTest.java

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

    servletContext.setInitParameter("javax.servlet.jsp.jstl.fmt.localizationContext", "messages");
    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);/* w ww . ja  v a  2s  .  co  m*/
    characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*");

    rootContext.setServletContext(servletContext);
    rootContext.register(WebConfigForTest.class);
    rootContext.refresh();

}

From source file:com.mnt.base.console.WebJettyController.java

protected void init() {
    log.info("Prepare to startup the Jetty Web Server...");

    super.init();

    String webRootPath = BaseConfiguration.getProperty("web_root_path");

    if (CommonUtil.isEmpty(webRootPath)) {
        webRootPath = DEFAULT_WEB_ROOT_PATH;
    }//from  w w w  .ja  v a 2  s .co m

    final WebAppContext webappContext = new WebAppContext(BaseConfiguration.getServerHome(true) + webRootPath,
            BaseConfiguration.getServerContextPath());
    webappContext.setParentLoaderPriority(true);
    File tmpFolder = new File(BaseConfiguration.getServerHome() + "tmp");
    if (!tmpFolder.exists()) {
        tmpFolder.mkdirs();
    }
    webappContext.setTempDirectory(tmpFolder);
    webappContext.setAttribute("javax.servlet.context.tempdir", tmpFolder);

    jettyServer.setHandler(webappContext);

    super.setupExternalConf(new ExternalConfSetter() {

        @Override
        public void addServlet(Class<HttpServlet> servletClass, String pathSpec) throws Exception {
            HttpServlet servlet = (HttpServlet) (servletClass.newInstance());
            webappContext.addServlet(new ServletHolder(servlet), pathSpec);
        }

        @Override
        public void addFilter(Class<Filter> filterClass, String pathSpec) throws Exception {
            webappContext.addFilter(filterClass, pathSpec, EnumSet.of(DispatcherType.REQUEST));
        }
    });
    // be end of the previous setting
    webappContext.addFilter(new FilterHolder(new WebAccessRouterFilter()), "/*",
            EnumSet.of(DispatcherType.REQUEST));
}

From source file:io.gravitee.management.war.WebAppInitializer.java

@Override
public void onStartup(ServletContext context) throws ServletException {
    // initialize
    initialize();//w  ww .  java  2  s  .com
    Properties prop = propertiesLoader.load();

    // REST configuration
    ServletRegistration.Dynamic servletRegistration = context.addServlet("REST",
            ServletContainer.class.getName());
    servletRegistration.addMapping("/management/*");
    servletRegistration.setLoadOnStartup(1);
    servletRegistration.setInitParameter("javax.ws.rs.Application", GraviteeApplication.class.getName());

    // Spring configuration
    System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME,
            prop.getProperty("security.type", "basic-auth"));
    context.addListener(new ContextLoaderListener());
    context.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName());
    context.setInitParameter("contextConfigLocation", RestConfiguration.class.getName());

    // Spring Security filter
    context.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class)
            .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), false, "/*");
}

From source file:org.ireland.jnetty.dispatch.filter.FilterMapping.java

/**
 * True if the dispatcher is for REQUEST.(dispatcherType,REQUEST)
 *//*from www  .j  a  va 2 s.c o m*/
public boolean isRequest() {
    return _dispatcherTypes == null || _dispatcherTypes.contains(DispatcherType.REQUEST);
}

From source file:com.gosmarter.it.eis.config.ExcelERPWebApplicationInitializer.java

private void registerSpringSecurityFilterChain(ServletContext servletContext) {
    DelegatingFilterProxy delegatingFilterProxy = new DelegatingFilterProxy("springSecurityFilterChain");
    FilterRegistration fr = servletContext.addFilter("securityFilter", delegatingFilterProxy);
    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*");
}

From source file:com.almende.eve.transport.http.embed.JettyLauncher.java

@Override
public void addFilter(final String filterpath, final String path) {
    LOG.info("Adding filter:" + filterpath + " / " + path);
    context.addFilter(filterpath, path, EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
}

From source file:com.github.aptd.simulation.ui.CHTTPServer.java

/**
 * ctor/*from  w w  w .j  a  v  a 2  s .  c om*/
 */
private CHTTPServer() {
    // web context definition
    final WebAppContext l_webapp = new WebAppContext();

    // server process
    m_server = new Server(new InetSocketAddress(
            CConfiguration.INSTANCE.<String>getOrDefault("localhost", "httpserver", "host"),
            CConfiguration.INSTANCE.<Integer>getOrDefault(8000, "httpserver", "port")));

    // set server / webapp connection
    m_server.setHandler(l_webapp);
    l_webapp.setServer(m_server);
    l_webapp.setContextPath("/");
    l_webapp.setWelcomeFiles(new String[] { "index.html", "index.htm" });
    l_webapp.setResourceBase(CHTTPServer.class
            .getResource(MessageFormat.format("/{0}/html", CCommon.PACKAGEROOT.replace(".", "/")))
            .toExternalForm());
    l_webapp.addServlet(new ServletHolder(new ServletContainer(m_restagent)), "/rest/*");
    l_webapp.addFilter(new FilterHolder(new CrossOriginFilter()), "/rest/*",
            EnumSet.of(DispatcherType.REQUEST));
}