List of usage examples for javax.servlet ServletRequest getAttribute
public Object getAttribute(String name);
Object
, or null
if no attribute of the given name exists. From source file:com.laxser.blitz.web.impl.thread.RootEngine.java
/** * Keep a snapshot of the request attributes in case of an include, to * be able to restore the original attributes after the include. * //from w ww . j a v a2s. c o m * @param inv */ private void saveAttributesBeforeInclude(final Invocation inv) { ServletRequest request = inv.getRequest(); logger.debug("Taking snapshot of request attributes before include"); Map<String, Object> attributesSnapshot = new HashMap<String, Object>(); Enumeration<?> attrNames = request.getAttributeNames(); while (attrNames.hasMoreElements()) { String attrName = (String) attrNames.nextElement(); attributesSnapshot.put(attrName, request.getAttribute(attrName)); } inv.setAttribute("$$paoding-blitz.attributesBeforeInclude", attributesSnapshot); }
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;/*from ww w . ja v a2 s. c o 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:gov.nih.nci.rembrandt.web.taglib.ClinicalPlotTag.java
public int doStartTag() { chart = null;/* ww w . ja v a 2s .c o m*/ clinicalData.clear(); ServletRequest request = pageContext.getRequest(); HttpSession session = pageContext.getSession(); Object o = request.getAttribute(beanName); JspWriter out = pageContext.getOut(); ServletResponse response = pageContext.getResponse(); try { // //retrieve the Finding from cache and build the list of Clinical Data points //ClinicalFinding clinicalFinding = (ClinicalFinding)businessTierCache.getSessionFinding(session.getId(),taskId); ReportBean clincalReportBean = presentationTierCache.getReportBean(session.getId(), taskId); Resultant clinicalResultant = clincalReportBean.getResultant(); ResultsContainer resultsContainer = clinicalResultant.getResultsContainer(); SampleViewResultsContainer sampleViewContainer = null; if (resultsContainer instanceof DimensionalViewContainer) { DimensionalViewContainer dimensionalViewContainer = (DimensionalViewContainer) resultsContainer; sampleViewContainer = dimensionalViewContainer.getSampleViewResultsContainer(); } if (sampleViewContainer != null) { Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); clinicalFactors.add(ClinicalFactorType.AgeAtDx); //clinicalFactors.add(ClinicalFactorType.Survival); Collection<SampleResultset> samples = sampleViewContainer.getSampleResultsets(); if (samples != null) { int numDxvsKa = 0; int numDxvsSl = 0; for (SampleResultset rs : samples) { //String id = rs.getBiospecimen().getValueObject(); String id = rs.getSampleIDDE().getValueObject(); ClinicalDataPoint clinicalDataPoint = new ClinicalDataPoint(id); String diseaseName = rs.getDisease().getValueObject(); if (diseaseName != null) { clinicalDataPoint.setDiseaseName(diseaseName); } else { clinicalDataPoint.setDiseaseName(DiseaseType.NON_TUMOR.name()); } Long sl = rs.getSurvivalLength(); double survivalDays = -1.0; double survivalMonths = -1.0; if (sl != null) { survivalDays = sl.doubleValue(); survivalMonths = survivalDays / 30.0; //if ((survivalMonths > 0.0)&&(survivalMonths < 1000.0)) { clinicalDataPoint.setSurvival(survivalDays); //} } Long dxAge = rs.getAge(); if (dxAge != null) { clinicalDataPoint.setAgeAtDx(dxAge.doubleValue()); } KarnofskyClinicalEvalDE ka = rs.getKarnofskyClinicalEvalDE(); if (ka != null) { String kaStr = ka.getValueObject(); if (kaStr != null) { if (kaStr.contains("|")) { kaStr = kaStr.trim(); String[] kaStrArray = kaStr.split("\\|"); for (int i = 0; i < kaStrArray.length; i++) { if (i == 0) { //first score is baseline just use this for now //later we will need to use all score in a series for each patient double kaVal = Double.parseDouble(kaStrArray[i].trim()); clinicalDataPoint.setKarnofskyScore(kaVal); } } } else { double kaVal = Double.parseDouble(kaStr); clinicalDataPoint.setKarnofskyScore(kaVal); } } } if ((dxAge != null) && (ka != null)) { numDxvsKa++; } if ((dxAge != null) && (sl != null)) { numDxvsSl++; } // Object dx = rs.getAgeGroup(); // if(sl !=null && dx !=null){ // clinicalDataPoint.setSurvival(new Double(sl.toString())); // clinicalDataPoint.setAgeAtDx(new Double(dx.toString())); // } // Object ks = rs.getKarnofskyClinicalEvalDE(); // Object dx = rs.getAgeGroup(); // if(ks !=null && dx !=null){ // clinicalDataPoint.setNeurologicalAssessment(new Double(ks.toString())); // clinicalDataPoint.setAgeAtDx(new Double(dx.toString())); // } clinicalData.add(clinicalDataPoint); } } } System.out.println("Done creating points!"); //------------------------------------------------------------- //GET THE CLINICAL DATA AND POPULATE THE clinicalData list //Note the ClinicalFinding is currently an empty class //---------------------------------------------------------- //check the components to see which graph to get if (components.equalsIgnoreCase("SurvivalvsAgeAtDx")) { chart = (JFreeChart) CaIntegratorChartFactory.getClinicalGraph(clinicalData, ClinicalFactorType.SurvivalLength, "Survival Length (Months)", ClinicalFactorType.AgeAtDx, "Age At Diagnosis (Years)"); } if (components.equalsIgnoreCase("KarnofskyScorevsAgeAtDx")) { chart = (JFreeChart) CaIntegratorChartFactory.getClinicalGraph(clinicalData, ClinicalFactorType.KarnofskyAssessment, "Karnofsky Score", ClinicalFactorType.AgeAtDx, "Age At Diagnosis (Years)"); } RembrandtImageFileHandler imageHandler = new RembrandtImageFileHandler(session.getId(), "png", 600, 500); //The final complete path to be used by the webapplication String finalPath = imageHandler.getSessionTempFolder(); String finalURLpath = imageHandler.getFinalURLPath(); /* * Create the actual charts, writing it to the session temp folder */ ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection()); String mapName = imageHandler.createUniqueMapName(); ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 600, 500, info); /* This is here to put the thread into a loop while it waits for the * image to be available. It has an unsophisticated timer but at * least it is something to avoid an endless loop. **/ boolean imageReady = false; int timeout = 1000; FileInputStream inputStream = null; while (!imageReady) { timeout--; try { inputStream = new FileInputStream(finalPath); inputStream.available(); imageReady = true; inputStream.close(); } catch (IOException ioe) { imageReady = false; if (inputStream != null) { inputStream.close(); } } if (timeout <= 1) { break; } } out.print(ImageMapUtil.getBoundingRectImageMapTag(mapName, false, info)); //finalURLpath = finalURLpath.replace("\\", "/"); finalURLpath = finalURLpath.replace("\\", "/"); long randomness = System.currentTimeMillis(); //prevent image caching out.print("<img id=\"geneChart\" alt=\"geneChart\" name=\"geneChart\" src=\"" + finalURLpath + "?" + randomness + "\" usemap=\"#" + mapName + "\" border=\"0\" />"); //out.print("<img id=\"geneChart\" name=\"geneChart\" src=\""+finalURLpath+"\" usemap=\"#"+mapName + "\" border=\"0\" />"); } catch (IOException e) { logger.error(e); } catch (Exception e) { logger.error(e); } catch (Throwable t) { logger.error(t); } return EVAL_BODY_INCLUDE; }
From source file:org.codehaus.groovy.grails.web.servlet.DefaultGrailsApplicationAttributes.java
public FlashScope getFlashScope(ServletRequest request) { if (!(request instanceof HttpServletRequest)) { return null; }/*from w w w . ja v a 2 s . com*/ HttpServletRequest servletRequest = (HttpServletRequest) request; HttpSession session = servletRequest.getSession(false); FlashScope fs; if (session != null) { fs = (FlashScope) session.getAttribute(FLASH_SCOPE); } else { fs = (FlashScope) request.getAttribute(FLASH_SCOPE); } if (fs == null) { fs = new GrailsFlashScope(); if (session != null) { session.setAttribute(FLASH_SCOPE, fs); } else { request.setAttribute(FLASH_SCOPE, fs); } } return fs; }
From source file:org.shredzone.cilla.plugin.flattr.FlattrFragmentRenderer.java
/** * Adds the flattr css and js to the page's header. *//*from www . ja va2 s .c om*/ @Override public void onNewDocumentHeader(DocumentHeader header, ServletRequest req) { if (flattrCssTag == null) { flattrCssTag = new CssLinkTag(linkService.linkTo().view("resource").param("package", "flattr") .param("name", "flattr.css").toString()); } if (flattrJsTag == null) { flattrJsTag = new JavaScriptLinkTag(linkService.linkTo().view("resource").param("package", "flattr") .param("name", "flattr.js").toString()); } header.add(flattrCssTag); header.add(flattrJsTag); Page page = (Page) req.getAttribute("page"); if (page != null) { UserId owner = flattrPublicationService.getFlattrThingOwner(page); if (owner != null) { String profile = "https://flattr.com/profile/" + owner.getUserId(); header.add(new LinkTag("me", profile)); } } }
From source file:org.apache.beehive.netui.pageflow.scoping.internal.ScopedRequestImpl.java
public final Object getAttribute(String attrName, boolean allowOuterRequestAttributes) { if (!allowOuterRequestAttributes) return _scopedContainer.getAttribute(attrName); ServletRequest outerRequest = getRequest(); if (!_seeOuterRequestAttributes && _visibleOuterRequestAttrs.contains(attrName)) { return outerRequest.getAttribute(attrName); }/* ww w . ja v a 2s. c o m*/ Object value = _scopedContainer.getAttribute(attrName); if (value == null && _seeOuterRequestAttributes) { value = outerRequest.getAttribute(attrName); } return value; }
From source file:com.vilt.spring.context.response.OncePerRequestContextFilter.java
/** * This <code>doFilter</code> implementation stores a request attribute for * "already filtered", proceeding without filtering again if the attribute * is already there.//from w w w . j a va2 s . c o m * * @see #getAlreadyFilteredAttributeName * @see #doFilterInternal */ public final void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { throw new ServletException("OncePerRequestContextFilter just supports HTTP requests"); } HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String alreadyFilteredAttributeName = getAlreadyFilteredAttributeName(); if (request.getAttribute(alreadyFilteredAttributeName) != null) { // Proceed without invoking this filter... filterChain.doFilter(request, response); return; } // Do invoke this filter... request.setAttribute(alreadyFilteredAttributeName, TRUE); try { doFilterInternal(httpRequest, httpResponse, filterChain); } finally { // Remove the "already filtered" request attribute for this // request. request.removeAttribute(alreadyFilteredAttributeName); } }
From source file:com.cisco.oss.foundation.http.server.AbstractInfraHttpFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // String defaultValue = isEnabledByDefault() + ""; // boolean enabled = getConfigValue(enabledKey, Boolean.valueOf(defaultValue)); // if (enabled) { // doFilterImpl(request, response, chain); // } else { // chain.doFilter(request, response); // }//from ww w .jav a 2 s . c o m Boolean firstRequestProcessing = (Boolean) request.getAttribute("firstRequestProcessing"); if (firstRequestProcessing == null || (firstRequestProcessing != null && firstRequestProcessing)) { String defaultValue = isEnabledByDefault() + ""; boolean enabled = getConfigValue(enabledKey, isEnabledByDefault()); if (enabled) { doFilterImpl(request, response, chain); } else { chain.doFilter(request, response); } } else { chain.doFilter(request, response); } }
From source file:gov.nih.nci.cabig.caaers.web.ae.CaptureAdverseEventController.java
/** * Returns the value associated with the <code>attributeName</code>, if present in * HttpRequest parameter, if not available, will check in HttpRequest attribute map. *///w w w . j av a2 s . c o m protected Object findInRequest(final ServletRequest request, final String attributName) { Object attr = request.getParameter(attributName); if (attr == null) { attr = request.getAttribute(attributName); } return attr; }
From source file:org.mentawai.util.DebugServletFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { PrintWriter writer = res.getWriter(); CharResponseWrapper wrapper = new CharResponseWrapper((HttpServletResponse) res); chain.doFilter(req, wrapper);/* w w w . j a v a 2s.com*/ writer.println(wrapper.toString()); Object debug = req.getAttribute(DEBUG_KEY); if (debug == null) { HttpSession session = ((HttpServletRequest) req).getSession(); if (session != null) { debug = session.getAttribute(DEBUG_KEY); session.removeAttribute(DEBUG_KEY); } } if (debug != null) { if (COMMENTED) writer.println("\n\n<!-- MENTAWAI DEBUG: Begin \n\n"); else writer.println("<pre>\n\n"); writer.println("- - - - - - - - - - - - - - - - Mentawai DEBUG - - - - - - - - - - - - - - - - \n\n"); writer.println(debug.toString()); writer.println("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \n\n"); if (COMMENTED) writer.println("\n\n" + htmlRedFont + "Mentawai Web Framework - Version:" + ApplicationManager.MENTAWAI_VERSION + " Build:" + ApplicationManager.MENTAWAI_BUILD); else writer.println(htmlRedFont + "<b>Mentawai Web Framework</b> - Version:<b>" + ApplicationManager.MENTAWAI_VERSION + " </b> Build:<b>" + ApplicationManager.MENTAWAI_BUILD + "</b>" + htmlCloseFont); if (COMMENTED) writer.println("\n\n MENTA DEBUG : End -->\n"); else writer.println("</pre>\n"); } }