Example usage for javax.servlet DispatcherType REQUEST

List of usage examples for javax.servlet DispatcherType REQUEST

Introduction

In this page you can find the example usage for javax.servlet DispatcherType REQUEST.

Prototype

DispatcherType REQUEST

To view the source code for javax.servlet DispatcherType REQUEST.

Click Source Link

Usage

From source file:org.cryptomator.frontend.webdav.WebDavServletContextFactory.java

/**
 * Creates a new Jetty ServletContextHandler, that can be be added to a servletCollection as follows:
 * /*from   ww w .j  a va 2  s  .c o  m*/
 * <pre>
 * ServletContextHandler context = factory.create(...);
 * servletCollection.addHandler(context);
 * servletCollection.mapContexts();
 * </pre>
 * 
 * @param contextRoot The URI of the context root. Its path will be used as the servlet's context path.
 * @param root The location within a filesystem that shall be served via WebDAV.
 * @return A new Jetty servlet context handler.
 */
public ServletContextHandler create(URI contextRoot, Folder root) {
    final ResourceTypeChecker resourceTypeChecker = (path) -> {
        if (root.resolveFolder(path).exists()) {
            return ResourceType.FOLDER;
        } else if (root.resolveFile(path).exists()) {
            return ResourceType.FILE;
        } else {
            return ResourceType.UNKNOWN;
        }
    };
    final String contextPath = StringUtils.removeEnd(contextRoot.getPath(), "/");
    final ServletContextHandler servletContext = new FontendIdHidingServletContextHandler(null, contextPath,
            ServletContextHandler.SESSIONS);
    final ServletHolder servletHolder = new ServletHolder(contextPath, new WebDavServlet(contextRoot, root));
    servletContext.addServlet(servletHolder, WILDCARD);
    servletContext.addFilter(LoopbackFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST));
    servletContext.addFilter(PostRequestBlockingFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST));
    servletContext.addFilter(MkcolComplianceFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST));
    servletContext.addFilter(AcceptRangeFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST));
    servletContext.addFilter(new FilterHolder(new UriNormalizationFilter(resourceTypeChecker)), WILDCARD,
            EnumSet.of(DispatcherType.REQUEST));
    if (SystemUtils.IS_OS_MAC_OSX) {
        servletContext.addFilter(MacChunkedPutCompatibilityFilter.class, WILDCARD,
                EnumSet.of(DispatcherType.REQUEST));
    }
    return servletContext;
}

From source file:org.eclipse.gyrex.http.jetty.internal.app.ApplicationHandler.java

