Java Code Examples for javax.servlet.http.HttpServletRequest.getDispatcherType()

The following are Jave code examples for showing how to use getDispatcherType() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jboot   File: JbootResourceServlet.java   View Source Code Vote up 6 votes
private String getPath(final HttpServletRequest request) {
    String servletPath;
    String pathInfo;

    if (request.getDispatcherType() == DispatcherType.INCLUDE && request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null) {
        pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
        servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
    } else {
        pathInfo = request.getPathInfo();
        servletPath = request.getServletPath();
    }
    String result = pathInfo;
    if (result == null) {
        result = CanonicalPathUtils.canonicalize(servletPath);
    } else if (resolveAgainstContextRoot) {
        result = servletPath + CanonicalPathUtils.canonicalize(pathInfo);
    } else {
        result = CanonicalPathUtils.canonicalize(result);
    }
    if ((result == null) || (result.isEmpty())) {
        result = "/";
    }
    return result;

}
 
Example 2
Project: lams   File: DefaultServlet.java   View Source Code Vote up 6 votes
private String getPath(final HttpServletRequest request) {
    String servletPath;
    String pathInfo;

    if (request.getDispatcherType() == DispatcherType.INCLUDE && request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI) != null) {
        pathInfo = (String) request.getAttribute(RequestDispatcher.INCLUDE_PATH_INFO);
        servletPath = (String) request.getAttribute(RequestDispatcher.INCLUDE_SERVLET_PATH);
    } else {
        pathInfo = request.getPathInfo();
        servletPath = request.getServletPath();
    }
    String result = pathInfo;
    if (result == null) {
        result = servletPath;
    } else if(resolveAgainstContextRoot) {
        result = servletPath + CanonicalPathUtils.canonicalize(pathInfo);
    } else {
        result = CanonicalPathUtils.canonicalize(result);
    }
    if ((result == null) || (result.equals(""))) {
        result = "/";
    }
    return result;

}
 
Example 3
Project: jboot   File: JbootResourceServlet.java   View Source Code Vote up 5 votes
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    /*
     * Where a servlet has received a POST request we still require the capability to include static content.
     */
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doPost(req, resp);
    }
}
 
Example 4
Project: jboot   File: JbootResourceServlet.java   View Source Code Vote up 5 votes
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doPut(req, resp);
    }
}
 
Example 5
Project: jboot   File: JbootResourceServlet.java   View Source Code Vote up 5 votes
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doDelete(req, resp);
    }
}
 
Example 6
Project: jboot   File: JbootResourceServlet.java   View Source Code Vote up 5 votes
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doOptions(req, resp);
    }
}
 
Example 7
Project: jboot   File: JbootResourceServlet.java   View Source Code Vote up 5 votes
@Override
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doTrace(req, resp);
    }
}
 
Example 8
Project: tomcat7   File: TestAsyncContextImpl.java   View Source Code Vote up 5 votes
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    if ("y".equals(req.getParameter(DISPATCH_CHECK))) {
        if (req.getDispatcherType() != DispatcherType.ASYNC) {
            track("WrongDispatcherType-");
        }
    }
    track("DispatchingServletGet-");
    final int iter = Integer.parseInt(req.getParameter(ITER_PARAM)) - 1;
    final AsyncContext ctxt = req.startAsync();
    if (addTrackingListener) {
        TrackingListener listener =
            new TrackingListener(completeOnError, true, null);
        ctxt.addListener(listener);
    }
    Runnable run = new Runnable() {
        @Override
        public void run() {
            if (iter > 0) {
                ctxt.dispatch("/stage1?" + ITER_PARAM + "=" + iter +
                        "&" + DISPATCH_CHECK + "=y");
            } else {
                ctxt.dispatch("/stage2");
            }
        }
    };
    if ("y".equals(req.getParameter("useThread"))) {
        new Thread(run).start();
    } else {
        run.run();
    }
}
 
Example 9
Project: lams   File: DefaultServlet.java   View Source Code Vote up 5 votes
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    /*
     * Where a servlet has received a POST request we still require the capability to include static content.
     */
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doPost(req, resp);
    }
}
 
Example 10
Project: lams   File: DefaultServlet.java   View Source Code Vote up 5 votes
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doPut(req, resp);
    }
}
 
Example 11
Project: lams   File: DefaultServlet.java   View Source Code Vote up 5 votes
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doDelete(req, resp);
    }
}
 
Example 12
Project: lams   File: DefaultServlet.java   View Source Code Vote up 5 votes
@Override
protected void doOptions(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doOptions(req, resp);
    }
}
 
Example 13
Project: lams   File: DefaultServlet.java   View Source Code Vote up 5 votes
@Override
protected void doTrace(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    switch (req.getDispatcherType()) {
        case INCLUDE:
        case FORWARD:
        case ERROR:
            doGet(req, resp);
            break;
        default:
            super.doTrace(req, resp);
    }
}
 
