Search in sources :

Example 21 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)

Example 22 with ServletMapping

use of org.eclipse.jetty.servlet.ServletMapping in project oozie by apache.

the class ServletMapper method mapOozieServlets.

/**
 * Maps Oozie servlets to path specs. Make sure it is in sync with FilterMapper when making changes.
 */
void mapOozieServlets() {
    mapServlet(VersionServlet.class, "/versions");
    mapServlet(V0AdminServlet.class, "/v0/admin/*");
    mapServlet(V1AdminServlet.class, "/v1/admin/*");
    mapServlet(V2AdminServlet.class, "/v2/admin/*");
    mapServlet(CallbackServlet.class, "/callback/*");
    ServletHandler servletHandler = servletContextHandler.getServletHandler();
    String v0JobsServletName = V0JobsServlet.class.getSimpleName();
    servletHandler.addServlet(new ServletHolder(v0JobsServletName, new V0JobsServlet()));
    ServletMapping jobServletMappingV0 = new ServletMapping();
    jobServletMappingV0.setPathSpec("/v0/jobs");
    jobServletMappingV0.setServletName(v0JobsServletName);
    String v1JobsServletName = V1JobsServlet.class.getSimpleName();
    servletHandler.addServlet(new ServletHolder(v1JobsServletName, new V1JobsServlet()));
    ServletMapping jobServletMappingV1 = new ServletMapping();
    jobServletMappingV1.setPathSpec("/v1/jobs");
    jobServletMappingV1.setServletName(v1JobsServletName);
    // v1 and v2 version for the jobs API are same.
    ServletMapping jobServletMappingV2 = new ServletMapping();
    jobServletMappingV2.setPathSpec("/v2/jobs");
    jobServletMappingV2.setServletName(v1JobsServletName);
    servletHandler.addServletMapping(jobServletMappingV0);
    servletHandler.addServletMapping(jobServletMappingV1);
    servletHandler.addServletMapping(jobServletMappingV2);
    mapServlet(V0JobServlet.class, "/v0/job/*");
    mapServlet(V1JobServlet.class, "/v1/job/*");
    mapServlet(V2JobServlet.class, "/v2/job/*");
    mapServlet(SLAServlet.class, "/v1/sla/*");
    mapServlet(V2SLAServlet.class, "/v2/sla/*");
    mapServlet(V2ValidateServlet.class, "/v2/validate/*");
    mapServlet(ErrorServlet.class, "/error/*");
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) V0JobsServlet(org.apache.oozie.servlet.V0JobsServlet) V1JobsServlet(org.apache.oozie.servlet.V1JobsServlet)

Example 23 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 24 with ServletMapping

use of org.eclipse.jetty.servlet.ServletMapping in project goodies by sonatype.

the class JettyServerProvider method addServlet.

public void addServlet(String pathSpec, ServletHolder servletHolder) {
    if (webappContext == null) {
        try {
            initServer();
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }
    }
    // Jetty 9.2 is sensitive to overlapping mappings, so remove it pathSpec already exists
    if (webappContext.getServletHandler().getServletMapping(pathSpec) != null) {
        final ServletMapping[] servletMappings = webappContext.getServletHandler().getServletMappings();
        final String oldServletName = webappContext.getServletHandler().getServletMapping(pathSpec).getServletName();
        ServletMapping oldServletMapping = null;
        for (ServletMapping servletMapping : servletMappings) {
            if (servletMapping.getServletName().equals(oldServletName)) {
                oldServletMapping = servletMapping;
                break;
            }
        }
        final ServletMapping[] servletMappingsOldRemoved = ArrayUtil.removeFromArray(servletMappings, oldServletMapping);
        webappContext.getServletHandler().setServletMappings(servletMappingsOldRemoved);
    }
    webappContext.getServletHandler().addServletWithMapping(servletHolder, pathSpec);
}
Also used : ServletMapping(org.eclipse.jetty.servlet.ServletMapping) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException)

Example 25 with ServletMapping

use of org.eclipse.jetty.servlet.ServletMapping in project keycloak by keycloak.

the class JettyAppServer method deploy.

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
    log.info("Deploying archive " + archive.getName());
    if (!(archive instanceof WebArchive)) {
        throw new IllegalArgumentException("JettyContainer only supports WebArchives.");
    }
    WebArchive webArchive = (WebArchive) archive;
    try {
        KeycloakAdapterApp app = appProvider.createApp(webArchive);
        WebAppContext webAppContext = (WebAppContext) app.getContextHandler();
        addAdditionalConfigurations(webAppContext);
        setContextRoot(webArchive, app, webAppContext);
        if (app.usesOIDCAuthenticator()) {
            addOIDCAuthenticator(webAppContext);
        }
        if (app.usesSAMLAuthenticator()) {
            addSAMLAuthenticator(webAppContext);
        }
        if (app.usesJaxrs()) {
            addRestEasyServlet(webArchive, webAppContext);
        }
        setEmbeddedClassloaderForDeployment(webAppContext);
        deployer.addApp(app);
        deployer.requestAppGoal(app, AppLifeCycle.STARTED);
        deployedApps.put(archive.getId(), app);
        HTTPContext httpContext = new HTTPContext(configuration.getBindAddress(), configuration.getBindHttpPort());
        ServletHandler servletHandler = webAppContext.getServletHandler();
        for (ServletHolder servlet : servletHandler.getServlets()) {
            log.debugf("Servlet context mapping: %s => %s", servlet.getName(), servlet.getContextPath());
            httpContext.add(new Servlet(servlet.getName(), servlet.getContextPath()));
        }
        if (log.isInfoEnabled()) {
            for (ServletMapping mapping : server.getChildHandlerByClass(ServletHandler.class).getServletMappings()) {
                log.debugf("Servlet mapping: %s => %s", mapping.getServletName(), Arrays.toString(mapping.getPathSpecs()));
            }
        }
        return new ProtocolMetaData().addContext(httpContext);
    } catch (Exception e) {
        throw new DeploymentException("Unable to deploy archive", e);
    }
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) ServletMapping(org.eclipse.jetty.servlet.ServletMapping) ServletHandler(org.eclipse.jetty.servlet.ServletHandler) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Aggregations

ServletMapping (org.eclipse.jetty.servlet.ServletMapping)27 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)20 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ServletHandler (org.eclipse.jetty.servlet.ServletHandler)5 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)3 Source (org.eclipse.jetty.servlet.Source)3 ConstraintAware (org.eclipse.jetty.security.ConstraintAware)2 ConstraintMapping (org.eclipse.jetty.security.ConstraintMapping)2 JspConfig (org.eclipse.jetty.servlet.ServletContextHandler.JspConfig)2 Constraint (org.eclipse.jetty.util.security.Constraint)2 MetaData (org.eclipse.jetty.webapp.MetaData)2 Node (org.eclipse.jetty.xml.XmlParser.Node)2 MalformedURLException (java.net.MalformedURLException)1 CertificateException (java.security.cert.CertificateException)1 EventListener (java.util.EventListener)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Servlet (javax.servlet.Servlet)1