List of usage examples for javax.servlet ServletContext addServlet
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass);
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 ww w . j a v 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:org.consultjr.mvc.core.config.ApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext context = getContext(); servletContext.addListener(new ContextLoaderListener(context)); servletContext.addListener(new ApplicationSessionListener()); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1);/*from w w w. ja va2 s .c o m*/ dispatcher.addMapping("/"); }
From source file:com.consol.citrus.simulator.WebAppInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocation("/WEB-INF/citrus-servlet-context.xml"); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("citrus", new MessageDispatcherServlet()); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.addMapping("/simulator"); dispatcherServlet.addMapping("/simulator/*"); dispatcherServlet.setInitParameter("contextConfigLocation", ""); ServletRegistration.Dynamic statusServlet = servletContext.addServlet("status", new SimulatorStatusServlet()); statusServlet.setLoadOnStartup(1000); statusServlet.addMapping("/status"); statusServlet.addMapping("/status/*"); ServletRegistration.Dynamic runServlet = servletContext.addServlet("run", new SimulatorRunServlet()); runServlet.setLoadOnStartup(1000);// w w w . ja v a 2s . c o m runServlet.addMapping("/run"); runServlet.addMapping("/run/*"); ServletRegistration.Dynamic resourceServlet = servletContext.addServlet("resource", new StaticResourceServlet()); resourceServlet.setLoadOnStartup(1000); resourceServlet.addMapping("/info"); resourceServlet.addMapping("/info/*"); servletContext.addListener(new ContextLoaderListener(appContext)); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding(System.getProperty("file.encoding", "UTF-8")); encodingFilter.setForceEncoding(true); FilterRegistration.Dynamic filter = servletContext.addFilter("encoding-filter", encodingFilter); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); }
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 ww w .j a v a2 s .c o 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, "/nopublic/*"); security.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:org.ratty.configs.AppConfig.java
public void onStartup(ServletContext servletContext) throws ServletException { final AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(AppConfig.class); ctx.setServletContext(servletContext); final ServletRegistration.Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx)); dynamic.addMapping("/"); dynamic.setLoadOnStartup(1);// w ww . j av a 2 s. c o m }
From source file:org.synchronoss.cloud.nio.multipart.example.utils.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation("org.synchronoss.cloud.nio.multipart.example.config"); context.setServletContext(servletContext); Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); dynamic.setAsyncSupported(true);/*from w w w .j a v a 2s .c om*/ dynamic.addMapping("/"); dynamic.setLoadOnStartup(1); }
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);/*from w w w . ja v a2 s. c o 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:io.cettia.ProtocolTest.java
@Test public void protocol() throws Exception { final DefaultServer server = new DefaultServer(); server.onsocket(new Action<ServerSocket>() { @Override//from w w w . j a va2 s .c om public void on(final ServerSocket socket) { log.debug("socket.uri() is {}", socket.uri()); socket.on("abort", new VoidAction() { @Override public void on() { socket.close(); } }).on("echo", new Action<Object>() { @Override public void on(Object data) { socket.send("echo", data); } }).on("/reply/inbound", new Action<Reply<Map<String, Object>>>() { @Override public void on(Reply<Map<String, Object>> reply) { Map<String, Object> data = reply.data(); switch ((String) data.get("type")) { case "resolved": reply.resolve(data.get("data")); break; case "rejected": reply.reject(data.get("data")); break; } } }).on("/reply/outbound", new Action<Map<String, Object>>() { @Override public void on(Map<String, Object> data) { switch ((String) data.get("type")) { case "resolved": socket.send("test", data.get("data"), new Action<Object>() { @Override public void on(Object data) { socket.send("done", data); } }); break; case "rejected": socket.send("test", data.get("data"), null, new Action<Object>() { @Override public void on(Object data) { socket.send("done", data); } }); break; } } }); } }); final HttpTransportServer httpTransportServer = new HttpTransportServer().ontransport(server); final WebSocketTransportServer wsTransportServer = new WebSocketTransportServer().ontransport(server); org.eclipse.jetty.server.Server jetty = new org.eclipse.jetty.server.Server(); ServerConnector connector = new ServerConnector(jetty); jetty.addConnector(connector); connector.setPort(8000); ServletContextHandler handler = new ServletContextHandler(); jetty.setHandler(handler); handler.addEventListener(new ServletContextListener() { @Override @SuppressWarnings("serial") public void contextInitialized(ServletContextEvent event) { ServletContext context = event.getServletContext(); ServletRegistration regSetup = context.addServlet("/setup", new HttpServlet() { @Override protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { Map<String, String[]> params = req.getParameterMap(); if (params.containsKey("heartbeat")) { server.setHeartbeat(Integer.parseInt(params.get("heartbeat")[0])); } if (params.containsKey("_heartbeat")) { server.set_heartbeat(Integer.parseInt(params.get("_heartbeat")[0])); } } }); regSetup.addMapping("/setup"); // For HTTP transport Servlet servlet = new AsityServlet().onhttp(httpTransportServer); ServletRegistration.Dynamic reg = context.addServlet(AsityServlet.class.getName(), servlet); reg.setAsyncSupported(true); reg.addMapping("/cettia"); } @Override public void contextDestroyed(ServletContextEvent sce) { } }); // For WebSocket transport ServerContainer container = WebSocketServerContainerInitializer.configureContext(handler); ServerEndpointConfig config = ServerEndpointConfig.Builder.create(AsityServerEndpoint.class, "/cettia") .configurator(new Configurator() { @Override public <T> T getEndpointInstance(Class<T> endpointClass) throws InstantiationException { return endpointClass.cast(new AsityServerEndpoint().onwebsocket(wsTransportServer)); } }).build(); container.addEndpoint(config); jetty.start(); CommandLine cmdLine = CommandLine.parse("./src/test/resources/node/node") .addArgument("./src/test/resources/runner").addArgument("--cettia.transports") .addArgument("websocket,httpstream,httplongpoll"); DefaultExecutor executor = new DefaultExecutor(); // The exit value of mocha is the number of failed tests. executor.execute(cmdLine); jetty.stop(); }
From source file:at.ac.tuwien.infosys.configuration.WebAppInitializer.java
@Override public void onStartup(final ServletContext context) throws ServletException { final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); root.scan("at.ac.tuwien.infosys"); context.addListener(new ContextLoaderListener(root)); final ServletRegistration.Dynamic appServlet = context.addServlet("appServlet", new DispatcherServlet(new GenericWebApplicationContext())); appServlet.setAsyncSupported(true);// w w w .j a va 2s . c o m appServlet.setLoadOnStartup(1); appServlet.addMapping("/*"); }
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 www . j av a 2 s . com*/ 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)); }