Example usage for javax.servlet ServletRequest getRequestDispatcher

List of usage examples for javax.servlet ServletRequest getRequestDispatcher

Introduction

In this page you can find the example usage for javax.servlet ServletRequest getRequestDispatcher.

Prototype

public RequestDispatcher getRequestDispatcher(String path);

Source Link

Document

Returns a RequestDispatcher object that acts as a wrapper for the resource located at the given path.

Usage

From source file:se.crisp.codekvast.support.web.config.WebjarVersionFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    String requestURI = ((HttpServletRequest) request).getRequestURI();
    String expandedRequestURI = expandRequestURI(requestURI);
    if (expandedRequestURI != null) {
        log.trace("Forwarding {} to {}", requestURI, expandedRequestURI);
        request.getRequestDispatcher(expandedRequestURI).forward(request, response);
    } else {//w  ww.  j a v  a  2 s  . co  m
        chain.doFilter(request, response);
    }
}

From source file:org.acegisecurity.ui.AccessDeniedHandlerImpl.java

public void handle(ServletRequest request, ServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {
    if (errorPage != null) {
        // Put exception into request scope (perhaps of use to a view)
        ((HttpServletRequest) request).setAttribute(ACEGI_SECURITY_ACCESS_DENIED_EXCEPTION_KEY,
                accessDeniedException);/*  w ww  .j a  va 2s.com*/

        // Perform RequestDispatcher "forward"
        RequestDispatcher rd = request.getRequestDispatcher(errorPage);
        rd.forward(request, response);
    }

    if (!response.isCommitted()) {
        // Send 403 (we do this after response has been written)
        ((HttpServletResponse) response).sendError(HttpServletResponse.SC_FORBIDDEN,
                accessDeniedException.getMessage());
    }
}

From source file:com.gisgraphy.webapp.filter.MockFilterChain.java

public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
    String uri = ((HttpServletRequest) request).getRequestURI();
    String requestContext = ((HttpServletRequest) request).getContextPath();

    if (StringUtils.isNotEmpty(requestContext) && uri.startsWith(requestContext)) {
        uri = uri.substring(requestContext.length());
    }//from  www .  j a  v a 2s .co  m

    this.forwardURL = uri;
    log.debug("Forwarding to: " + uri);

    RequestDispatcher dispatcher = request.getRequestDispatcher(uri);
    dispatcher.forward(request, response);
}

From source file:org.obiba.mica.web.filter.StaticResourcesProductionFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String contextPath = httpRequest.getContextPath();
    String requestURI = httpRequest.getRequestURI();
    requestURI = StringUtils.substringAfter(requestURI, contextPath);
    if (StringUtils.equals("/", requestURI)) {
        requestURI = "/index.html";
    }/* w  w  w  . j  a  v  a2 s. c om*/
    String newURI = "/dist" + requestURI;
    request.getRequestDispatcher(newURI).forward(request, response);
}

From source file:pt.ist.bennu.core.presentationTier.servlets.filters.FunctionalityFilter.java

private void dispatchTo(final ServletRequest servletRequest, final ServletResponse servletResponse, String path)
        throws ServletException, IOException {
    final RequestDispatcher requestDispatcher = servletRequest.getRequestDispatcher(path);
    requestDispatcher.forward(servletRequest, servletResponse);
}

From source file:CheckFilter.java

private void reject(ServletRequest request, ServletResponse response) throws IOException, ServletException {

    request.setAttribute("errorMsg", "Please make sure to provide a valid value for all of the text fields.");

    Enumeration params = request.getParameterNames();
    String paramN = null;//  w ww.  ja v a2s  . c o  m

    while (params.hasMoreElements()) {

        paramN = (String) params.nextElement();

        request.setAttribute(paramN, request.getParameter(paramN));

    }

    RequestDispatcher dispatcher = request.getRequestDispatcher("/form.jsp");
    dispatcher.forward(request, response);

}

From source file:com.jiwhiz.web.filter.StaticResourcesProductionFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    String contextPath = ((HttpServletRequest) request).getContextPath();
    String requestURI = httpRequest.getRequestURI();
    requestURI = StringUtils.substringAfter(requestURI, contextPath);
    if (StringUtils.equals("/", requestURI)) {
        requestURI = "/index.html";
    }//from w  ww  . j  av  a2s . co m
    String newURI = "/dist" + requestURI;
    request.getRequestDispatcher(newURI).forward(request, response);
}

From source file:alpha.portal.webapp.filter.MockFilterChain.java

public void doFilter(final ServletRequest request, final ServletResponse response)
        throws IOException, ServletException {
    String uri = ((HttpServletRequest) request).getRequestURI();
    final String requestContext = ((HttpServletRequest) request).getContextPath();

    if (StringUtils.isNotEmpty(requestContext) && uri.startsWith(requestContext)) {
        uri = uri.substring(requestContext.length());
    }//from   www .ja va2s.  com

    this.forwardURL = uri;
    this.log.debug("Forwarding to: " + uri);

    final RequestDispatcher dispatcher = request.getRequestDispatcher(uri);
    dispatcher.forward(request, response);
}

From source file:com.confighub.api.server.filters.UrlRewriteFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws ServletException, IOException {
    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;/*from www.  ja  v  a  2s.c  o m*/
    }

    String url = ((HttpServletRequest) request).getRequestURL().toString().toLowerCase();
    URL aUrl = new URL(url);
    String path = aUrl.getPath();

    if (path.startsWith("/email-verification") || path.startsWith("/passwordReset")) {
        request.getRequestDispatcher("/index.html").forward(request, response);
        return;
    }

    if (Utils.isBlank(path) || path.equals("/") || path.equals("/index.html") || path.startsWith("/rest")) {
        try {
            chain.doFilter(request, response);
        } catch (Exception e) {
            request.getRequestDispatcher("/404.html").forward(request, response);
        }
        return;
    }

    if (path.startsWith("/r/") || path.startsWith("/account/") || path.contains("edit/file/")) {
        request.getRequestDispatcher("/index.html").forward(request, response);
        return;
    }

    boolean hasExt = Utils.isBlank(FilenameUtils.getExtension(url));

    if (!hasExt) {
        try {
            chain.doFilter(request, response);
        } catch (Exception e) {
            request.getRequestDispatcher("/404.html").forward(request, response);
        }
        return;
    }

    request.getRequestDispatcher("/index.html").forward(request, response);
}

From source file:org.eclipse.skalli.view.internal.filter.ext.GitGerritFilter.java

/**
 * Dispatch this request to error page/*from   w  w w  .  j a  v a2  s. c o m*/
 */
private void handleException(ServletRequest request, ServletResponse response, Exception e)
        throws ServletException, IOException {
    RequestDispatcher rd = request.getRequestDispatcher(Consts.URL_ERROR);
    request.setAttribute(ATTRIBUTE_EXCEPTION, e);
    rd.forward(request, response);
}