use of org.eclipse.jetty.servlet.ServletMapping in project jetty.project by eclipse.
the class QuickStartDescriptorProcessor method visitServletMapping.
/**
* Process a servlet-mapping element
*
* @param context the webapp
* @param descriptor the xml file to process
* @param node the servlet-mapping element in the xml file to process
*/
public void visitServletMapping(WebAppContext context, Descriptor descriptor, XmlParser.Node node) {
String servletName = node.getString("servlet-name", false, true);
ServletMapping mapping = null;
ServletMapping[] mappings = context.getServletHandler().getServletMappings();
if (mappings != null) {
for (ServletMapping m : mappings) {
if (servletName.equals(m.getServletName())) {
mapping = m;
break;
}
}
}
if (mapping != null && _originAttributeName != null) {
String origin = node.getAttribute(_originAttributeName);
if (!StringUtil.isBlank(origin) && origin.startsWith(DefaultsDescriptor.class.getSimpleName()))
mapping.setDefault(true);
}
}
use of org.eclipse.jetty.servlet.ServletMapping in project hadoop by apache.
the class HttpServer2 method addInternalServlet.
/**
* Add an internal servlet in the server, specifying whether or not to
* protect with Kerberos authentication.
* Note: This method is to be used for adding servlets that facilitate
* internal communication and not for user facing functionality. For
* servlets added using this method, filters (except internal Kerberos
* filters) are not enabled.
*
* @param name The name of the servlet (can be passed as null)
* @param pathSpec The path spec for the servlet
* @param clazz The servlet class
* @param requireAuth Require Kerberos authenticate to access servlet
*/
public void addInternalServlet(String name, String pathSpec, Class<? extends HttpServlet> clazz, boolean requireAuth) {
ServletHolder holder = new ServletHolder(clazz);
if (name != null) {
holder.setName(name);
}
// Jetty doesn't like the same path spec mapping to different servlets, so
// if there's already a mapping for this pathSpec, remove it and assume that
// the newest one is the one we want
final ServletMapping[] servletMappings = webAppContext.getServletHandler().getServletMappings();
for (int i = 0; i < servletMappings.length; i++) {
if (servletMappings[i].containsPathSpec(pathSpec)) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found existing " + servletMappings[i].getServletName() + " servlet at path " + pathSpec + "; will replace mapping" + " with " + holder.getName() + " servlet");
}
ServletMapping[] newServletMappings = ArrayUtil.removeFromArray(servletMappings, servletMappings[i]);
webAppContext.getServletHandler().setServletMappings(newServletMappings);
break;
}
}
webAppContext.addServlet(holder, pathSpec);
if (requireAuth && UserGroupInformation.isSecurityEnabled()) {
LOG.info("Adding Kerberos (SPNEGO) filter to " + name);
ServletHandler handler = webAppContext.getServletHandler();
FilterMapping fmap = new FilterMapping();
fmap.setPathSpec(pathSpec);
fmap.setFilterName(SPNEGO_FILTER);
fmap.setDispatches(FilterMapping.ALL);
handler.addFilterMapping(fmap);
}
}
use of org.eclipse.jetty.servlet.ServletMapping in project spring-boot by spring-projects.
the class JettyServletWebServerFactory method addJspServlet.
/**
* Add Jetty's {@code JspServlet} to the given {@link WebAppContext}.
* @param context the jetty {@link WebAppContext}
*/
protected final void addJspServlet(WebAppContext context) {
Assert.notNull(context, "Context must not be null");
ServletHolder holder = new ServletHolder();
holder.setName("jsp");
holder.setClassName(getJsp().getClassName());
holder.setInitParameter("fork", "false");
holder.setInitParameters(getJsp().getInitParameters());
holder.setInitOrder(3);
context.getServletHandler().addServlet(holder);
ServletMapping mapping = new ServletMapping();
mapping.setServletName("jsp");
mapping.setPathSpecs(new String[] { "*.jsp", "*.jspx" });
context.getServletHandler().addServletMapping(mapping);
}
use of org.eclipse.jetty.servlet.ServletMapping in project processdash by dtuma.
the class WebAppContextDashboard method initializeTextPreprocessorSupport.
private void initializeTextPreprocessorSupport() {
ServletHolder holder = new ServletHolder(new TextPreprocessingHandlerServlet());
getServletHandler().addServlet(holder);
ServletMapping map = new ServletMapping();
map.setServletName(holder.getName());
map.setPathSpecs(TextPreprocessingHandlerServlet.FILENAME_PATTERNS);
getServletHandler().addServletMapping(map);
}
use of org.eclipse.jetty.servlet.ServletMapping in project processdash by dtuma.
the class WebAppContextDashboard method initializeTinyCgiSupport.
private void initializeTinyCgiSupport() {
List<String> linkFiles = listFilesWithSuffixes(true, TinyCGIHandlerServlet.LINK_SUFFIX);
if (linkFiles.isEmpty())
return;
// strip the ".link" suffix off each filename to produce a URI
for (int i = linkFiles.size(); i-- > 0; ) {
String oneLink = linkFiles.get(i);
String oneUri = oneLink.substring(0, oneLink.length() - TinyCGIHandlerServlet.LINK_SUFFIX.length());
linkFiles.set(i, oneUri);
}
// register a servlet to handle those URIs
ServletHolder holder = new ServletHolder(new TinyCGIHandlerServlet());
getServletHandler().addServlet(holder);
ServletMapping map = new ServletMapping();
map.setServletName(holder.getName());
map.setPathSpecs(linkFiles.toArray(new String[linkFiles.size()]));
try {
PathMap.setPathSpecSeparators("!");
getServletHandler().addServletMapping(map);
} finally {
PathMap.setPathSpecSeparators(":,");
}
}
Aggregations