List of usage examples for javax.servlet ServletRequest setAttribute
public void setAttribute(String name, Object o);
From source file:org.wso2.carbon.identity.relyingparty.saml.SAMLTokenConsumer.java
/** * When the token is valid this method injects valid states message * /*from w w w. j ava 2s . c om*/ * @param verifier * @param request * @throws RelyingPartyException */ protected void injectDataToRequestOnSuccess(SAMLTokenVerifier verifier, ServletRequest request) throws RelyingPartyException { String issuerInfo = getIssuerInfoString(verifier); Iterator propertyEntry = null; if (issuerInfo != null) { request.setAttribute(TokenVerifierConstants.ISSUER_INFO, issuerInfo); } propertyEntry = verifier.getAttributeTable().entrySet().iterator(); while (propertyEntry.hasNext()) { Entry entry = (Entry) propertyEntry.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); request.setAttribute(key, value); } request.setAttribute(TokenVerifierConstants.SERVLET_ATTR_STATE, TokenVerifierConstants.STATE_SUCCESS); }
From source file:org.smigo.config.RequestLogFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletResponse resp = (HttpServletResponse) response; HttpServletRequest req = (HttpServletRequest) request; resp.addHeader("SmigoUser", req.getRemoteUser()); log.info("Incoming request:" + req.getMethod() + req.getRequestURL().toString()); request.setAttribute(REQUEST_TIMER, System.nanoTime()); chain.doFilter(request, response);/* w w w .j a v a2s .co m*/ logHandler.log(req, resp); }
From source file:ru.org.linux.site.TemplateFilter.java
@Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException { if (filterConfig == null) { return;//from ww w. j a v a 2 s. co m } try { Template tmpl = new Template((HttpServletRequest) servletRequest, properties, (HttpServletResponse) servletResponse, userDao); servletRequest.setAttribute("template", tmpl); } catch (Exception ex) { logger.fatal("Can't build Template", ex); return; } filterChain.doFilter(servletRequest, servletResponse); }
From source file:it.unipmn.di.dcs.sharegrid.web.servlet.MultipartFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request.getAttribute(MultipartFilter.DoFilterCalledAttr) != null) { chain.doFilter(request, response); return;//from ww w .jav a 2 s . c o m } request.setAttribute(MultipartFilter.DoFilterCalledAttr, "true"); // sanity check if (!(response instanceof HttpServletResponse)) { chain.doFilter(request, response); return; } HttpServletRequest httpReq = (HttpServletRequest) request; if (!ServletFileUpload.isMultipartContent(httpReq)) { chain.doFilter(request, response); return; } // Wraps the current request into a multipart request object // for handling multipart form parameters. MultipartRequestWrapper reqWrapper = null; reqWrapper = new MultipartRequestWrapper(httpReq, this.maxSize, this.maxFileSize, this.thresholdSize, this.repositoryPath); chain.doFilter(reqWrapper, response); }
From source file:net.geoprism.SessionFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpRes = (HttpServletResponse) res; // response time logging req.setAttribute("startTime", (Long) (new Date().getTime())); HttpSession session = httpReq.getSession(); WebClientSession clientSession = (WebClientSession) session.getAttribute(ClientConstants.CLIENTSESSION); // This isLoggedIn check is not 100% sufficient, it doesn't go to the server // and check, it only does it locally, so if the session has expired it'l // let it through. if (clientSession != null && clientSession.getRequest().isLoggedIn()) { try {/*from www. ja v a2 s. co m*/ req.setAttribute(ClientConstants.CLIENTREQUEST, clientSession.getRequest()); chain.doFilter(req, res); } catch (Throwable t) { while (t.getCause() != null && !t.getCause().equals(t)) { t = t.getCause(); } if (t instanceof InvalidSessionExceptionDTO) { // If we're asynchronous, we want to return a serialized exception if (StringUtils.endsWith(httpReq.getRequestURL().toString(), ".mojax")) { ErrorUtility.prepareAjaxThrowable(t, httpRes); } else { // Not an asynchronous request, redirect to the login page. httpRes.sendRedirect(httpReq.getContextPath() + "/loginRedirect"); } } else { if (t instanceof RuntimeException) { throw (RuntimeException) t; } else { throw new RuntimeException(t); } } } return; } else if (pathAllowed(httpReq)) { chain.doFilter(req, res); return; } else { // The user is not logged in // If we're asynchronous, we want to return a serialized exception if (StringUtils.endsWith(httpReq.getRequestURL().toString(), ".mojax")) { ErrorUtility.prepareAjaxThrowable(new InvalidSessionExceptionDTO(), httpRes); } else { // Not an asynchronous request, redirect to the login page. httpRes.sendRedirect(httpReq.getContextPath() + "/loginRedirect"); } } }
From source file:org.shredzone.cilla.view.PageListView.java
/** * Fetches the pages by query./*from w w w .j a va 2 s . c o m*/ * * @param filter * {@link FilterModel} with the query parameters * @param paginator * {@link PaginatorModel} to be used, or {@code null} if none was given * @param context * {@link ViewFacade} to be used */ private String fetchPages(FilterModel filter, PaginatorModel paginator, ServletRequest req) throws CillaServiceException { if (paginator == null) { paginator = new PaginatorModel(); } paginator.setPerPage(maxEntries); SearchResult result = searchService.search(filter); paginator.setCount(result.getCount()); result.setPaginator(paginator); req.setAttribute("result", result); req.setAttribute("paginator", paginator); return "view/pageList.jsp"; }
From source file:org.osaf.cosmo.acegisecurity.context.HttpRequestContextIntegrationFilter.java
/** * Generates a new security context, continues the filter chain, * then clears the context by generating another new one. * * @param request the servlet request// w ww. j a v a 2 s .com * @param response the servlet response * @param chain the filter chain * @throws IOException if an I/O error occurs * @throws ServletException if any other error occurs */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request.getAttribute(FILTER_APPLIED) != null) { // ensure that filter is applied only once per request chain.doFilter(request, response); return; } request.setAttribute(FILTER_APPLIED, Boolean.TRUE); if (log.isDebugEnabled()) { log.debug("New SecurityContext instance associated with SecurityContextHolder"); } SecurityContextHolder.setContext(generateNewContext()); try { chain.doFilter(request, response); } catch (IOException ioe) { throw ioe; } catch (ServletException se) { throw se; } finally { // do clean up, even if there was an exception SecurityContextHolder.clearContext(); if (log.isDebugEnabled()) { log.debug("SecurityContextHolder refreshed, as request processing completed"); } } }
From source file:ro.raisercostin.web.DebuggingFilter.java
public void doFilter(final ServletRequest request, final ServletResponse response, FilterChain chain) throws IOException, ServletException { request.setAttribute("debug", new DebugInfo() { public String getJspInfo() { return debug(servletContext, (HttpServletRequest) request, (HttpServletResponse) response, new HtmlPrinter(), true, true); }/*from ww w . j av a 2s . c om*/ public boolean isRequested() { String debug = request.getParameter("debug"); if (debug != null) { if ("false".equals(debug)) { return false; } return true; } return false; } }); if (loggerParameters.isDebugEnabled()) { loggerParameters .debug(debug(servletContext, (HttpServletRequest) request, (HttpServletResponse) response, new PlainTextPrinter(), loggerAll.isDebugEnabled(), loggerRequest.isDebugEnabled())); } chain.doFilter(request, response); }
From source file:org.apache.catalina.core.StandardWrapperValve.java
/** * Handle the specified ServletException encountered while processing * the specified Request to produce the specified Response. Any * exceptions that occur during generation of the exception report are * logged and swallowed./*w w w .j a v a 2 s . c o m*/ * * @param request The request being processed * @param response The response being generated * @param exception The exception that occurred (which possibly wraps * a root cause exception */ private void exception(Request request, Response response, Throwable exception) { ServletRequest sreq = request.getRequest(); sreq.setAttribute(Globals.EXCEPTION_ATTR, exception); ServletResponse sresponse = response.getResponse(); if (sresponse instanceof HttpServletResponse) ((HttpServletResponse) sresponse).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); }
From source file:org.unitedinternet.cosmo.acegisecurity.context.HttpRequestContextIntegrationFilter.java
/** * Generates a new security context, continues the filter chain, * then clears the context by generating another new one. * * @param request the servlet request/*from ww w . j a v a2s . c o m*/ * @param response the servlet response * @param chain the filter chain * @throws IOException if an I/O error occurs * @throws ServletException if any other error occurs */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request.getAttribute(FILTER_APPLIED) != null) { // ensure that filter is applied only once per request chain.doFilter(request, response); return; } request.setAttribute(FILTER_APPLIED, Boolean.TRUE); if (LOG.isDebugEnabled()) { LOG.debug("New SecurityContext instance associated with SecurityContextHolder"); } SecurityContextHolder.setContext(generateNewContext()); try { chain.doFilter(request, response); } catch (IOException ioe) { throw ioe; } catch (ServletException se) { throw se; } finally { // do clean up, even if there was an exception SecurityContextHolder.clearContext(); if (LOG.isDebugEnabled()) { LOG.debug("SecurityContextHolder refreshed, as request processing completed"); } } }