Search in sources :

Example 16 with ServletMapping

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);
    }
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping)

Example 17 with ServletMapping

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);
    }
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) FilterMapping(org.eclipse.jetty.servlet.FilterMapping)

Example 18 with ServletMapping

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);
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 19 with ServletMapping

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);
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Example 20 with ServletMapping

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(":,");
    }
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHolder(org.eclipse.jetty.servlet.ServletHolder)

Aggregations

ServletMapping (org.eclipse.jetty.servlet.ServletMapping)20 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)14 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Source (org.eclipse.jetty.servlet.Source)3 ConstraintAware (org.eclipse.jetty.security.ConstraintAware)2 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)2 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)2 JspConfig (org.eclipse.jetty.servlet.ServletContextHandler.JspConfig)2 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)2 Constraint (org.eclipse.jetty.util.security.Constraint)2 MetaData (org.eclipse.jetty.webapp.MetaData)2 Node (org.eclipse.jetty.xml.XmlParser.Node)2 EventListener (java.util.EventListener)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Servlet (javax.servlet.Servlet)1 ServletSecurityElement (javax.servlet.ServletSecurityElement)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1