List of usage examples for javax.servlet FilterChain doFilter
public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException;
From source file:com.weitaomi.systemconfig.filter.LoggingFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (logger.isInfoEnabled()) { long requestId = id.incrementAndGet(); request = new RequestWrapper(requestId, request); //response = new ResponseWrapper(requestId, response); }/*from ww w. j av a2 s . c o m*/ try { filterChain.doFilter(request, response); } finally { if (logger.isInfoEnabled()) { logRequest(request); } } }
From source file:org.lightadmin.core.view.TilesContainerEnrichmentFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { ApplicationContext applicationContext = ServletUtil.getApplicationContext(getServletContext()); TilesContainer container = TilesAccess.getContainer(applicationContext, LIGHT_ADMIN_TILES_CONTAINER_ATTRIBUTE); request.setAttribute(TilesAccess.CURRENT_CONTAINER_ATTRIBUTE_NAME, container); filterChain.doFilter(request, response); }
From source file:cc.aileron.wsgi.router.WsgiRouterImpl.java
/** * @param request/*from w w w . j a v a 2 s .c o m*/ * @param response * @param chain * @throws IOException * @throws ServletException * @throws FileUploadException */ private void doRouting(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws IOException, ServletException, FileUploadException { final WorkflowFindCondition condition = getFindCondition(request); final WorkflowDto dto = container.get(condition); if (dto.isNull()) { logger.trace("request is null : {}", condition); chain.doFilter(request, response); return; } logger.trace("request is execute : {} {} ", dto.resourceClass(), condition); dto.execute(); if (dto.isThrough) { logger.trace("request is through : {} {}", dto.resourceClass(), condition); chain.doFilter(request, response); } }
From source file:eionet.cr.web.filters.HomespaceUrlFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { // Pass on if not a HTTP request. if (!(servletRequest instanceof HttpServletRequest)) { filterChain.doFilter(servletRequest, servletResponse); return;//w w w. j a va 2 s . c o m } // Instantiate local variables for HTTP request, response and request-URL HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; String requestURL = httpRequest.getRequestURL().toString(); boolean isProjectFolder = FolderUtil.isProjectFolder(requestURL); String contextPath = httpRequest.getContextPath(); if (LOGGER.isTraceEnabled()) { LOGGER.trace("httpRequest.getRequestURL() = " + requestURL); LOGGER.trace("httpRequest.getRequestURI() = " + httpRequest.getRequestURI()); LOGGER.trace("httpRequest.getContextPath() = " + contextPath); LOGGER.trace("httpRequest.getServletPath() = " + httpRequest.getServletPath()); LOGGER.trace("httpRequest.getPathInfo() = " + httpRequest.getPathInfo()); } // Parse path info if it is not null and its length is greater than 1 // (because if its equal to 1, then it is "/", meaning the application's root URI). String pathInfo = httpRequest.getPathInfo(); if (pathInfo != null && pathInfo.length() > 1) { int i = pathInfo.indexOf('/', 1); if (i != -1 && pathInfo.length() > (i + 1)) { try { // Prepare the default redirect location. String queryString = "?uri=" + URLEncoder.encode(requestURL, "UTF-8"); String redirectLocation = contextPath + Util.getUrlBinding(ExportTriplesActionBean.class) + queryString; // Override the prepared redirect location in the below special cases. if (DAOFactory.get().getDao(HelperDAO.class).isTabularDataSubject(requestURL)) { // The requested URL is a subject in tabular data (i.e. CSV or TSV) file. redirectLocation = contextPath + TabularDataServlet.URL_PATTERN + queryString; LOGGER.debug("URL points to tabular data subject, redirecting to: " + redirectLocation); // if project file, do not check the filestore in ordinary way } else if (isStoredFile(pathInfo, isProjectFolder) && !isRdfXmlPreferred(httpRequest)) { // The requested URL is a stored file, and requester wants original copy (i.e. not triples) redirectLocation = contextPath + DownloadServlet.URL_PATTERN + queryString; LOGGER.debug("URL points to stored file, redirecting to: " + redirectLocation); } else if (isSparqlBookmark(pathInfo)) { if (isRdfXmlPreferred(httpRequest)) { redirectLocation = contextPath + Util.getUrlBinding(ExportTriplesActionBean.class) + queryString + "&exportProperties="; } else { redirectLocation = contextPath + Util.getUrlBinding(ViewActionBean.class) + queryString; } } // Redirect to the location resolved above. httpResponse.sendRedirect(redirectLocation); return; } catch (DAOException e) { throw new ServletException(e.getMessage(), e); } } } filterChain.doFilter(servletRequest, servletResponse); }
From source file:com.github.fauu.natrank.web.filter.CORSFilter.java
@Override protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException { httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS"); httpServletResponse.setHeader("Access-Control-Max-Age", "3600"); httpServletResponse.setHeader("Access-Control-Allow-Headers", "x-requested-with"); filterChain.doFilter(httpServletRequest, httpServletResponse); }
From source file:org.usergrid.rest.filters.ContentTypeFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { chain.doFilter(request, response); return;/*from w ww . j av a 2s .com*/ } HttpServletRequest origRequest = (HttpServletRequest) request; HeaderWrapperRequest newRequest = new HeaderWrapperRequest(origRequest); newRequest.adapt(); chain.doFilter(newRequest, response); }
From source file:monasca.common.middleware.TokenAuth.java
/** * {@inheritDoc}/*from ww w . j a v a 2s. co m*/ */ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { // According to CORS spec OPTIONS method does not pass auth info if (((HttpServletRequest) req).getMethod().equals("OPTIONS")) { chain.doFilter(req, resp); return; } Object auth = null; int numberOfTries = 0; if (!appConfig.isInitialized()) { appConfig.initialize(filterConfig, req); } int retries = appConfig.getRetries(); long pauseTime = appConfig.getPauseTime(); // Extract credential String token = ((HttpServletRequest) req).getHeader(TOKEN); if (token == null) { if (!appConfig.isDelayAuthDecision()) { logger.debug(HttpServletResponse.SC_UNAUTHORIZED + " No token found."); ((HttpServletResponse) resp).sendError(HttpServletResponse.SC_UNAUTHORIZED, TOKEN_NOTFOUND); return; } else { logger.info("No token found...Skipping"); } } else { do { try { auth = FilterUtils.getCachedToken(token); } catch (ServiceUnavailableException e) { if (numberOfTries < retries) { FilterUtils.pause(pauseTime); logger.debug("Retrying connection after " + pauseTime + " seconds."); numberOfTries++; continue; } else { logger.debug("Exhausted retries.."); TokenExceptionHandler handler = TokenExceptionHandler .valueOf("ServiceUnavailableException"); handler.onException(e, resp, token); } return; } catch (ClientProtocolException e) { if (numberOfTries < retries) { FilterUtils.pause(pauseTime); logger.debug("Retrying connection after " + pauseTime + " seconds."); numberOfTries++; continue; } else { logger.debug("Exhausted retries.."); TokenExceptionHandler handler = TokenExceptionHandler.valueOf("ClientProtocolException"); handler.onException(e, resp, token); } return; } catch (UncheckedExecutionException e) { final TokenExceptionHandler handler; final Exception toHandle; if ((e.getCause() != null) && e.getCause() instanceof AdminAuthException) { toHandle = (AdminAuthException) e.getCause(); handler = TokenExceptionHandler.valueOf("AdminAuthException"); } else if ((e.getCause() != null) && e.getCause() instanceof AuthException) { toHandle = (AuthException) e.getCause(); handler = TokenExceptionHandler.valueOf("AuthException"); } else { toHandle = e; handler = TokenExceptionHandler.valueOf("UncheckedExecutionException"); } handler.onException(toHandle, resp, token); return; } } while (auth == null && numberOfTries <= retries); } req = FilterUtils.wrapRequest(req, auth); logger.debug("TokenAuth: Forwarding down stream to next filter/servlet"); // Forward downstream... chain.doFilter(req, resp); }
From source file:com.loadtesting.showcase.springmvc.filter.PatternFilter.java
/** * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) *///from w ww .j ava2 s . c om public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ExampleKpiCapturers caps = new ExampleKpiCapturers(request, PatternLayer.list()); WebProfilingFormat webFormat; try { caps.startDefaultCapturer(); CountingOutputStream cos = new CountingOutputStream(response.getOutputStream()); chain.doFilter(request, response); webFormat = new WebProfilingFormat(request.getContentLength(), cos.getByteCount()); } finally { caps.endDefaultCapturer(); } sendReports(webFormat, caps); }
From source file:com.navercorp.arcus.util.CrossOriginResourceSharingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse servletResponse = (HttpServletResponse) response; servletResponse.addHeader("Access-Control-Allow-Origin", "*"); servletResponse.addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); servletResponse.addHeader("Access-Control-Allow-Headers", "Content-Type"); chain.doFilter(request, response); }
From source file:com.loadtesting.showcase.springmvc.filter.LoadTestFilter.java
/** * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) *///from ww w . ja va2s . c o m public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ExampleKpiCapturers caps = new ExampleKpiCapturers(request, LoadTestLayer.list()); WebProfilingFormat webFormat; try { caps.startDefaultCapturer(); CountingOutputStream cos = new CountingOutputStream(response.getOutputStream()); chain.doFilter(request, response); webFormat = new WebProfilingFormat(request.getContentLength(), cos.getByteCount()); } finally { caps.endDefaultCapturer(); } sendReports(webFormat, caps); }