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.appdynamicspilot.servlet.EntityManagerFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    EntityManagerHelper.getInstance().setEntityManager(emf.createEntityManager());
    filterChain.doFilter(servletRequest, servletResponse);

    EntityManagerHelper.getInstance().getEntityManager().close();
    EntityManagerHelper.getInstance().setEntityManager(null);
}

From source file:grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter.java

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
        throws IOException, ServletException {

    applyAnonymousForThisRequest((HttpServletRequest) req);

    chain.doFilter(req, res);
}

From source file:de.rgielen.struts1.filter.ParamWrapperFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    chain.doFilter(new ParamFilteredRequest(request, pattern), response);
}

From source file:io.wcm.caravan.commons.cors.impl.CorsServletFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    if (!enabled) {
        chain.doFilter(servletRequest, servletResponse);
        return;/*w w  w.j  a va2  s. c  o  m*/
    }

    HttpServletRequest request = (HttpServletRequest) servletRequest;
    HttpServletResponse response = (HttpServletResponse) servletResponse;

    String origin = request.getHeader(HttpHeader.ORIGIN);
    if (StringUtils.isNotEmpty(origin)) {
        if (allowAllHosts) {
            response.setHeader(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN, "*");
        } else if ((hostWhitelist.isEmpty() || hostWhitelist.contains(origin))
                && (hostBlacklist.isEmpty() || !hostBlacklist.contains(origin))) {
            response.setHeader(HttpHeader.ACCESS_CONTROL_ALLOW_ORIGIN, origin);
            response.addHeader(HttpHeader.VARY, HttpHeader.ORIGIN);
        }
    }

    chain.doFilter(request, response);
}

From source file:com.github.achatain.nopasswordauthentication.di.filters.JsonFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (HTTPMethod.GET.name().equals(((HttpServletRequest) request).getMethod())) {
        chain.doFilter(request, response);
        return;/*ww  w  .ja  v  a 2 s.co  m*/
    }

    String contentType = request.getContentType();

    if (JSON_TYPES.contains(StringUtils.lowerCase(contentType))) {
        chain.doFilter(request, response);
    } else {
        throw new UnsupportedContentTypeException(
                String.format("Expected a JSON content type but got [%s]", contentType));
    }
}

From source file:scratch.cucumber.example.security.spring.StatelessAuthenticationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
        throws IOException, ServletException {
    contextHolder.getContext().setAuthentication(authenticationBinder.retrieve((HttpServletRequest) request));
    filterChain.doFilter(request, response);
}

From source file:com.example.HoneycombFilter.java

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

    if (!(request instanceof HttpServletRequest)) {
        chain.doFilter(request, response);
        return;/*from w w  w .  java  2  s .c om*/
    }
    HttpServletRequest req = (HttpServletRequest) request;
    long start = System.nanoTime();
    try {
        chain.doFilter(request, response);
    } finally {
        long responseTimeNanos = System.nanoTime() - start;
        Event event = libhoney.newEvent();
        event.addField("method", req.getMethod());
        event.addField("path", req.getRequestURI());
        event.addField("query", req.getQueryString());
        Principal principal = req.getUserPrincipal();
        if (principal != null) {
            event.addField("user", principal.getName());
        }
        event.addField("host", req.getRemoteHost());
        event.addField("responseTimeNanos", responseTimeNanos);
        try {
            event.send();
        } catch (HoneyException e) {
            log.error(e.getMessage(), e);
        }
    }
}

From source file:com.netsteadfast.greenstep.base.filter.CharsetFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    response.setContentType(this.contentType);
    response.setCharacterEncoding(this.encoding);
    chain.doFilter(request, response);
}

From source file:com.bennavetta.appsite.security.SecurityConfig.java

@Bean
public Filter log() {
    return new Filter() {

        @Override/*from www  .  j  a  v a2s .com*/
        public void destroy() {
        }

        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain filter)
                throws IOException, ServletException {
            System.err.println("Intercepted: " + request);
            filter.doFilter(request, response);
        }

        @Override
        public void init(FilterConfig arg0) throws ServletException {
        }

    };
}

From source file:edu.wisc.web.util.NoCacheHeaderFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    response.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate");
    response.setDateHeader("Expires", 0);
    filterChain.doFilter(request, response);
}