List of usage examples for javax.servlet ServletRegistration.Dynamic addMapping
public Set<String> addMapping(String... urlPatterns);
From source file:com.flipkart.polyguice.dropwiz.PolyguiceApp.java
private void registerServlet(Class<?> type, Environment env) { LOGGER.debug("registering servlet: {}", type.getName()); WebServlet ann = type.getAnnotation(WebServlet.class); String srvName = ann.name();//from www . j ava 2s.com if (StringUtils.isBlank(srvName)) { LOGGER.error("servlet {}: name could not be blank", type.getName()); return; } String[] paths = ann.urlPatterns(); if (paths == null || paths.length == 0) { paths = ann.value(); if (paths == null || paths.length == 0) { LOGGER.error("url patterns missing for servlet {}", type.getName()); return; } } int losu = ann.loadOnStartup(); Servlet servlet = null; try { servlet = (Servlet) type.newInstance(); polyguice.getComponentContext().inject(servlet); } catch (Exception exep) { LOGGER.error("error creating servlet {}", type.getName()); return; } ServletRegistration.Dynamic dynamic = env.servlets().addServlet(srvName, servlet); dynamic.addMapping(paths); dynamic.setLoadOnStartup(losu); if (ann.initParams() == null) { return; } for (WebInitParam param : ann.initParams()) { String name = param.name(); String value = param.value(); if (StringUtils.isNoneBlank(name)) { dynamic.setInitParameter(name, value); } } }
From source file:com.contact.MyWebAppInitializer.java
public void onStartup(ServletContext container) throws ServletException { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocation("/WEB-INF/spring/appServlet/servlet-context.xml"); ServletRegistration.Dynamic dispatcher = container.addServlet("appServlet", new DispatcherServlet(appContext)); MultipartConfigElement multipartConfigElement = new MultipartConfigElement(null, 5000000, 5000000, 0); dispatcher.setMultipartConfig(multipartConfigElement); dispatcher.setLoadOnStartup(1);/*w ww . j ava 2 s . c o m*/ dispatcher.addMapping("/"); }
From source file:ca.n4dev.dev.worktime.config.SpringAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext context = getContext(); servletContext.addListener(new ContextLoaderListener(context)); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); //servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")).addMappingForUrlPatterns(null, false, "/*"); dispatcher.setLoadOnStartup(1);//from www. j av a2 s .c om dispatcher.addMapping(MAPPING_URL); }
From source file:org.kew.rmf.reconciliation.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) { WebApplicationContext rootContext = createRootContext(servletContext); configureSpringMvc(servletContext, rootContext); // Add Perf4J graphing servlet ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("perf4j", org.perf4j.logback.servlet.GraphingServlet.class); servletRegistration.setInitParameter("graphNames", "graphOtherTimes,graphQueryTimes,graphQueriesPerSecond"); servletRegistration.addMapping("/perf4j"); String TAG_SWAP_FILTER_CLASS = "org.kew.servlet.filter.TagSwapFilter"; try {/*from ww w . j a v a 2s.c o m*/ Class.forName(TAG_SWAP_FILTER_CLASS, false, this.getClass().getClassLoader()); String[] urlPatterns = { "/", "/about/*", "/admin", "/filematch/*", "/help" }; FilterRegistration.Dynamic cssLinkFilter = servletContext.addFilter("CssLinkFilter", TAG_SWAP_FILTER_CLASS); cssLinkFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/head.chunk"); cssLinkFilter.setInitParameter("tag_name", "[KEWCSS]"); cssLinkFilter.addMappingForUrlPatterns(null, true, urlPatterns); FilterRegistration.Dynamic headerFilter = servletContext.addFilter("HeaderFilter", TAG_SWAP_FILTER_CLASS); headerFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/bodytop.chunk"); headerFilter.setInitParameter("tag_name", "[KEWHEADER]"); headerFilter.addMappingForUrlPatterns(null, true, urlPatterns); FilterRegistration.Dynamic footerFilter = servletContext.addFilter("FooterFilter", TAG_SWAP_FILTER_CLASS); footerFilter.setInitParameter("include_file_name", "/var/lib/science-apps/web-resources/bodybottom.chunk"); footerFilter.setInitParameter("tag_name", "[KEWFOOTER]"); footerFilter.addMappingForUrlPatterns(null, true, urlPatterns); } catch (ClassNotFoundException e) { log.error("Kew servlet filters not in use, class {} not on classpath", TAG_SWAP_FILTER_CLASS); } }
From source file:org.alfresco.bm.web.WebApp.java
@Override public void onStartup(ServletContext container) { // Grab the server capabilities, otherwise just use the java version String javaVersion = System.getProperty("java.version"); String systemCapabilities = System.getProperty(PROP_SYSTEM_CAPABILITIES, javaVersion); String appDir = new File(".").getAbsolutePath(); String appContext = container.getContextPath(); String appName = container.getContextPath().replace(SEPARATOR, ""); // Create an application context (don't start, yet) XmlWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setConfigLocations(new String[] { "classpath:config/spring/app-context.xml" }); // Pass our properties to the new context Properties ctxProperties = new Properties(); {/*from www . ja va 2 s .c om*/ ctxProperties.put(PROP_SYSTEM_CAPABILITIES, systemCapabilities); ctxProperties.put(PROP_APP_CONTEXT_PATH, appContext); ctxProperties.put(PROP_APP_DIR, appDir); } ConfigurableEnvironment ctxEnv = ctx.getEnvironment(); ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource(appName, ctxProperties)); // Override all properties with system properties ctxEnv.getPropertySources().addFirst(new PropertiesPropertySource("system", System.getProperties())); // Bind to shutdown ctx.registerShutdownHook(); ContextLoaderListener ctxLoaderListener = new ContextLoaderListener(ctx); container.addListener(ctxLoaderListener); ServletRegistration.Dynamic jerseyServlet = container.addServlet("jersey-serlvet", SpringServlet.class); jerseyServlet.setInitParameter("com.sun.jersey.config.property.packages", "org.alfresco.bm.rest"); jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true"); jerseyServlet.addMapping("/api/*"); }
From source file:org.obiba.mica.config.WebConfiguration.java
/** * Initializes Metrics.// w w w. j ava 2s . c o m */ private void initMetrics(ServletContext servletContext, EnumSet<DispatcherType> disps) { log.debug("Initializing Metrics registries"); servletContext.setAttribute(InstrumentedFilter.REGISTRY_ATTRIBUTE, metricRegistry); servletContext.setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry); log.debug("Registering Metrics Filter"); FilterRegistration.Dynamic metricsFilter = servletContext.addFilter("webappMetricsFilter", new InstrumentedFilter()); metricsFilter.addMappingForUrlPatterns(disps, true, "/*"); metricsFilter.setAsyncSupported(true); log.debug("Registering Metrics Servlet"); ServletRegistration.Dynamic metricsAdminServlet = servletContext.addServlet("metricsServlet", new MetricsServlet()); metricsAdminServlet.addMapping("/jvm/*"); metricsAdminServlet.setAsyncSupported(true); metricsAdminServlet.setLoadOnStartup(2); }
From source file:org.brutusin.rpc.RpcWebInitializer.java
private RpcServlet registerRpcServlet(ServletContext ctx) { LOGGER.info("Starting HTTP RPC runtime"); RpcServlet servlet = new RpcServlet(); ServletRegistration.Dynamic regInfo = ctx.addServlet(RpcServlet.class.getName(), servlet); ServletSecurityElement sec = new ServletSecurityElement(new HttpConstraintElement()); regInfo.setServletSecurity(sec);// w ww .j a v a 2 s. c om regInfo.setLoadOnStartup(1); regInfo.addMapping(RpcConfig.getInstance().getPath() + "/http"); return servlet; }
From source file:io.cettia.ProtocolTest.java
@Test public void protocol() throws Exception { final DefaultServer server = new DefaultServer(); server.onsocket(new Action<ServerSocket>() { @Override/*w ww .j av a2 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:org.bonitasoft.web.designer.SpringWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { for (String line : BANNER) { logger.info(line);//from w w w.j ava2s .c o m } logger.info(Strings.repeat("=", 100)); logger.info(String.format("UI-DESIGNER : %s edition v.%s", prop.getProperty("designer.edition"), prop.getProperty("designer.version"))); logger.info(Strings.repeat("=", 100)); // Create the root context Spring AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(new Class<?>[] { ApplicationConfig.class }); // Manage the lifecycle of the root application context servletContext.addListener(new ContextLoaderListener(rootContext)); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.setMultipartConfig(new MultipartConfigElement(System.getProperty("java.io.tmpdir"))); dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); }
From source file:net.oneandone.stool.overview.initializer.ApplicationInitializer.java
@Override public void afterSpringSecurityFilterChain(ServletContext servletContext) { AnnotationConfigWebApplicationContext context; ServletRegistration.Dynamic dispatcher; context = new AnnotationConfigWebApplicationContext(); context.setConfigLocation("net.oneandone.stool.overview.config"); servletContext.addListener(new ContextLoaderListener(context)); dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1);//from w ww. jav a 2s . c o m dispatcher.addMapping("/"); }