List of usage examples for javax.servlet ServletRequest setAttribute
public void setAttribute(String name, Object o);
From source file:org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.java
private String getControllerName(ServletRequest request) { String controllerName = (String) request .getAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE); if (controllerName == null || controllerName.length() == 0) { GroovyObject controller = getController(request); if (controller != null) { controllerName = (String) controller.getProperty(ControllerDynamicMethods.CONTROLLER_NAME_PROPERTY); request.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE, controllerName); }//from ww w .ja va2s .c o m } return controllerName != null ? controllerName : ""; }
From source file:gov.nih.nci.protexpress.ui.filters.UserFilter.java
/** * {@inheritDoc}/*from ww w . j ava 2 s . c om*/ */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (!(request instanceof HttpServletRequest)) { chain.doFilter(request, response); return; } String username = ((HttpServletRequest) request).getRemoteUser(); if (StringUtils.isNotBlank(username)) { User user = ProtExpressRegistry.getUserProvisioningManager().getUser(username); if (user == null) { user = new User(); user.setLoginName(username); } UserHolder.setUser(user); request.setAttribute("currentUser", UserHolder.getUser()); request.setAttribute("currentUserDisplayName", UserHolder.getDisplayNameForUser()); } else { UserHolder.setUser(null); } chain.doFilter(request, response); }
From source file:uk.ac.lancs.e_science.sakai.tools.blogger.PostEditionAbstractController.java
public String doPreview() { ServletRequest request = (ServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();//from w ww . ja v a 2 s. c o m request.setAttribute("post", post); return "previewPost"; }
From source file:org.grails.web.servlet.DefaultGrailsApplicationAttributes.java
private String getControllerName(ServletRequest request) { String controllerName = (String) request .getAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE); if (controllerName == null || controllerName.length() == 0) { GroovyObject controller = getController(request); if (controller != null) { controllerName = (String) controller.getProperty(ControllerDynamicMethods.CONTROLLER_NAME_PROPERTY); request.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAME_ATTRIBUTE, controllerName); if (controller instanceof GrailsControllerClass) { String namespace = ((GrailsControllerClass) controller).getNamespace(); if (namespace != null) { request.setAttribute(GrailsApplicationAttributes.CONTROLLER_NAMESPACE_ATTRIBUTE, namespace); }//w w w .j a va 2 s. c o m } } } return controllerName != null ? controllerName : ""; }
From source file:de.itsvs.cwtrpc.controller.CacheControlFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { /* filter must not be applied on an internal forward or on error */ if (request.getAttribute(PROCESSED_ALREADY_ATTR_NAME) == null) { final PreparedCacheControlUriConfig uriConfig; uriConfig = getPreparedUriConfig((HttpServletRequest) request); if (uriConfig != null) { addHeaders((HttpServletResponse) response, uriConfig); }//from ww w .j av a 2 s .c om request.setAttribute(PROCESSED_ALREADY_ATTR_NAME, Boolean.TRUE); } chain.doFilter(request, response); }
From source file:org.apache.myfaces.webapp.filter.ExtensionsFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request.getAttribute(DOFILTER_CALLED) != null) { chain.doFilter(request, response); return;/* ww w.j av a 2 s. co m*/ } request.setAttribute(DOFILTER_CALLED, "true"); if (!(response instanceof HttpServletResponse)) { //If this is a portlet request, just continue the chaining chain.doFilter(request, response); return; } HttpServletResponse httpResponse = (HttpServletResponse) response; HttpServletRequest httpRequest = (HttpServletRequest) request; // Serve resources AddResource addResource; try { addResource = AddResourceFactory.getInstance(httpRequest, _servletContext); if (addResource.isResourceUri(_servletContext, httpRequest)) { addResource.serveResource(_servletContext, httpRequest, httpResponse); return; } } catch (Throwable th) { log.error("Exception wile retrieving addResource", th); throw new ServletException(th); } HttpServletRequest extendedRequest = httpRequest; // For multipart/form-data requests // This is done by TomahawkFacesContextWrapper if (ServletFileUpload.isMultipartContent(httpRequest)) { extendedRequest = new MultipartRequestWrapper(httpRequest, _uploadMaxFileSize, _uploadThresholdSize, _uploadRepositoryPath, _uploadMaxSize, _cacheFileSizeErrors); } try { if (addResource instanceof AddResource2) { ((AddResource2) addResource).responseStarted(_servletContext, extendedRequest); } else { addResource.responseStarted(); } //This case is necessary when is used //org.apache.myfaces.renderkit.html.util.DefaultAddResource //Buffers the output and add to the header the necessary stuff //In other case this is simply ignored (NonBufferingAddResource and //StreamingAddResource), because this not require buffering //and the chaining continues. if (addResource.requiresBuffer()) { ExtensionsResponseWrapper extendedResponse = new ExtensionsResponseWrapper( (HttpServletResponse) response); // Standard request chain.doFilter(extendedRequest, extendedResponse); extendedResponse.finishResponse(); // write the javascript stuff for myfaces and headerInfo, if needed HttpServletResponse servletResponse = (HttpServletResponse) response; // only parse HTML responses if (extendedResponse.getContentType() != null && isValidContentType(extendedResponse.getContentType())) { addResource.parseResponse(extendedRequest, extendedResponse.toString(), servletResponse); addResource.writeMyFacesJavascriptBeforeBodyEnd(extendedRequest, servletResponse); if (!addResource.hasHeaderBeginInfos()) { // writes the response if no header info is needed addResource.writeResponse(extendedRequest, servletResponse); return; } // Some headerInfo has to be added addResource.writeWithFullHeader(extendedRequest, servletResponse); // writes the response addResource.writeResponse(extendedRequest, servletResponse); } else { byte[] responseArray = extendedResponse.getBytes(); if (responseArray.length > 0) { // When not filtering due to not valid content-type, deliver the byte-array instead of a charset-converted string. // Otherwise a binary stream gets corrupted. servletResponse.getOutputStream().write(responseArray); } } } else { chain.doFilter(extendedRequest, response); } } finally { addResource.responseFinished(); } //chain.doFilter(extendedRequest, response); }
From source file:org.eclipse.skalli.view.internal.filter.SearchFilter.java
@Override protected SearchResult<Project> getSearchHits(User user, ServletRequest request, ServletResponse response, int start, int count) throws IOException, ServletException { SearchQuery searchQuery = null;// w ww .j a v a2 s .c o m SearchResult<Project> result = null; try { searchQuery = new SearchQuery(request); searchQuery.setPagingInfo(start, count); result = SearchUtils.searchProjects(searchQuery); } catch (Exception e) { FilterUtil.handleException(request, response, e); return new SearchResult<Project>("*"); //$NON-NLS-1$ } Statistics.getDefault().trackSearch(user.getUserId(), result.getQueryString(), result.getResultCount(), result.getDuration()); request.setAttribute(Consts.ATTRIBUTE_QUERY, searchQuery.getQuery()); request.setAttribute(Consts.ATTRIBUTE_USERQUERY, searchQuery.getUser()); request.setAttribute(Consts.ATTRIBUTE_TAGQUERY, searchQuery.getTag()); return result; }
From source file:nl.surfnet.coin.shared.filter.LoggingFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Create copy outpustream and wrap response to use this final OutputStream outputStreamCopy = new ByteArrayOutputStream(); HttpServletResponse wrappedResponse = new MemorizingResponseWrapper((HttpServletResponse) response, outputStreamCopy);// www. j ava 2 s .c o m // Generate unique request id to make correlation request-log and response log easier String requestId; synchronized (lock) { requestId = generateRequestId(); } request.setAttribute(REQUEST_ID_ATTR, requestId); request.setAttribute(OUTPUT_STREAM_COPY_ATTR, outputStreamCopy); preHandle((HttpServletRequest) request, requestId); try { chain.doFilter(request, wrappedResponse); postHandle(request, wrappedResponse, null); } catch (IOException ioe) { postHandle(request, wrappedResponse, ioe); throw ioe; } catch (ServletException se) { postHandle(request, wrappedResponse, se); throw se; } catch (RuntimeException rte) { postHandle(request, wrappedResponse, rte); throw rte; } }
From source file:au.org.paperminer.main.UserFilter.java
/** * Loads info about an existing PM user into a session cookie * @param req// w ww . j a v a2s . c om * @param resp */ private void openUser(ServletRequest req, ServletResponse resp) { m_logger.info("opening user"); String email = req.getParameter("em"); String verify = req.getParameter("vfy"); removeCookie((HttpServletResponse) resp); UserHelper userHelper = new UserHelper(email, null); if (!userHelper.isKnownUser()) { req.setAttribute(PaperMinerConstants.ERROR_PAGE, "e103"); } else { CookieHelper.addCookie((HttpServletResponse) resp, userHelper); if ((verify != null) && verify.equals("y")) { sendVerificationEmail(userHelper.get(UserHelper.ID), userHelper.get(UserHelper.EMAIL), req); } m_logger.info("user " + email + " exists with id " + userHelper.get(UserHelper.ID)); } }
From source file:org.openrepose.powerfilter.PowerFilterChain.java
public void startFilterChain(ServletRequest servletRequest, ServletResponse servletResponse) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) servletRequest; boolean addTraceHeader = traceRequest(request); boolean useTrace = addTraceHeader || (filterTimer != null); tracer = new RequestTracer(useTrace, addTraceHeader); currentFilters = getFilterChainForRequest(request.getRequestURI()); filterChainAvailable = isCurrentFilterChainAvailable(); servletRequest.setAttribute("filterChainAvailableForRequest", filterChainAvailable); servletRequest.setAttribute("http://openrepose.org/requestUrl", ((HttpServletRequest) servletRequest).getRequestURL().toString()); servletRequest.setAttribute("http://openrepose.org/queryParams", servletRequest.getParameterMap()); MutableHttpServletRequest wrappedRequest = MutableHttpServletRequest .wrap((HttpServletRequest) servletRequest); splitRequestHeaders(wrappedRequest); doFilter(wrappedRequest, servletResponse); }