@Override
public void doScope(String target, final Request baseRequest, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException, ServletException {

    /*/*from   ww  w  . j  a  va 2  s .  co  m*/
     * IMPLEMENTATION NOTE
     *
     * This method is overridden to customize the path handling.
     *
     * Normally, a ContextHandler has a context path. However, the ApplicationHandler
     * must inherit the context path from the calling ApplicationHandlerCollection because
     * it changes depending on the incoming url.
     *
     * Additionally, class loader handling has been disabled in order to rely on the Equinox default.
     */

    // note, we do not support requests going through different contexts
    final ContextHandler.Context origContext = baseRequest.getContext();
    if ((origContext != null) && (origContext != _scontext))
        throw new IllegalStateException(
                "origContext != this context, nesting/cross-application routing not supported!");

    // backup paths
    final String origContextPath = baseRequest.getContextPath();
    final String origServletPath = baseRequest.getServletPath();
    final String origPathInfo = baseRequest.getPathInfo();

    // if the current context is not set, we need to set and restore
    final boolean newContext = (origContext == null) || (currentContextPath.get() == null);

    // set 'current' context path if not already set
    if (newContext) {
        // note, we rely on ApplicationHandlerCollection to pre-set the
        // correct context path on the request
        currentContextPath.set(baseRequest.getContextPath());
    }
    try {
        final String contextPath = currentContextPath.get();
        String pathInfo = null;

        final DispatcherType dispatch = baseRequest.getDispatcherType();

        // Are we already in this context?
        if (newContext) {
            // check the target
            if (DispatcherType.REQUEST.equals(dispatch) || DispatcherType.ASYNC.equals(dispatch)) {

                // perform checkContext to support unavailable status
                if (!checkContext(target, baseRequest, response))
                    return;

                // only accept requests coming through ApplicationHandlerCollection
                if (contextPath == null)
                    return;

                // calculate paths
                if (target.length() > contextPath.length()) {
                    if (contextPath.length() > 1) {
                        target = target.substring(contextPath.length());
                    }
                    pathInfo = target;
                } else if (contextPath.length() == 1) {
                    target = URIUtil.SLASH;
                    pathInfo = URIUtil.SLASH;
                } else {
                    // redirect null path infos in order to have context request end with /
                    baseRequest.setHandled(true);
                    if (baseRequest.getQueryString() != null) {
                        response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(), URIUtil.SLASH) + "?"
                                + baseRequest.getQueryString());
                    } else {
                        response.sendRedirect(URIUtil.addPaths(baseRequest.getRequestURI(), URIUtil.SLASH));
                    }
                    return;
                }
            }
        } else {
            // calculate paths for forwarded requests
            // (note, handle error dispatches like forwards for custom error handler support)
            if ((DispatcherType.FORWARD.equals(dispatch) || DispatcherType.ERROR.equals(dispatch))
                    && target.startsWith(URIUtil.SLASH)) {
                pathInfo = target;
            }
        }

        // update the paths
        baseRequest.setContext(_scontext);
        if (!DispatcherType.INCLUDE.equals(dispatch) && target.startsWith(URIUtil.SLASH)) {
            if (contextPath.length() == 1) {
                baseRequest.setContextPath(EMPTY_STRING);
            } else {
                baseRequest.setContextPath(contextPath);
            }
            baseRequest.setServletPath(null);
            baseRequest.setPathInfo(pathInfo);
        }

        // set application handler debug info reference
        if (showDebugInfo) {
            final StringBuilder dump = new StringBuilder();
            dump(dump);
            baseRequest.setAttribute(ATTRIBUTE_DEBUG_INFO, dump.toString());
        }

        // next scope
        // start manual inline of nextScope(target,baseRequest,request,response);
        if (never()) {
            nextScope(target, baseRequest, request, response);
        } else if (_nextScope != null) {
            _nextScope.doScope(target, baseRequest, request, response);
        } else if (_outerScope != null) {
            _outerScope.doHandle(target, baseRequest, request, response);
        } else {
            doHandle(target, baseRequest, request, response);
        } // end manual inline (pathetic attempt to reduce stack depth)
    } finally {
        if (newContext) {
            // reset the context and servlet path
            baseRequest.setContext(origContext);
            baseRequest.setContextPath(origContextPath);
            baseRequest.setServletPath(origServletPath);
            baseRequest.setPathInfo(origPathInfo);
            currentContextPath.set(null);
        }
    }

}

From source file:org.eclipse.gyrex.http.jetty.internal.app.ApplicationHandlerCollection.java

