Java Code Examples for javax.servlet.ServletRegistration#addMapping()
The following examples show how to use
javax.servlet.ServletRegistration#addMapping() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServletRegister.java From vi with Apache License 2.0 | 6 votes |
protected static final void regiesterVIServlet(ServletContext context,Logger logger){ try { ServletRegistration.Dynamic asr = context.addServlet("VIApiServlet", VIApiServlet.class); if (asr != null) { asr.setLoadOnStartup(Integer.MAX_VALUE); asr.addMapping("/@in/api/*"); } else { logger.warn("Servlet VIApiServlet already exists"); } ServletRegistration ssr = context.addServlet("VIHttpServlet", StaticContentServlet.class); if (ssr != null) { ssr.addMapping("/@in/*"); } else { logger.warn("Servlet VIHttpServlet already exists"); } }catch (Throwable e){ logger.error("VI register servlet failed",e); } }
Example 2
Source File: DispatcherServlet.java From myspring with MIT License | 5 votes |
@Override public void init(ServletConfig config) throws ServletException { Object oldCxt = config.getServletContext().getAttribute(ContextLoaderListener.ROOT_CXT_ATTR); this.context = oldCxt == null ? new WebApplicationContext() : (WebApplicationContext)oldCxt; ServletContext sc = config.getServletContext(); //注册JSP的Servlet,视图才能重定向 ServletRegistration jspServlet = sc.getServletRegistration("jsp"); jspServlet.addMapping(CommonUtis.JSP_PATH_PREFIX + "*"); }
Example 3
Source File: RpcServerManager.java From nuls-v2 with MIT License | 5 votes |
public void startServer(String ip, int port) { URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build(); // Create test web application context. WebappContext webappContext = new WebappContext("NULS-V2-SDK-PROVIDER-SERVER", "/"); ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class); servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.provider.api.config.NulsResourceConfig"); servletRegistration.addMapping("/*"); httpServer = new HttpServer(); NetworkListener listener = new NetworkListener("grizzly2", ip, port); TCPNIOTransport transport = listener.getTransport(); ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig() .setCorePoolSize(4) .setMaxPoolSize(4) .setQueueLimit(1000) .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build()); transport.configureBlocking(false); transport.setSelectorRunnersCount(2); transport.setWorkerThreadPoolConfig(workerPool); transport.setIOStrategy(WorkerThreadIOStrategy.getInstance()); transport.setTcpNoDelay(true); listener.setSecure(false); httpServer.addListener(listener); ServerConfiguration config = httpServer.getServerConfiguration(); config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET); webappContext.deploy(httpServer); try { ClassLoader loader = this.getClass().getClassLoader(); httpServer.start(); Log.info("http restFul server is started!url is " + serverURI.toString()); } catch (IOException e) { Log.error(e); httpServer.shutdownNow(); } }
Example 4
Source File: DispatherServlet.java From bfmvc with Apache License 2.0 | 5 votes |
@Override public void init(ServletConfig config) throws ServletException { Loader.init();//初始化框架&应用 ServletContext sc = config.getServletContext(); //注册JSP的Servlet ServletRegistration jspServlet = sc.getServletRegistration("jsp"); jspServlet.addMapping(ConfigHelper.getAppJspPath() + "*"); //注册处理静态资源的Servlet ServletRegistration defaultServlet = sc.getServletRegistration("default"); defaultServlet.addMapping(ConfigHelper.getAppAssetPath() + "*"); }
Example 5
Source File: CamundaBpmWebappInitializer.java From camunda-bpm-spring-boot-starter with Apache License 2.0 | 5 votes |
private ServletRegistration registerServlet(final String servletName, final Class<?> applicationClass, final String... urlPatterns) { ServletRegistration servletRegistration = servletContext.getServletRegistration(servletName); if (servletRegistration == null) { servletRegistration = servletContext.addServlet(servletName, ServletContainer.class); servletRegistration.addMapping(urlPatterns); servletRegistration.setInitParameters(singletonMap(JAXRS_APPLICATION_CLASS, applicationClass.getName())); log.debug("Servlet {} for URL {} registered.", servletName, urlPatterns); } return servletRegistration; }
Example 6
Source File: ContainerListener.java From smart-framework with Apache License 2.0 | 5 votes |
private void registerDefaultServlet(ServletContext context) { ServletRegistration defaultServlet = context.getServletRegistration("default"); defaultServlet.addMapping("/index.html"); defaultServlet.addMapping("/favicon.ico"); String wwwPath = FrameworkConstant.WWW_PATH; if (StringUtil.isNotEmpty(wwwPath)) { defaultServlet.addMapping(wwwPath + "*"); } }
Example 7
Source File: ContainerListener.java From smart-framework with Apache License 2.0 | 5 votes |
private void registerJspServlet(ServletContext context) { ServletRegistration jspServlet = context.getServletRegistration("jsp"); jspServlet.addMapping("/index.jsp"); String jspPath = FrameworkConstant.JSP_PATH; if (StringUtil.isNotEmpty(jspPath)) { jspServlet.addMapping(jspPath + "*"); } }
Example 8
Source File: ContainerListener.java From smart-framework with Apache License 2.0 | 5 votes |
private void registerDefaultServlet(ServletContext context) { ServletRegistration defaultServlet = context.getServletRegistration("default"); defaultServlet.addMapping("/index.html"); defaultServlet.addMapping("/favicon.ico"); String wwwPath = FrameworkConstant.WWW_PATH; if (StringUtil.isNotEmpty(wwwPath)) { defaultServlet.addMapping(wwwPath + "*"); } }
Example 9
Source File: ContainerListener.java From smart-framework with Apache License 2.0 | 5 votes |
private void registerJspServlet(ServletContext context) { ServletRegistration jspServlet = context.getServletRegistration("jsp"); jspServlet.addMapping("/index.jsp"); String jspPath = FrameworkConstant.JSP_PATH; if (StringUtil.isNotEmpty(jspPath)) { jspServlet.addMapping(jspPath + "*"); } }
Example 10
Source File: CamundaBpmWebappInitializer.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
private ServletRegistration registerServlet(final String servletName, final Class<?> applicationClass, final String... urlPatterns) { ServletRegistration servletRegistration = servletContext.getServletRegistration(servletName); if (servletRegistration == null) { servletRegistration = servletContext.addServlet(servletName, ServletContainer.class); servletRegistration.addMapping(urlPatterns); servletRegistration.setInitParameters(singletonMap(JAXRS_APPLICATION_CLASS, applicationClass.getName())); log.debug("Servlet {} for URL {} registered.", servletName, urlPatterns); } return servletRegistration; }
Example 11
Source File: RpcServerManager.java From nuls-v2 with MIT License | 4 votes |
public void startServer(String ip, int port) { URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build(); // Create test web application context. WebappContext webappContext = new WebappContext("NULS-RPC-SERVER", "/api"); ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class); servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.test.controller.NulsResourceConfig"); servletRegistration.addMapping("/api/*"); httpServer = new HttpServer(); NetworkListener listener = new NetworkListener("grizzly2", ip, port); TCPNIOTransport transport = listener.getTransport(); ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig() .setCorePoolSize(4) .setMaxPoolSize(4) .setQueueLimit(1000) .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build()); transport.configureBlocking(false); transport.setSelectorRunnersCount(2); transport.setWorkerThreadPoolConfig(workerPool); transport.setIOStrategy(WorkerThreadIOStrategy.getInstance()); transport.setTcpNoDelay(true); listener.setSecure(false); httpServer.addListener(listener); ServerConfiguration config = httpServer.getServerConfiguration(); config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET); webappContext.deploy(httpServer); try { ClassLoader loader = this.getClass().getClassLoader(); addSwagerUi(loader); addClientUi(loader); httpServer.start(); log.info("http restFul server is started!url is " + serverURI.toString()); } catch (IOException e) { log.error("",e); httpServer.shutdownNow(); } }
Example 12
Source File: RpcServerManager.java From nuls with MIT License | 4 votes |
public void startServer(String ip, int port) { URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build(); // Create test web application context. WebappContext webappContext = new WebappContext("NULS-RPC-SERVER", "/api"); ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class); servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.client.rpc.config.NulsResourceConfig"); servletRegistration.addMapping("/api/*"); httpServer = new HttpServer(); NetworkListener listener = new NetworkListener("grizzly2", ip, port); TCPNIOTransport transport = listener.getTransport(); ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig() .setCorePoolSize(4) .setMaxPoolSize(4) .setQueueLimit(1000) .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build()); transport.configureBlocking(false); transport.setSelectorRunnersCount(2); transport.setWorkerThreadPoolConfig(workerPool); transport.setIOStrategy(WorkerThreadIOStrategy.getInstance()); transport.setTcpNoDelay(true); listener.setSecure(false); httpServer.addListener(listener); ServerConfiguration config = httpServer.getServerConfiguration(); config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET); webappContext.deploy(httpServer); try { ClassLoader loader = this.getClass().getClassLoader(); addSwagerUi(loader); addClientUi(loader); httpServer.start(); Log.info("http restFul server is started!url is " + serverURI.toString()); } catch (IOException e) { Log.error(e); httpServer.shutdownNow(); } }