List of usage examples for javax.servlet FilterChain doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;
From source file:se.skltp.cooperation.web.rest.v1.filter.SimpleCORSFilter.java
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"); response.setHeader("Access-Control-Max-Age", "3600"); chain.doFilter(req, res); }
From source file:com.adobe.acs.commons.forms.impl.FormsPostFilterImpl.java
@Override public final void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { if (!(servletRequest instanceof SlingHttpServletRequest) || !(servletResponse instanceof SlingHttpServletResponse)) { filterChain.doFilter(servletRequest, servletResponse); return;/* ww w.j ava2 s. c om*/ } final SlingHttpServletRequest slingRequest = (SlingHttpServletRequest) servletRequest; final SlingHttpServletResponse slingResponse = (SlingHttpServletResponse) servletResponse; /** * Fail fast and early! * * Must be: * - HTTP POST Request * - Have Forms Sling Suffix * - At this point, 99% of includes will be passed over * - Must contain Form Resource Query Parameter */ if (!StringUtils.equals("POST", slingRequest.getMethod()) || !formsRouter.hasValidSuffix(slingRequest)) { filterChain.doFilter(servletRequest, servletResponse); return; } final String formResource = this.getParameter(slingRequest, FormHelper.FORM_RESOURCE_INPUT); if (formResource == null || slingRequest.getResourceResolver().resolve(formResource) == null) { filterChain.doFilter(servletRequest, servletResponse); return; } String formSelector = formsRouter.getFormSelector(slingRequest); if (formSelector == null) { formSelector = FormHelper.DEFAULT_FORM_SELECTOR; } final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(formSelector); options.setReplaceSuffix(slingRequest.getRequestPathInfo().getSuffix()); if (log.isDebugEnabled()) { log.debug("Form Filter; Internal forward to path: {} ", formResource); log.debug("Form Filter; Internal forward w/ replace selectors: {} ", options.getReplaceSelectors()); log.debug("Form Filter; Internal forward w/ suffix: {} ", options.getReplaceSuffix()); } slingRequest.getRequestDispatcher(formResource, options).forward(slingRequest, slingResponse); }
From source file:com.antelink.sourcesquare.server.servlet.ResultFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { if (this.sourceSquareResult == null) { logger.debug("filter results"); ((HttpServletResponse) resp).sendRedirect("index.jsp"); } else {/*from w ww . j a v a 2 s.co m*/ logger.debug("show results"); chain.doFilter(req, resp); } }
From source file:org.hspconsortium.platform.authorization.web.LaunchContextFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { HttpSession session = request.getSession(); try {/* www.j ava2 s.co m*/ Set<String> launchContextIds = (Set<String>) session.getAttribute(Constants.LAUNCH_CONTEXT_ID_MAP_KEY); LaunchContextHolder.setLaunchContextIds(launchContextIds); filterChain.doFilter(request, response); } finally { session.setAttribute(Constants.LAUNCH_CONTEXT_ID_MAP_KEY, LaunchContextHolder.getLaunchContextIds()); LaunchContextHolder.clearLaunchContextIds(); } }
From source file:com.chevrier.legiondao.config.CorsFilter.java
@Override protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { httpServletResponse.addHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS"); httpServletResponse.addHeader("Access-Control-Allow-Headers", "origin, content-type, accept,x-req"); filterChain.doFilter(httpServletRequest, httpServletResponse); }
From source file:org.zalando.zmon.actuator.ZmonMetricsFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start();/*from w w w .j av a 2 s. c om*/ String path = new UrlPathHelper().getPathWithinApplication(request); int status = HttpStatus.INTERNAL_SERVER_ERROR.value(); try { chain.doFilter(request, response); status = getStatus(response); } finally { stopWatch.stop(); metricsWrapper.recordClientRequestMetrics(request, path, status, stopWatch.getTotalTimeMillis()); } }
From source file:nl.surfnet.coin.api.saml.SAMLAssertionAuthenticationFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; if (!openSAMLContext.isSAMLResponse(req)) { LOG.debug("Request is not a SAML response. Will continue filter chain."); chain.doFilter(request, response); return;/*from ww w . ja v a 2 s. co m*/ } SAMLAuthenticationToken samlAuthenticationToken = new SAMLAuthenticationToken( getPreAuthenticatedPrincipal(req), Arrays.asList(new SimpleGrantedAuthority("ROLE_USER"))); samlAuthenticationToken.setAuthenticated(true); samlAuthenticationToken.setDetails(authenticationDetailsSource.buildDetails(req)); SecurityContextHolder.getContext().setAuthentication(samlAuthenticationToken); String originalUrl = request.getParameter("RelayState"); try { LOG.debug("Redirecting to original url {}", originalUrl); ((HttpServletResponse) response).sendRedirect(originalUrl); } catch (IOException e) { LOG.info("Cannot redirect to original url", e); } }
From source file:org.focusns.common.web.performance.MonitorFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { ////from w ww .ja va2 s. co m if (log.isTraceEnabled()) { // String requestDesc = getRequestDescription(request); StopWatch stopWatch = new StopWatch(); stopWatch.start(requestDesc); // filterChain.doFilter(request, response); // stopWatch.stop(); // log.trace(stopWatch.prettyPrint()); } else { filterChain.doFilter(request, response); } }
From source file:com.adobe.acs.commons.http.headers.impl.AbstractDispatcherCacheHeaderFilter.java
@Override public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException { if (!(servletRequest instanceof HttpServletRequest) || !(servletResponse instanceof HttpServletResponse)) { filterChain.doFilter(servletRequest, servletResponse); return;/*from w w w . java 2 s .c o m*/ } final HttpServletRequest request = (HttpServletRequest) servletRequest; final HttpServletResponse response = (HttpServletResponse) servletResponse; if (this.accepts(request)) { String header = getHeaderName(); String val = getHeaderValue(); String attributeName = AbstractDispatcherCacheHeaderFilter.class.getName() + ".header." + header; if (request.getAttribute(attributeName) == null) { log.debug("Adding header {}: {}", header, val); response.addHeader(header, val); request.setAttribute(attributeName, MARKER); } else { log.debug("Header {} was already set. Skipping.", header); } } filterChain.doFilter(request, response); }
From source file:com.janrain.servlet.ProcessTimeLoggingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest servletRequest = (HttpServletRequest) request; if (servletRequest.getRequestURL().indexOf("http://localhost") != 0) { long start = System.currentTimeMillis(); chain.doFilter(request, response); long stop = System.currentTimeMillis(); StringBuilder output = new StringBuilder(); output.append("Time [ ").append(stop - start).append(" ms ]"); output.append(" Request [").append(servletRequest.getRequestURL()); if (servletRequest.getQueryString() != null) { output.append("?").append(servletRequest.getQueryString()); }//www. j a v a2 s .c o m output.append("]"); output.append(" Remote Addr [ ").append(servletRequest.getRemoteAddr()).append(" ] "); String referer = servletRequest.getHeader("referer"); if (StringUtils.isNotBlank(referer)) { output.append(" Referer [ ").append(referer).append(" ] "); } String userAgent = servletRequest.getHeader("user-agent"); if (StringUtils.isNotBlank(userAgent)) { output.append(" [ ").append(userAgent).append(" ] "); } logger.debug(output); } else { chain.doFilter(request, response); } }