@Override
public void handle(final String target, final Request baseRequest, final HttpServletRequest request,
        final HttpServletResponse response) throws IOException, ServletException {
    // don't do anything if already processed
    if (response.isCommitted() || baseRequest.isHandled())
        return;/*from  ww w  .j av a  2s  .c  o m*/

    final Iterator<Handler> handlers = this.handlers.iterator();
    if (!handlers.hasNext())
        return;

    final ThroughputMetric requestsMetric = metrics.getRequestsMetric();
    final long requestStart = requestsMetric.requestStarted();
    try {
        doHandle(target, baseRequest, request, response);
        if (response instanceof Response) {
            final int status = ((Response) response).getStatus();
            if (HttpStatus.isServerError(status)) {
                metrics.getRequestsMetric().requestFailed();
                metrics.error(status, ((Response) response).getReason());
            } else {
                metrics.getRequestsMetric().requestFinished(((Response) response).getContentCount(),
                        System.currentTimeMillis() - requestStart);
            }
        } else {
            metrics.getRequestsMetric().requestFinished(0, System.currentTimeMillis() - requestStart);
        }
    } catch (final EofException | RuntimeIOException | ContinuationThrowable e) {
        metrics.getRequestsMetric().requestFailed();
        throw e;
    } catch (final Exception e) {
        metrics.getRequestsMetric().requestFailed();

        final DispatcherType type = baseRequest.getDispatcherType();
        if (!(DispatcherType.REQUEST.equals(type) || DispatcherType.ASYNC.equals(type))) {
            if (e instanceof IOException)
                throw (IOException) e;
            if (e instanceof RuntimeException)
                throw (RuntimeException) e;
            if (e instanceof ServletException)
                throw (ServletException) e;
        }

        // handle or log exception
        else if (e instanceof RuntimeIOException)
            throw (RuntimeIOException) e;
        else if (e instanceof EofException)
            throw (EofException) e;
        else if ((e instanceof IOException) || (e instanceof UnavailableException)
                || (e instanceof IllegalStateException)) {
            if (Platform.inDebugMode()) {
                LOG.debug("Exception processing request {}: {}", request.getRequestURI(),
                        ExceptionUtils.getMessage(e), e);
                LOG.debug(request.toString());
            }
        } else {
            LOG.error("Exception processing request {}: {}",
                    new Object[] { request.getRequestURI(), ExceptionUtils.getRootCauseMessage(e), e });
            if (Platform.inDebugMode()) {
                LOG.debug(request.toString());
            }
        }

        // send error response if possible
        if (!response.isCommitted()) {
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, e.getClass());
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
            if (e instanceof UnavailableException) {
                final UnavailableException ue = (UnavailableException) e;
                if (ue.isPermanent()) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
                } else {
                    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, e.getMessage());
                }
            } else if (e instanceof IllegalStateException) {
                response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, e.getMessage());
            } else {
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
            }
        } else {
            // give up
            if (JettyDebug.debug) {
                LOG.debug("Response already committed for handling {}", ExceptionUtils.getMessage(e));
            }
        }
    } catch (final Error e) {
        metrics.getRequestsMetric().requestFailed();

        // only handle some errors
        if (!((e instanceof LinkageError) || (e instanceof AssertionError)))
            throw e;

        final DispatcherType type = baseRequest.getDispatcherType();
        if (!(DispatcherType.REQUEST.equals(type) || DispatcherType.ASYNC.equals(type)))
            throw e;

        LOG.error("Error processing request {}: {}",
                new Object[] { request.getRequestURI(), ExceptionUtils.getRootCauseMessage(e), e });
        if (JettyDebug.debug) {
            LOG.debug(request.toString());
        }

        // TODO httpResponse.getHttpConnection().forceClose();
        if (!response.isCommitted()) {
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE, e.getClass());
            request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        } else {
            if (JettyDebug.debug) {
                LOG.debug("Response already committed for handling {}", ExceptionUtils.getMessage(e));
            }
        }
    }
}

From source file:org.glite.security.voms.admin.core.VOMSService.java

private static void configureOrgDbHibernateSessionFitler(ServletContext ctxt) {
    if (!VOMSConfiguration.instance().getRegistrationType().equals(OrgDBConfigurator.ORGDB_REGISTRATION_TYPE)) {
        return;//from www .j  a v  a2  s . c  o  m
    }

    FilterRegistration.Dynamic fr = ctxt.addFilter("orgdb-hibernate-session-filter",
            OrgDbHibernateSessionFilter.class);

    fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "*");

}

From source file:org.ireland.jnetty.webapp.RequestDispatcherImpl.java

