List of usage examples for javax.servlet DispatcherType REQUEST
DispatcherType REQUEST
To view the source code for javax.servlet DispatcherType REQUEST.
Click Source Link
From source file:http2.Main.java
public static void main(String[] args) throws Exception { AnnotationConfigWebApplicationContext cxt = new AnnotationConfigWebApplicationContext(); cxt.register(WebConfig.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(cxt); Server server = new Server(); ServletContextHandler context = new ServletContextHandler(); context.setResourceBase("src/main/webapp"); context.addServlet(new ServletHolder("default", DefaultServlet.class), ""); context.addServlet(new ServletHolder(dispatcherServlet), "/"); context.addFilter(new FilterHolder(new PushCacheFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); server.setHandler(context);// www.j av a2 s . c o m HttpConfiguration httpConfig = new HttpConfiguration(); httpConfig.setSecureScheme("https"); httpConfig.setSecurePort(8443); httpConfig.setSendXPoweredBy(true); httpConfig.setSendServerVersion(true); HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); httpsConfig.addCustomizer(new SecureRequestCustomizer()); ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfig)); httpConnector.setPort(8080); server.addConnector(httpConnector); ServerConnector http2Connector = createHttp2Connector(server, httpsConfig); http2Connector.setPort(8443); server.addConnector(http2Connector); ALPN.debug = true; server.start(); server.dumpStdErr(); server.join(); }
From source file:com.github.zk1931.pulsefs.Main.java
public static void main(String[] args) throws Exception { // Options for command arguments. Options options = new Options(); Option port = OptionBuilder.withArgName("port").hasArg(true).isRequired(true).withDescription("port number") .create("port"); Option addr = OptionBuilder.withArgName("addr").hasArg(true).withDescription("addr (ip:port) for Zab.") .create("addr"); Option join = OptionBuilder.withArgName("join").hasArg(true).withDescription("the addr of server to join.") .create("join"); Option dir = OptionBuilder.withArgName("dir").hasArg(true).withDescription("the directory for logs.") .create("dir"); Option help = OptionBuilder.withArgName("h").hasArg(false).withLongOpt("help") .withDescription("print out usages.").create("h"); Option timeout = OptionBuilder.withArgName("timeout").hasArg(true) .withDescription("session timeout(seconds)").create("timeout"); options.addOption(port).addOption(addr).addOption(join).addOption(dir).addOption(timeout).addOption(help); CommandLineParser parser = new BasicParser(); CommandLine cmd;/*ww w . j ava 2s . co m*/ String usage = "./bin/pulsefs -port port [Options]"; try { cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); return; } } catch (ParseException exp) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(usage, options); return; } PulseFSConfig config = new PulseFSConfig(); if (cmd.hasOption("addr")) { config.setServerId(cmd.getOptionValue("addr")); } if (cmd.hasOption("join")) { config.setJoinPeer(cmd.getOptionValue("join")); } if (cmd.hasOption("dir")) { config.setLogDir(cmd.getOptionValue("dir")); } if (cmd.hasOption("timeout")) { String sessionTimeout = cmd.getOptionValue("timeout"); config.setSessionTimeout(Integer.parseInt(sessionTimeout)); } if (cmd.hasOption("port")) { config.setPort(Integer.parseInt(cmd.getOptionValue("port"))); } Server server = new Server(config.getPort()); // Suppress "Server" header in HTTP response. for (Connector y : server.getConnectors()) { for (ConnectionFactory x : y.getConnectionFactories()) { if (x instanceof HttpConnectionFactory) { ((HttpConnectionFactory) x).getHttpConfiguration().setSendServerVersion(false); } } } PulseFS fs = new PulseFS(config); SessionFilter sessionFilter = new SessionFilter(fs); FilterHolder filters = new FilterHolder(sessionFilter); ServletContextHandler pulsefs = new ServletContextHandler(ServletContextHandler.SESSIONS); pulsefs.setContextPath(PulseFSConfig.PULSEFS_ROOT); pulsefs.setAllowNullPathInfo(true); pulsefs.addServlet(new ServletHolder(new PulseFSHandler(fs)), "/*"); pulsefs.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletContextHandler servers = new ServletContextHandler(ServletContextHandler.SESSIONS); servers.setContextPath(PulseFSConfig.PULSEFS_SERVERS_PATH); // Redirects /pulsefs/servers to /pulsefs/servers/ servers.setAllowNullPathInfo(true); servers.addServlet(new ServletHolder(new PulseFSServersHandler(fs)), "/*"); servers.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletContextHandler tree = new ServletContextHandler(ServletContextHandler.SESSIONS); tree.setContextPath("/"); tree.addServlet(new ServletHolder(new TreeHandler(fs)), "/*"); tree.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ServletContextHandler sessions = new ServletContextHandler(ServletContextHandler.SESSIONS); sessions.setContextPath(PulseFSConfig.PULSEFS_SESSIONS_PATH); // Redirects /pulsefs/sessions to /pulsefs/sessions/ sessions.setAllowNullPathInfo(true); sessions.addServlet(new ServletHolder(new PulseFSSessionsHandler(fs)), "/*"); sessions.addFilter(filters, "/*", EnumSet.of(DispatcherType.REQUEST)); ContextHandlerCollection contexts = new ContextHandlerCollection(); contexts.setHandlers(new Handler[] { sessions, servers, pulsefs, tree }); server.setHandler(contexts); server.start(); server.join(); }
From source file:com.dm.platform.listener.base.MyServletContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { System.out.println("MyServletContextListener"); ServletContext sc = sce.getServletContext(); ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class); sr.setInitParameter("contextConfigLocation", "/WEB-INF/dispatcher-servlet.xml"); sr.addMapping("/spring/*"); FilterRegistration fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class); fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*"); // fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(), DelegatingFilterProxy.class); // fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*"); sc.addListener(new ContextLoaderListener()); }
From source file:com.dm.platform.listener.PlatformServletContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { System.out.println("contextInitialized"); ServletContext sc = sce.getServletContext(); sc.setInitParameter("contextConfigLocation", "/WEB-INF/applicationContext.xml"); // sc.addListener(ContextLoaderListener.class); FilterRegistration fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(), DelegatingFilterProxy.class); fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/spring/*"); ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class); sr.setInitParameter("contextConfigLocation", "/WEB-INF/dispatcher-servlet.xml /WEB-INF/platform-security.xml"); sr.addMapping("/spring/*"); fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class); fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*"); }
From source file:com.olegchir.wicket_spring_security_example.init.AppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { //Create webapp context AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); //part of spring-web root.register(SpringSecurityConfiguration.class); //register class by annotation. Here be all security rules. //Register DelegatingFilterProxy FilterRegistration.Dynamic springSecurityFilterChainReg = servletContext .addFilter("springSecurityFilterChain", DelegatingFilterProxy.class); springSecurityFilterChainReg//ww w.j a va 2s .c o m .addMappingForUrlPatterns(EnumSet.of(DispatcherType.ERROR, DispatcherType.REQUEST), false, "/*"); servletContext.addListener(new ContextLoaderListener(root)); //Register WicketFilter WicketFilter wicketFilter = new WicketFilter(new WicketApplication()) { @Override public void init(boolean isServlet, FilterConfig filterConfig) throws ServletException { setFilterPath(""); //don't use web.xml. WicketApplication.init is a custom override for it. super.init(isServlet, filterConfig); } }; FilterRegistration.Dynamic wicketFilterReg = servletContext.addFilter("wicketFilter", wicketFilter); wicketFilterReg.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "*"); }
From source file:http2.DispatcherServletInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.addFilter("pcf", "org.eclipse.jetty.servlets.PushCacheFilter").addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), true, "/*"); super.onStartup(servletContext); }
From source file:rashjz.info.com.az.config.MyWebInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(SpringWebConfig.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(appContext); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("SpringDispatcher", dispatcherServlet); dispatcher.setLoadOnStartup(1);// w ww. j a v a 2 s .co m dispatcher.addMapping("/"); 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); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); }
From source file:org.ameba.http.MultiTenancyConfiguration.java
/** * Registers the MultiTenantSessionFilter filter. * * @return The registration bean instance *///from ww w.j a v a 2 s .c o m public @Bean FilterRegistrationBean multiTenantSessionFilter() { FilterRegistrationBean registration = new FilterRegistrationBean(new MultiTenantSessionFilter()); 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:org.fon.documentmanagementsystem.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(AppConfig.class); ctx.setServletContext(servletContext); ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1);/*from www .j a v a 2 s . co m*/ servlet.setMultipartConfig(new MultipartConfigElement("", 1024 * 1024 * 25, 1024 * 1024 * 25, 0)); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); }
From source file:org.jblogcms.core.config.MainConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(MainContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/* ww w . j a v a 2 s. com*/ dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); 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)); }