Search in sources :

Example 6 with DispatcherType

use of javax.servlet.DispatcherType in project jetty.project by eclipse.

the class ContextHandler method checkContext.

/* ------------------------------------------------------------ */
/*
     * @see org.eclipse.jetty.server.Handler#handle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
public boolean checkContext(final String target, final Request baseRequest, final HttpServletResponse response) throws IOException {
    DispatcherType dispatch = baseRequest.getDispatcherType();
    // Check the vhosts
    if (!checkVirtualHost(baseRequest))
        return false;
    if (!checkContextPath(target))
        return false;
    // redirect null path infos
    if (!_allowNullPathInfo && _contextPath.length() == target.length() && _contextPath.length() > 1) {
        // context request must 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 false;
    }
    switch(_availability) {
        case SHUTDOWN:
        case UNAVAILABLE:
            baseRequest.setHandled(true);
            response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
            return false;
        default:
            if ((DispatcherType.REQUEST.equals(dispatch) && baseRequest.isHandled()))
                return false;
    }
    return true;
}
Also used : DispatcherType(javax.servlet.DispatcherType)

Example 7 with DispatcherType

use of javax.servlet.DispatcherType in project jetty.project by eclipse.

the class ContextHandler method doHandle.

/* ------------------------------------------------------------ */
/**
     * @see org.eclipse.jetty.server.handler.ScopedHandler#doHandle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest,
     *      javax.servlet.http.HttpServletResponse)
     */
@Override
public void doHandle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    final DispatcherType dispatch = baseRequest.getDispatcherType();
    final boolean new_context = baseRequest.takeNewContext();
    try {
        if (new_context)
            requestInitialized(baseRequest, request);
        switch(dispatch) {
            case REQUEST:
                if (isProtectedTarget(target)) {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                    baseRequest.setHandled(true);
                    return;
                }
                break;
            case ERROR:
                // If this is already a dispatch to an error page, proceed normally
                if (Boolean.TRUE.equals(baseRequest.getAttribute(Dispatcher.__ERROR_DISPATCH)))
                    break;
                // We can just call doError here.  If there is no error page, then one will
                // be generated. If there is an error page, then a RequestDispatcher will be
                // used to route the request through appropriate filters etc.
                doError(target, baseRequest, request, response);
                return;
            default:
                break;
        }
        nextHandle(target, baseRequest, request, response);
    } finally {
        if (new_context)
            requestDestroyed(baseRequest, request);
    }
}
Also used : DispatcherType(javax.servlet.DispatcherType)

Example 8 with DispatcherType

use of javax.servlet.DispatcherType in project Activiti by Activiti.

the class WebConfigurer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    log.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = null;
    if (context == null) {
        rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationConfiguration.class);
        rootContext.refresh();
    } else {
        rootContext = context;
    }
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);
    EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
    initSpring(servletContext, rootContext);
    initSpringSecurity(servletContext, disps);
    log.debug("Web application fully configured");
}
Also used : ServletContext(javax.servlet.ServletContext) DispatcherType(javax.servlet.DispatcherType) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 9 with DispatcherType

use of javax.servlet.DispatcherType in project Activiti by Activiti.

the class JPAWebConfigurer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    log.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = null;
    if (context == null) {
        rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(JPAApplicationConfiguration.class);
        rootContext.refresh();
    } else {
        rootContext = context;
    }
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);
    EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
    initSpring(servletContext, rootContext);
    initSpringSecurity(servletContext, disps);
    log.debug("Web application fully configured");
}
Also used : ServletContext(javax.servlet.ServletContext) DispatcherType(javax.servlet.DispatcherType) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Example 10 with DispatcherType

use of javax.servlet.DispatcherType in project Activiti by Activiti.

the class WebConfigurer method contextInitialized.

@Override
public void contextInitialized(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    log.debug("Configuring Spring root application context");
    AnnotationConfigWebApplicationContext rootContext = null;
    if (context == null) {
        rootContext = new AnnotationConfigWebApplicationContext();
        rootContext.register(ApplicationConfiguration.class);
        rootContext.refresh();
    } else {
        rootContext = context;
    }
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, rootContext);
    EnumSet<DispatcherType> disps = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC);
    initSpring(servletContext, rootContext);
    initSpringSecurity(servletContext, disps);
    log.debug("Web application fully configured");
}
Also used : ServletContext(javax.servlet.ServletContext) DispatcherType(javax.servlet.DispatcherType) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext)

Aggregations

DispatcherType (javax.servlet.DispatcherType)45 ServletContext (javax.servlet.ServletContext)6 ServletRequest (javax.servlet.ServletRequest)6 IOException (java.io.IOException)5 FilterMap (org.apache.catalina.deploy.FilterMap)5 ServletResponse (javax.servlet.ServletResponse)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Server (org.eclipse.jetty.server.Server)4 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)4 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)4 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)3 File (java.io.File)3 WebInitParam (javax.servlet.annotation.WebInitParam)3 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)3 Test (org.junit.Test)3 ServletFilterMapping (com.sun.enterprise.deployment.web.ServletFilterMapping)2 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)2 ManagedFilter (io.undertow.servlet.core.ManagedFilter)2 ArrayList (java.util.ArrayList)2