private void doDispatch(HttpServletRequest request, HttpServletResponse response, HttpInvocation invocation)
        throws ServletException, IOException {

    // ,responsebuffer,TODO: need resetBuffer()?
    response.resetBuffer();/*from  ww w  .j a  v  a 2s  .c o m*/

    // Set the invocation into HttpServlerRequestImpl
    if (request instanceof HttpServletRequestImpl) {
        ((HttpServletRequestImpl) request).setInvocation(_dispatchInvocation);
        ((HttpServletRequestImpl) request).setDispatcherType(DispatcherType.REQUEST);
    }

    boolean isValid = false;

    try {

        invocation.getFilterChainInvocation().service(request, response);
        isValid = true;
    } finally {
        if (request.getAsyncContext() != null) {
            // An async request was started during the forward, don't close the
            // response as it may be written to during the async handling
            return;
        }

        // server/106r, ioc/0310
        if (isValid) {
            finishResponse(response);
        }
    }
}

From source file:org.italiangrid.voms.container.VOMSAppProvider.java

protected ContextHandler configureVOMSES() {

    String webappResourceDir = this.getClass().getClassLoader().getResource("status-webapp").toExternalForm();

    WebAppContext statusContext = new WebAppContext();

    statusContext.setContextPath("/");
    statusContext.setResourceBase(webappResourceDir);
    statusContext.setCompactPath(true);/*from ww  w  . j av  a 2s .co  m*/

    statusContext.setParentLoaderPriority(true);

    statusContext.setInitParameter("host", hostname);
    statusContext.setInitParameter("confdir", configurationDir);
    statusContext
            .setConnectorNames(new String[] { Container.HTTP_CONNECTOR_NAME, Container.HTTPS_CONNECTOR_NAME });

    VOMSStatusFilter f = new VOMSStatusFilter(deploymentManager, hostname, port);
    FilterHolder fh = new FilterHolder(f);

    statusContext.addFilter(fh, "/*", EnumSet.of(DispatcherType.FORWARD, DispatcherType.REQUEST));

    statusContext.setThrowUnavailableOnStartupException(true);
    statusContext.addLifeCycleListener(new VOMSESListener());

    return statusContext;
}

From source file:org.lightjason.trafficsimulation.ui.CHTTPServer.java

/**
 * ctor//from   w w  w  .  j  a  v  a  2s  .c o  m
 */
private CHTTPServer() {
    // web context definition
    final WebAppContext l_webapp = new WebAppContext();

    // server process
    m_server = new Server(new InetSocketAddress(
            CConfiguration.INSTANCE.<String>getOrDefault("localhost", "httpserver", "host"),
            CConfiguration.INSTANCE.<Integer>getOrDefault(8000, "httpserver", "port")));

    // set server / webapp connection
    m_server.setHandler(l_webapp);
    l_webapp.setServer(m_server);
    l_webapp.setContextPath("/");
    l_webapp.setWelcomeFiles(new String[] { "index.html", "index.htm" });
    l_webapp.setResourceBase(CHTTPServer.class
            .getResource(MessageFormat.format("{0}{1}{2}", "/", CCommon.PACKAGEPATH, "html")).toExternalForm());
    l_webapp.addServlet(new ServletHolder(new ServletContainer(m_restagent)), "/rest/*");
    l_webapp.addFilter(new FilterHolder(new CrossOriginFilter()), "/rest/*",
            EnumSet.of(DispatcherType.REQUEST));
}

From source file:org.openspaces.core.space.RestBean.java