Example 14
Project: apache-tomcat-7.0.73-with-comment   File: TestAsyncContextImpl.java   View Source Code Vote up 5 votes
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    if ("y".equals(req.getParameter(DISPATCH_CHECK))) {
        if (req.getDispatcherType() != DispatcherType.ASYNC) {
            track("WrongDispatcherType-");
        }
    }
    track("DispatchingServletGet-");
    final int iter = Integer.parseInt(req.getParameter(ITER_PARAM)) - 1;
    final AsyncContext ctxt = req.startAsync();
    if (addTrackingListener) {
        TrackingListener listener =
            new TrackingListener(completeOnError, true, null);
        ctxt.addListener(listener);
    }
    Runnable run = new Runnable() {
        @Override
        public void run() {
            if (iter > 0) {
                ctxt.dispatch("/stage1?" + ITER_PARAM + "=" + iter +
                        "&" + DISPATCH_CHECK + "=y");
            } else {
                ctxt.dispatch("/stage2");
            }
        }
    };
    if ("y".equals(req.getParameter("useThread"))) {
        new Thread(run).start();
    } else {
        run.run();
    }
}
 
Example 15
Project: jboot   File: JbootResourceServlet.java   View Source Code Vote up 4 votes
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    String path = getPath(req);
    if (!isAllowed(path, req.getDispatcherType())) {
        resp.sendError(StatusCodes.NOT_FOUND);
        return;
    }
    if (File.separatorChar != '/') {
        //if the separator char is not / we want to replace it with a / and canonicalise
        path = CanonicalPathUtils.canonicalize(path.replace(File.separatorChar, '/'));
    }
    final Resource resource;
    //we want to disallow windows characters in the path
    if (File.separatorChar == '/' || !path.contains(File.separator)) {
        resource = resourceManager.getResource(path);
    } else {
        resource = null;
    }

    if (resource == null) {
        if (req.getDispatcherType() == DispatcherType.INCLUDE) {
            //servlet 9.3
            throw new FileNotFoundException(path);
        } else {
            resp.sendError(StatusCodes.NOT_FOUND);
        }
        return;
    } else if (resource.isDirectory()) {
        if ("css".equals(req.getQueryString())) {
            resp.setContentType("text/css");
            resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
            return;
        } else if ("js".equals(req.getQueryString())) {
            resp.setContentType("application/javascript");
            resp.getWriter().write(DirectoryUtils.Blobs.FILE_JS);
            return;
        }
        if (directoryListingEnabled) {
            StringBuilder output = DirectoryUtils.renderDirectoryListing(req.getRequestURI(), resource);
            resp.getWriter().write(output.toString());
        } else {
            resp.sendError(StatusCodes.FORBIDDEN);
        }
    } else {
        if (path.endsWith("/")) {
            //UNDERTOW-432
            resp.sendError(StatusCodes.NOT_FOUND);
            return;
        }
        serveFileBlocking(req, resp, resource);
    }
}
 
Example 16
Project: lams   File: DefaultServlet.java   View Source Code Vote up 4 votes
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    String path = getPath(req);
    if (!isAllowed(path, req.getDispatcherType())) {
        resp.sendError(StatusCodes.NOT_FOUND);
        return;
    }
    if(File.separatorChar != '/') {
        //if the separator char is not / we want to replace it with a / and canonicalise
        path = CanonicalPathUtils.canonicalize(path.replace(File.separatorChar, '/'));
    }
    final Resource resource;
    //we want to disallow windows characters in the path
    if(File.separatorChar == '/' || !path.contains(File.separator)) {
        resource = resourceManager.getResource(path);
    } else {
        resource = null;
    }

    if (resource == null) {
        if (req.getDispatcherType() == DispatcherType.INCLUDE) {
            //servlet 9.3
            throw new FileNotFoundException(path);
        } else {
            resp.sendError(StatusCodes.NOT_FOUND);
        }
        return;
    } else if (resource.isDirectory()) {
        if ("css".equals(req.getQueryString())) {
            resp.setContentType("text/css");
            resp.getWriter().write(DirectoryUtils.Blobs.FILE_CSS);
            return;
        } else if ("js".equals(req.getQueryString())) {
            resp.setContentType("application/javascript");
            resp.getWriter().write(DirectoryUtils.Blobs.FILE_JS);
            return;
        }
        if (directoryListingEnabled) {
            StringBuilder output = DirectoryUtils.renderDirectoryListing(req.getRequestURI(), resource);
            resp.getWriter().write(output.toString());
        } else {
            resp.sendError(StatusCodes.FORBIDDEN);
        }
    } else {
        if(path.endsWith("/")) {
            //UNDERTOW-432
            resp.sendError(StatusCodes.NOT_FOUND);
            return;
        }
        serveFileBlocking(req, resp, resource);
    }
}