Java Code Examples for org.eclipse.jetty.servlet.ServletMapping#getPathSpecs()
The following examples show how to use
org.eclipse.jetty.servlet.ServletMapping#getPathSpecs() .
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: AssetServlet.java From onedev with MIT License | 5 votes |
@Override public final Resource getResource(String pathInContext) { ServletContextHandler.Context context = (ServletContextHandler.Context) getServletContext(); ServletContextHandler contextHandler = (ServletContextHandler) context.getContextHandler(); for (ServletMapping mapping: contextHandler.getServletHandler().getServletMappings()) { if (mapping.getServletName().equals(getServletName())) { for (String pathSpec: mapping.getPathSpecs()) { String relativePath = null; if (pathSpec.endsWith("/*")) { pathSpec = StringUtils.substringBeforeLast(pathSpec, "/*"); if (pathInContext.startsWith(pathSpec + "/")) relativePath = pathInContext.substring(pathSpec.length()); } else if (pathSpec.startsWith("*.")) { pathSpec = StringUtils.stripStart(pathSpec, "*"); if (pathInContext.endsWith(pathSpec)) relativePath = pathInContext; } else if (pathSpec.equals(pathInContext)) { relativePath = pathInContext; } if (relativePath != null) { relativePath = StringUtils.stripStart(relativePath, "/"); Resource resource = Resource.newResource(loadResource(relativePath)); if (resource != null && resource.exists()) return resource; } } } } return null; }
Example 2
Source File: HttpConductorImpl.java From sql-layer with GNU Affero General Public License v3.0 | 5 votes |
@Override public void unregisterHandler(ServletHolder servlet) { synchronized(lock) { ServletHandler servletHandler = rootContextHandler.getServletHandler(); ServletHolder[] curServlets = servletHandler.getServlets(); List<ServletHolder> newServlets = new ArrayList<>(); newServlets.addAll(Arrays.asList(curServlets)); if(!newServlets.remove(servlet)) { throw new IllegalArgumentException("Servlet not registered"); } List<ServletMapping> newMappings = new ArrayList<>(); newMappings.addAll(Arrays.asList(servletHandler.getServletMappings())); for(Iterator<ServletMapping> it = newMappings.iterator(); it.hasNext(); ) { ServletMapping m = it.next(); if(servlet.getName().equals(m.getServletName())) { for(String path : m.getPathSpecs()) { registeredPaths.remove(path); } it.remove(); break; } } servletHandler.setServlets(newServlets.toArray(new ServletHolder[newServlets.size()])); servletHandler.setServletMappings(newMappings.toArray(new ServletMapping[newMappings.size()])); if(!servlet.isStopped()) { try { servlet.stop(); } catch(Exception e) { throw new HttpConductorException(e); } } } }
Example 3
Source File: WebMappingsRenderer.java From dropwizard-guicey with MIT License | 5 votes |
@SuppressFBWarnings("RV_RETURN_VALUE_IGNORED_INFERRED") private void renderServlet(final ServletMapping mapping, final ServletHolder holder, final Multimap<String, FilterReference> servletFilters, final TreeNode root) throws Exception { final List<String> markers = new ArrayList<>(); boolean first = true; for (String path : mapping.getPathSpecs()) { markers.clear(); if (first && !holder.isEnabled()) { markers.add("DISABLED"); } // indicate multiple mappings of the same servlet String type = IDEM; String async = ""; String stopped = ""; String name = ""; if (first) { type = RenderUtils.renderClassLine(Class.forName(holder.getClassName()), markers); if (holder.isStopped()) { stopped = STOPPED; } if (holder.isAsyncSupported()) { async = ASYNC; } name = mapping.getServletName(); } final TreeNode servlet = root.child("servlet %-20s %-7s %-70s %-10s %-15s %s", // blank placeholder to match with filters output path, async, type, stopped, "", name); if (first) { for (FilterReference filter : servletFilters.get(mapping.getServletName())) { renderFilter(filter.getMapping(), filter.getHolder(), servlet); } } first = false; } }