@Override
public void afterPropertiesSet() throws Exception {
    int runningNumber = clusterInfo.getRunningNumber();
    try {//from  w w w  .ja v a  2  s .c  o m
        jettyPort = Integer.valueOf(this.port);
    } catch (NumberFormatException e) {
        throw new CannotCreateContainerException("Port should be number");
    }
    jettyPort += runningNumber;
    server = new Server();
    server.setStopAtShutdown(true);
    server.setGracefulShutdown(1000);

    SelectChannelConnector connector = new SelectChannelConnector();
    connector.setPort(jettyPort);
    server.setConnectors(new Connector[] { connector });

    String ispaceName, igroups, ilocators;

    if (gigaspace == null && spaceName == null) {
        throw new CannotCreateContainerException(
                "Either giga-space or space-name attribute should be specified.");
    }
    if (gigaspace != null && spaceName != null) {
        throw new CannotCreateContainerException(
                "Either giga-space or space-name attribute can be specified but not both.");
    }

    if (spaceName != null) {
        ispaceName = spaceName;
        //TODO validate groups and locators ?
        igroups = (groups == null ? null : groups);
        ilocators = (locators == null ? null : locators);
    } else {
        IJSpace space = gigaspace.getSpace();
        ispaceName = space.getName();
        String[] lookupgroups = space.getFinderURL().getLookupGroups();
        if (lookupgroups == null || lookupgroups.length == 0) {
            igroups = null;
        } else {
            igroups = StringUtils.join(lookupgroups, ",", 0, lookupgroups.length);
        }

        LookupLocator[] lookuplocators = space.getFinderURL().getLookupLocators();
        if (lookuplocators == null || lookuplocators.length == 0) {
            ilocators = null;
        } else {
            ilocators = "";
            for (int i = 0; i < lookuplocators.length; i++) {
                ilocators += lookuplocators[i].getHost() + ":" + lookuplocators[i].getPort();
                if (i != (lookuplocators.length - 1)) {
                    ilocators += ",";
                }
            }
        }
    }

    logger.info("Starting REST service on port [" + jettyPort + "]");
    webAppContext = new WebAppContext();
    filterHolder = new FilterHolder(RequestStatisticsFilter.class);
    webAppContext.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.INCLUDE, DispatcherType.REQUEST));
    webAppContext.setContextPath("/");
    webAppContext.setWar(SystemInfo.singleton().locations().lib() + "/optional/rest/xap-rest.war");
    webAppContext.setInitParameter("port", port);
    webAppContext.setInitParameter("spaceName", ispaceName);
    if (igroups != null && !igroups.equalsIgnoreCase("null")) {
        logger.debug("Applying groups " + igroups);
        webAppContext.setInitParameter("lookupGroups", igroups);
    }

    if (ilocators != null && !ilocators.equalsIgnoreCase("null")) {
        logger.debug("Applying locators " + ilocators);
        webAppContext.setInitParameter("lookupLocators", ilocators);
    }

    if (properties != null && properties.getProperty("datetime_format") != null) {
        webAppContext.setInitParameter("datetime_format", properties.getProperty("datetime_format"));
    }

    server.setHandler(webAppContext);
    try {
        server.start();
        jettyStarted = true;
        logger.info("REST service is started");
    } catch (Exception e) {
        logger.error("Unable to start rest service on port [" + jettyPort + "]", e);
        throw new CannotCreateContainerException("Unable to start rest server on port [" + jettyPort + "]", e);
    }
}

From source file:org.overlord.gadgets.server.devsvr.GadgetDevServer.java

/**
 * @see org.overlord.commons.dev.server.DevServer#addModulesToJetty(org.overlord.commons.dev.server.DevServerEnvironment, org.eclipse.jetty.server.handler.ContextHandlerCollection)
 *//*from www . j  av  a  2s  . co m*/
