Example usage for javax.servlet FilterChain doFilter

List of usage examples for javax.servlet FilterChain doFilter

Introduction

In this page you can find the example usage for javax.servlet FilterChain doFilter.

Prototype

public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;

Source Link

Document

Causes the next filter in the chain to be invoked, or if the calling filter is the last filter in the chain, causes the resource at the end of the chain to be invoked.

Usage

From source file:com.bsb.cms.commons.page.filter.PageFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest hRequest = (HttpServletRequest) request;
    String uri = hRequest.getRequestURL().toString();
    if (uri.toLowerCase().endsWith(".jsp")) {
        chain.doFilter(request, response);
        return;/*from  ww w. j a  v a2 s  .  c  o m*/
    }
    /*  if (!(uri.toLowerCase().endsWith("list.htm"))) {//TODO
      //if (!(uri.toLowerCase().contains("list"))) {//TODO
        PageContext.removeContext();
        chain.doFilter(request, response);
        return;
      }*/
    if (!(uri.equals(PageContext.getLastUrl())))
        PageContext.removeContext();

    String pagec = hRequest.getParameter("page");//?
    //String pageSize = hRequest.getParameter("pageSize");//??
    String pageSize = hRequest.getParameter("rows");//??. easyui

    String sortField = hRequest.getParameter("sort");//sortField
    String order = hRequest.getParameter("order");//desc/asc

    pageSize = (StringUtils.isEmpty(pageSize)) ? "10" : pageSize;
    PageContext.setLastUrl(uri);
    PageContext page = PageContext.getContext();//-----------

    if (pagec == null)
        page.setCurrentPage(1);
    else
        page.setCurrentPage(Integer.parseInt(pagec));

    page.setPageSize(Integer.parseInt(pageSize));
    page.setPagination(true);

    if ("DESC".equalsIgnoreCase(order)) {
        page.setSortDESC(true);
    } else if ("ASC".equalsIgnoreCase(order)) {
        page.setSortDESC(false);
    }
    if ((sortField != null) && (!("".equals(sortField))))
        PageContext.initSort(sortField);

    request.setAttribute("page", page);//-----------------
    chain.doFilter(request, response);

}

From source file:eu.openanalytics.rpooli.web.BaseUriInjectionFilter.java

@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {
    final HttpServletRequest req = (HttpServletRequest) request;
    final String baseUri = StringUtils.replace(req.getRequestURL().toString(), req.getRequestURI(),
            req.getContextPath());/*from www .java 2s .c  o  m*/
    request.setAttribute("baseUri", baseUri);

    chain.doFilter(request, response);
}

From source file:org.apereo.openlrs.XAPIRequestValidationFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    String versionHeader = request.getHeader(Constants.XAPI_VERSION_HEADER);

    if (StringUtils.isNotBlank(versionHeader)) {
        // for now we are just checking for the header
        // in the future we'll deal with specific versioning checking
        filterChain.doFilter(request, response);
    } else {//w  w  w.j  av  a 2s  . c o m
        log.warn("Request missing XAPI VERSION HEADER");
        response.sendError(400, "Missing " + Constants.XAPI_VERSION_HEADER + " Header");
    }

}

From source file:com.corejsf.UploadFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    //System.out.println("**** doFilter #1");
    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;//from  w w  w. j av  a  2 s  .c  om
    }

    //System.out.println("**** doFilter #2");
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    boolean isMultipartContent = FileUpload.isMultipartContent(httpRequest);
    if (!isMultipartContent) {
        chain.doFilter(request, response);
        return;
    }

    //System.out.println("**** doFilter #3");
    DiskFileUpload upload = new DiskFileUpload();
    if (repositoryPath != null)
        upload.setRepositoryPath(repositoryPath);

    try {
        List list = upload.parseRequest(httpRequest);
        final Map map = new HashMap();
        for (int i = 0; i < list.size(); i++) {
            FileItem item = (FileItem) list.get(i);
            //System.out.println("form filed="+item.getFieldName()+" : "+str);
            if (item.isFormField()) {
                String str = item.getString("UTF-8");
                map.put(item.getFieldName(), new String[] { str });
            } else {
                httpRequest.setAttribute(item.getFieldName(), item);
            }
        }

        chain.doFilter(new HttpServletRequestWrapper(httpRequest) {
            public Map getParameterMap() {
                return map;
            }

            // busywork follows ... should have been part of the wrapper
            public String[] getParameterValues(String name) {
                Map map = getParameterMap();
                return (String[]) map.get(name);
            }

            public String getParameter(String name) {
                String[] params = getParameterValues(name);
                if (params == null)
                    return null;
                return params[0];
            }

            public Enumeration getParameterNames() {
                Map map = getParameterMap();
                return Collections.enumeration(map.keySet());
            }
        }, response);
    } catch (FileUploadException ex) {
        log.error(ex.getMessage());
        ServletException servletEx = new ServletException();
        servletEx.initCause(ex);
        throw servletEx;
    }
}

