@Override public void init(ServletConfig config) throws ServletException { HelperLoader.init(); ServletContext servletContext = config.getServletContext(); ServletRegistration jspServlet = servletContext.getServletRegistration("jsp"); jspServlet.addMapping(ConfigHelper.getAppJspPath() + "*"); ServletRegistration defaultServlet = servletContext.getServletRegistration("default"); defaultServlet.addMapping(ConfigHelper.getAppAssetPath() + "*"); }
@Override public void init(ServletConfig servletConfig) throws ServletException { // 初始化 Helper 类 HelperLoader.init(); // 获取 ServletContext 对象(用于注册Servlet) ServletContext servletContext = servletConfig.getServletContext(); // 注册处理 JSP 的 Servlet ServletRegistration jspServlet = servletContext.getServletRegistration("jsp"); jspServlet.addMapping(ConfigHelper.getAppJspPath() + "*"); // 注册处理静态资源的默认 Servlet ServletRegistration defaultServlet = servletContext.getServletRegistration("default"); defaultServlet.addMapping(ConfigHelper.getAppAssetPath() + "*"); }
/** * Add endpoint mapping to cas servlet. * * @param sce the sce * @param mapping the mapping */ protected final void addEndpointMappingToCasServlet( final ServletContextEvent sce, final String mapping) { logger.info("Adding [{}] to {} servlet context", mapping, WebUtils.CAS_SERVLET_NAME); final ServletRegistration registration = getCasServletRegistration(sce); if (registration != null) { registration.addMapping(mapping); logger.info("Added [{}] to {} servlet context", mapping, WebUtils.CAS_SERVLET_NAME); } }
@Override public void startServer() throws Exception { server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI)); AtmosphereServlet atmoServlet = new AtmosphereServlet(); WebappContext context = new WebappContext("Chatty", "/chatty"); ServletRegistration atmosphereRegistration = context.addServlet("Atmosphere", atmoServlet); atmosphereRegistration.addMapping("/atmos/*"); ServletContainer jerseyContainer = new ServletContainer(resourceConfig); ServletRegistration jerseyRegistration = context.addServlet("Jersey", jerseyContainer); jerseyRegistration.addMapping("/api/*"); context.deploy(server); server.start(); }
public void onStartup(Set<Class<?>> wsClassSet, ServletContext context) throws ServletException { LOGGER.info("WAR has webservice classes: " + wsClassSet); // TODO Check if metadata-complete is true in web.xml // Get the WSDL and schema documents in /WEB-INF/wsdl dir List<Source> metadata = new ArrayList<>(); try { Set<URL> docs = new HashSet<>(); collectDocs(docs, new ServletResourceLoader(context), JAXWS_WSDL_DD_DIR); for (URL url : docs) { Source source = new StreamSource(url.openStream(), url.toExternalForm()); metadata.add(source); } } catch (IOException me) { throw new ServletException(me); } // Parse /WEB-INF/webservices.xml DD List<EndpointInfo> ddEndpointList = parseDD(context); // Consolidate endpoints from DD and annotations List<EndpointInfo> endpointInfoList = getConsolidatedEndpoints(context, ddEndpointList, wsClassSet, metadata); if (endpointInfoList.isEmpty()) { return; // No web service endpoints } EndpointAdapterFactory factory = new EndpointAdapterFactory(); List<EndpointAdapter> adapters = new ArrayList<>(); for (EndpointInfo endpointInfo : endpointInfoList) { ServletRegistration reg = context.getServletRegistration(endpointInfo.servletLink); if (reg == null) { reg = context.addServlet(endpointInfo.servletLink, WSServlet.class); } else { // NEED the following in servlet API to override <servlet-class> // reg.setClassName(endpointInfo.implType); } Collection<String> mappings = reg.getMappings(); if (!mappings.contains(endpointInfo.urlPattern)) { reg.addMapping(endpointInfo.urlPattern); } EndpointAdapter adapter = factory.createAdapter(endpointInfo); adapters.add(adapter); } for (EndpointAdapter adapter : adapters) { adapter.publish(); } context.setAttribute(WSServlet.JAXWS_RI_RUNTIME_INFO, adapters); }
public static void main(String[] args) throws Exception { HttpServer server = HttpServer.createSimpleServer("/", 8080); WebappContext ctx = new WebappContext("api"); ServletRegistration jerseyServlet = ctx.addServlet("jersey", org.glassfish.jersey.servlet.ServletContainer.class); jerseyServlet.addMapping("/api/*"); jerseyServlet.setInitParameter("jersey.config.server.provider.packages", "com.resource"); jerseyServlet.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true"); ctx.deploy(server); try { server.start(); System.out.println("Press any key to stop the server...."); System.in.read(); } finally { server.shutdownNow(); } }
@Override protected void doAdditionalModuleStartLogic() throws Exception { if (StringUtils.isNotBlank(dispatchServletName)) { DispatcherServlet loaderServlet = new DispatcherServlet( (WebApplicationContext) ((SpringResourceLoader) rootResourceLoader.getResourceLoaders().get(0)) .getContext()); ServletRegistration registration = getServletContext().addServlet(dispatchServletName, loaderServlet); registration.addMapping("/" + dispatchServletName + "/*"); if (dispatchServletMappings != null) { dispatchServletMappings .stream() .map(mapping -> "/" + mapping + "/*") .forEach(registration::addMapping); } if (mapFilters) { for (String filterName : filtersToMap) { FilterRegistration filter = getServletContext().getFilterRegistration(filterName); filter.addMappingForServletNames(null, true, dispatchServletName); } } if (enableSpringSecurity) { DelegatingFilterProxy filterProxy = new DelegatingFilterProxy( SPRING_SECURITY_FILTER_CHAIN, (WebApplicationContext) ((SpringResourceLoader) rootResourceLoader.getResourceLoaders().get(0)) .getContext()); FilterRegistration.Dynamic securityFilter = getServletContext() .addFilter(KC_PREFIX + getModuleName() + SPRING_SECURITY_FILTER_PROXY, filterProxy); securityFilter.addMappingForServletNames(null, true, dispatchServletName); } } }