@Override
protected void addModulesToJetty(DevServerEnvironment environment, ContextHandlerCollection handlers)
        throws Exception {
    URL[] clURLs = new URL[] {
            new File(environment.getModuleDir("gadget-server"), "WEB-INF/classes").toURI().toURL() };
    // Set up the classloader.
    ClassLoader cl = new URLClassLoader(clURLs, GadgetDevServer.class.getClassLoader());
    Thread.currentThread().setContextClassLoader(cl);

    /* *********
     * gadgets
     * ********* */
    ServletContextHandler gadgets = new ServletContextHandler(ServletContextHandler.SESSIONS);
    gadgets.setContextPath("/gadgets");
    gadgets.setResourceBase(environment.getModuleDir("gadgets").getCanonicalPath());
    // File resources
    ServletHolder resources = new ServletHolder(new DefaultServlet());
    resources.setInitParameter("dirAllowed", "true");
    resources.setInitParameter("pathInfoOnly", "false");
    gadgets.addServlet(resources, "/");

    /* *********
     * gadget-web
     * ********* */
    System.setProperty("shindig.host", "");
    System.setProperty("shindig.port", "");
    System.setProperty("aKey", "/shindig/gadgets/proxy?container=default&url=");
    ServletContextHandler gadgetWeb = new ServletContextHandler(ServletContextHandler.SESSIONS);
    gadgetWeb.setInitParameter("guice-modules", GUICE_MODULES);
    gadgetWeb.setInitParameter("resteasy.servlet.mapping.prefix", "/rs");
    gadgetWeb.setContextPath("/gadget-web");
    gadgetWeb.setWelcomeFiles(new String[] { "Application.html" });
    //        gadgetServer.setResourceBase(environment.getModuleDir("gadget-server").getCanonicalPath());
    gadgetWeb.addEventListener(new GuiceServletContextListener());
    gadgetWeb.addEventListener(new ShindigResteasyBootstrapServletContextListener());
    // JSONP filter
    gadgetWeb.addFilter(JSONPFilter.class, "/rs/*", EnumSet.of(DispatcherType.REQUEST));
    // HostFilter
    gadgetWeb.addFilter(HostFilter.class, "/gadgets/ifr", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(HostFilter.class, "/gadgets/js/*", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(HostFilter.class, "/gadgets/proxy/*", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(HostFilter.class, "/gadgets/concat", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(HostFilter.class, "/gadgets/makeRequest", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(HostFilter.class, "/rpc/*", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(HostFilter.class, "/rest/*", EnumSet.of(DispatcherType.REQUEST));
    // ShiroFilter
    FilterHolder shiroFilter = new FilterHolder(IniShiroFilter.class);
    shiroFilter.setInitParameter("config", SHIRO_CONFIG);
    gadgetWeb.addFilter(shiroFilter, "/oauth/authorize", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(shiroFilter, "/oauth2/authorize", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(shiroFilter, "*.jsp", EnumSet.of(DispatcherType.REQUEST));
    // AuthFilter
    gadgetWeb.addFilter(AuthenticationServletFilter.class, "/gadgets/ifr", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(AuthenticationServletFilter.class, "/gadgets/js/*", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(AuthenticationServletFilter.class, "/gadgets/proxy/*",
            EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(AuthenticationServletFilter.class, "/gadgets/concat",
            EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(AuthenticationServletFilter.class, "/gadgets/makeRequest",
            EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(AuthenticationServletFilter.class, "/rpc/*", EnumSet.of(DispatcherType.REQUEST));
    gadgetWeb.addFilter(AuthenticationServletFilter.class, "/rest/*", EnumSet.of(DispatcherType.REQUEST));
    // EtagFilter
    gadgetWeb.addFilter(ETagFilter.class, "*", EnumSet.of(DispatcherType.REQUEST));
    // Servlets
    gadgetWeb.addServlet(GadgetRenderingServlet.class, "/gadgets/ifr");
    gadgetWeb.addServlet(HtmlAccelServlet.class, "/gadgets/accel");
    gadgetWeb.addServlet(ProxyServlet.class, "/gadgets/proxy/*");
    gadgetWeb.addServlet(MakeRequestServlet.class, "/gadgets/makeRequest");
    gadgetWeb.addServlet(ConcatProxyServlet.class, "/gadgets/concat");
    gadgetWeb.addServlet(OAuthCallbackServlet.class, "/gadgets/oauthcallback");
    gadgetWeb.addServlet(OAuth2CallbackServlet.class, "/gadgets/oauth2callback");
    gadgetWeb.addServlet(RpcServlet.class, "/gadgets/metadata");
    gadgetWeb.addServlet(JsServlet.class, "/gadgets/js/*");
    ServletHolder servletHolder = new ServletHolder(DataServiceServlet.class);
    servletHolder.setInitParameter("handlers", "org.apache.shindig.handlers");
    gadgetWeb.addServlet(servletHolder, "/rest/*");
    gadgetWeb.addServlet(servletHolder, "/gadgets/api/rest/*");
    gadgetWeb.addServlet(servletHolder, "/social/rest/*");
    servletHolder = new ServletHolder(JsonRpcServlet.class);
    servletHolder.setInitParameter("handlers", "org.apache.shindig.handlers");
    gadgetWeb.addServlet(servletHolder, "/rpc/*");
    gadgetWeb.addServlet(servletHolder, "/gadgets/api/rpc/*");
    gadgetWeb.addServlet(servletHolder, "/social/rpc/*");
    gadgetWeb.addServlet(SampleOAuthServlet.class, "/oauth/*");
    gadgetWeb.addServlet(OAuth2Servlet.class, "/oauth2/*");
    gadgetWeb.addServlet(RpcSwfServlet.class, "/xpc*");
    gadgetWeb.addServlet(HttpServletDispatcher.class, "/rs/*");
    // Service Overview REST service proxy servlet
    ServletHolder soProxyServlet = gadgetWeb.addServlet(RestProxyServlet.class, "/service/dependency/overview");
    soProxyServlet.setInitParameter("proxy-name", "service-overview");
    soProxyServlet.setInitParameter("proxy-url",
            "SCHEME://HOST:PORT/overlord-rtgov/service/dependency/overview");
    // Overlord Header JS servlet
    ServletHolder overlordHeaderJS = new ServletHolder(OverlordHeaderDataJS.class);
    overlordHeaderJS.setInitParameter("app-id", "gadget-server");
    gadgetWeb.addServlet(overlordHeaderJS, "/js/overlord-header-data.js");
    // File resources
    resources = new ServletHolder(new MultiDefaultServlet());
    resources.setInitParameter("resourceBase", "/");
    resources.setInitParameter("resourceBases",
            environment.getModuleDir("gadget-web").getCanonicalPath() + "|"
                    + environment.getModuleDir("gadget-server").getCanonicalPath() + "|"
                    + environment.getModuleDir("overlord-commons-uiheader").getCanonicalPath());
    resources.setInitParameter("dirAllowed", "true");
    resources.setInitParameter("pathInfoOnly", "false");
    gadgetWeb.addServlet(resources, "/");
    gadgetWeb.setSecurityHandler(createSecurityHandler());

    /* *********
     * rtgov mock
     * ********* */
    ServletContextHandler rtgov = new ServletContextHandler(ServletContextHandler.SESSIONS);
    rtgov.setContextPath("/overlord-rtgov");
    rtgov.setResourceBase(environment.getModuleDir("gadgets").getCanonicalPath());
    rtgov.addServlet(OverlordRTGovMockServlet.class, "/");
    rtgov.setSecurityHandler(createRtGovSecurityHandler());

    // Add the web contexts to jetty
    handlers.addHandler(gadgets);
    handlers.addHandler(gadgetWeb);
    handlers.addHandler(rtgov);
}

From source file:org.overlord.sramp.devsvr.SrampDevServer.java

/**
 * @see org.overlord.commons.dev.server.DevServer#addModulesToJetty(org.overlord.commons.dev.server.DevServerEnvironment, org.eclipse.jetty.server.handler.ContextHandlerCollection)
 *//*from   w w w  . j  a v a  2s . c o  m*/
@Override
protected void addModulesToJetty(DevServerEnvironment environment, ContextHandlerCollection handlers)
        throws Exception {
    super.addModulesToJetty(environment, handlers);

    /* *********
     * S-RAMP UI
     * ********* */
    ServletContextHandler srampUI = new ServletContextHandler(ServletContextHandler.SESSIONS);
    srampUI.setSecurityHandler(createSecurityHandler(true));
    srampUI.setContextPath("/s-ramp-ui");
    srampUI.setWelcomeFiles(new String[] { "index.html" });
    srampUI.setResourceBase(environment.getModuleDir("s-ramp-ui").getCanonicalPath());
    srampUI.addFilter(GWTCacheControlFilter.class, "/app/*", EnumSet.of(DispatcherType.REQUEST));
    srampUI.addFilter(GWTCacheControlFilter.class, "/rest/*", EnumSet.of(DispatcherType.REQUEST));
    srampUI.addFilter(GWTCacheControlFilter.class, "/", EnumSet.of(DispatcherType.REQUEST));
    srampUI.addFilter(GWTCacheControlFilter.class, "*.html", EnumSet.of(DispatcherType.REQUEST));
    srampUI.addFilter(ResourceCacheControlFilter.class, "/css/*", EnumSet.of(DispatcherType.REQUEST));
    srampUI.addFilter(ResourceCacheControlFilter.class, "/images/*", EnumSet.of(DispatcherType.REQUEST));
    srampUI.addFilter(ResourceCacheControlFilter.class, "/js/*", EnumSet.of(DispatcherType.REQUEST));
    srampUI.addFilter(org.overlord.sramp.ui.server.filters.LocaleFilter.class, "/*",
            EnumSet.of(DispatcherType.REQUEST));

    // Servlets
    srampUI.addServlet(new ServletHolder(ArtifactUploadServlet.class), "/app/services/artifactUpload");
    srampUI.addServlet(new ServletHolder(ArtifactDownloadServlet.class), "/app/services/artifactDownload");
    srampUI.addServlet(new ServletHolder(OntologyUploadServlet.class), "/app/services/ontologyUpload");
    srampUI.addServlet(new ServletHolder(OntologyDownloadServlet.class), "/app/services/ontologyDownload");
    srampUI.addServlet(new ServletHolder(KeyCloakLogoutServlet.class), "/app/services/logout");
    ServletHolder resteasyUIServlet = new ServletHolder(new HttpServletDispatcher());
    resteasyUIServlet.setInitParameter("javax.ws.rs.Application", JettySRAMPApplication.class.getName());
    resteasyUIServlet.setInitParameter("resteasy.servlet.mapping.prefix", "/rest");
    srampUI.addServlet(resteasyUIServlet, "/rest/*");
    // File resources
    ServletHolder resources = new ServletHolder(new MultiDefaultServlet());
    resources.setInitParameter("resourceBase", "/");
    resources.setInitParameter("resourceBases", environment.getModuleDir("s-ramp-ui").getCanonicalPath());
    resources.setInitParameter("dirAllowed", "true");
    resources.setInitParameter("pathInfoOnly", "false");
    String[] fileTypes = new String[] { "html", "js", "css", "png", "gif" };
    for (String fileType : fileTypes) {
        srampUI.addServlet(resources, "*." + fileType);
    }

    /* *************
     * S-RAMP server
     * ************* */
    ServletContextHandler srampServer = new ServletContextHandler(ServletContextHandler.SESSIONS);
    srampServer.setSecurityHandler(createSecurityHandler(false));
    srampServer.setContextPath("/s-ramp-server");
    srampServer.addEventListener(new SrampLifeCycle());
    ServletHolder resteasyServerServlet = new ServletHolder(new HttpServletDispatcher());
    resteasyServerServlet.setInitParameter("javax.ws.rs.Application", SRAMPApplication.class.getName());
    srampServer.addServlet(resteasyServerServlet, "/s-ramp/*");
    //maven repository servlet:
    ServletHolder mvnServlet = new ServletHolder(new MavenFacadeServlet());
    srampServer.addServlet(mvnServlet, "/maven/repository/*");
    srampServer.addServlet(mvnServlet, "/maven/repository");
    // TODO enable JSP support to test the repository listing

    srampServer.addFilter(BasicAuthFilter.class, "/s-ramp/*", EnumSet.of(DispatcherType.REQUEST))
            .setInitParameter("allowedIssuers", "/s-ramp-ui,/dtgov,/dtgov-ui");
    srampServer
            .addFilter(MavenRepositoryAuthFilter.class, "/maven/repository/*",
                    EnumSet.of(DispatcherType.REQUEST))
            .setInitParameter("allowedIssuers", "/s-ramp-ui,/dtgov,/dtgov-ui");
    srampServer.addFilter(LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    srampServer.addFilter(ServletCredentialsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));

    // Add to handlers
    handlers.addHandler(srampUI);
    handlers.addHandler(srampServer);
}