From source file:com.adobe.acs.commons.forms.impl.FormsPostRedirectGetSlingFilterImpl.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    if (!(servletRequest instanceof SlingHttpServletRequest)
            || !(servletResponse instanceof SlingHttpServletResponse)) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;//from  ww w.j av a2 s. c om
    }

    final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest;
    final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse;

    /**
     * Fail fast and early!
     *
     * Must be:
     *  - HTTP GET Request
     *  - Have Forms Sling Suffix
     *    - At this point, 99% of includes will be passed over
     *  - Must contain Form Selector Query Parameter
     *  - Include is not a product of a previous forward by this Filter
     */

    if (!StringUtils.equals("GET", slingRequest.getMethod()) || !formHelper.hasValidSuffix(slingRequest)) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    /* Ensure there is a valid form selector as part of Query Params */
    final String formSelector = formHelper.getFormSelector(slingRequest); //this.getParameter(slingRequest, PostRedirectGetFormHelper.QUERY_PARAM_FORM_SELECTOR);
    if (formSelector == null) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    /* Ensure this is not a product of a previous forward; This is to be absolutely sure we are not hitting an
     * infinite loop condition */
    if (slingRequest.getAttribute(REQUEST_ATTR_PREVIOUSLY_PROCESSED) != null) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    final RequestDispatcherOptions options = new RequestDispatcherOptions();

    options.setReplaceSelectors(formSelector);
    options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix());

    if (log.isDebugEnabled()) {
        log.debug("Post-Redirect-Get Form Filter; Internal forward to resource: {} ",
                slingRequest.getResource());
        log.debug("Post-Redirect-Get Form Filter; Internal forward to path: {} ",
                slingRequest.getResource().getPath());
        log.debug("Post-Redirect-Get Filter; Internal forward w/ replace selectors: {} ",
                options.getReplaceSelectors());
        log.debug("Post-Redirect-Get Filter; Internal forward w/ suffix: {} ", options.getReplaceSuffix());
    }

    // Avoid accidental infinite loops with API consumers doing their own Fws and Includes
    slingRequest.setAttribute(REQUEST_ATTR_PREVIOUSLY_PROCESSED, Boolean.TRUE);
    slingRequest.getRequestDispatcher(slingRequest.getResource(), options).forward(slingRequest, slingResponse);
}

From source file:org.jboss.arquillian.warp.impl.server.execution.WarpFilter.java

/**
 * Detects whenever the request is HTTP request and if yes, delegates to
 * {@link #doFilterHttp(HttpServletRequest, HttpServletResponse, FilterChain)}.
 */// ww  w . j a  v  a 2s .  co  m
@Override
public void doFilter(ServletRequest req, ServletResponse resp, final FilterChain chain)
        throws IOException, ServletException {

    if (manager == null || isHttpRequest(req, resp)) {
        doFilterHttp((HttpServletRequest) req, (HttpServletResponse) resp, chain);
    } else {
        chain.doFilter(req, resp);
    }
}

From source file:org.apereo.openlrs.controllers.xapi.XAPIRequestValidationFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    String versionHeader = request.getHeader(XApiConstants.XAPI_VERSION_HEADER);

    if (StringUtils.isNotBlank(versionHeader)) {
        // for now we are just checking for the header
        // in the future we'll deal with specific versioning checking
        filterChain.doFilter(request, response);
    } else {/*  w  ww . j  av a  2 s  .  c  o m*/
        log.warn("Request missing XAPI VERSION HEADER");
        response.sendError(400, "Missing " + XApiConstants.XAPI_VERSION_HEADER + " Header");
    }

}

From source file:io.github.arven.rs.provider.ApiOriginFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) res;
    response.setHeader("Access-Control-Allow-Origin", "*");
    response.setHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT");
    response.setHeader("Access-Control-Allow-Headers", "Content-Type");
    chain.doFilter(req, res);
}

From source file:fr.paris.lutece.portal.web.upload.UploadFilter.java

/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
 * @param request// w  w w  .  j a va  2 s.c om
 *            The ServletRequest
 * @param response
 *            The ServletResponse
 * @param chain
 *            The FilterChain
 * @throws IOException
 *             The IOException
 * @throws ServletException
 *             The SerletException
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request;

    if (!MultipartUtil.isMultipart(httpRequest)) {
        chain.doFilter(request, response);
    } else {
        try {
            MultipartHttpServletRequest multiHtppRequest = MultipartUtil.convert(_nSizeThreshold,
                    _nRequestSizeMax, _bActivateNormalizeFileName, httpRequest);
            chain.doFilter(multiHtppRequest, response);
        } catch (SizeLimitExceededException e) {
            AppLogService.error(e.getMessage(), e);

            Object[] args = { getDisplaySize() };
            ((HttpServletResponse) response).sendRedirect(AppPathService.getBaseUrl(httpRequest)
                    + getMessageRelativeUrl(httpRequest, PROPERTY_MESSAGE_FILE_SIZE_LIMIT_EXCEEDED, args,
                            PROPERTY_TITLE_FILE_SIZE_LIMIT_EXCEEDED));
        } catch (FileUploadException e) {
            AppLogService.error(e.getMessage(), e);
            throw new ServletException("Unkown error occured during the upload", e);
        }
    }
}

From source file:com.mycompany.springrest.token.JwtAuthenticationFilter.java

@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        FilterChain chain, Authentication authResult) throws IOException, ServletException {
    super.successfulAuthentication(request, response, chain, authResult);

    // As this authentication is in HTTP header, after success we need to continue the request normally
    // and return the response as if the resource was not secured at all
    chain.doFilter(request, response);
}