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:org.mfr.web.PrivateContentAccessManager.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest servletR = ((HttpServletRequest) request); RequestWrapper.httpRequest.set(servletR); try {//from ww w . j a v a 2 s . com String requestUri = servletR.getRequestURI(); Site site = (Site) request.getAttribute(SiteFilter.PORTFOLIOSITE); ; if (requestUri.length() == 1) { if (!SiteDao.isSitePasswordRequired(site) && !HttpHelper.isSiteGranted(site)) { request.getRequestDispatcher("/index.zul").forward(request, response); return; } else { if (SiteDao.isSitePasswordRequired(site) && !HttpHelper.isSiteGranted(site)) { request.getRequestDispatcher("/privateaccess.zul").forward(request, response); } else { request.getRequestDispatcher("/pindex.zul").forward(request, response); } return; } } int lastIndex = requestUri.lastIndexOf("/"); requestUri = requestUri.substring(lastIndex); logger.debug("pageActUri [" + requestUri + "]"); request.setAttribute(GlobalVariableResolver.PAGEACTURI, requestUri); User user = HttpHelper.getUser(((HttpServletRequest) request).getSession()); String threadName = Thread.currentThread().getName(); try { Thread.currentThread().setName( requestUri + "-" + ((HttpServletRequest) request).getSession().getId() + "-" + count++); List<String> actualAllowedPages = null; String redirectUrl = null; boolean hasPermission = hasPermission(requestUri); if (!SiteDao.isSitePasswordRequired(site) && SiteDao.notIsPublicOrOwner(site)) { actualAllowedPages = allowedPage; redirectUrl = LoginComposer.INDEXPAGE; } else { if (GlobalVariableResolver.isSiteOwner()) { redirectUrl = LoginComposer.PINDEXPAGE; } else if (SiteDao.isSitePasswordRequired(site) && !HttpHelper.isPasswordAccessGranted(site)) { redirectUrl = "/privateaccess.zul"; } else { redirectUrl = LoginComposer.PINDEXPAGE; } actualAllowedPages = portfolioAllowedPage; } if (!hasPermission && (!actualAllowedPages.contains(requestUri) && user == null) || (site != null && !redirectUrl.equals(requestUri) && (!actualAllowedPages.contains(requestUri) || !HttpHelper.isSiteGranted(site)))) { request.getRequestDispatcher(redirectUrl).forward(request, response); } else { filterChain.doFilter(request, response); } } catch (ServletException e) { logger.error("doFilter", e); throw e; } finally { Thread.currentThread().setName(threadName); } } catch (Exception e) { logger.error("filter", e); } finally { RequestWrapper.httpRequest.set(null); } }
From source file:gov.nih.nci.ispy.web.taglib.PCAPlotTag.java
public int doStartTag() { chart = null;/*from ww w . j a va 2s . c o m*/ pcaResults = null; pcaData.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 PCAData points PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache .getSessionFinding(session.getId(), taskId); Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); List<String> sampleIds = new ArrayList<String>(); Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>(); pcaResults = principalComponentAnalysisFinding.getResultEntries(); for (PCAresultEntry pcaEntry : pcaResults) { sampleIds.add(pcaEntry.getSampleId()); pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry); } //Get the clinical data for the sampleIds ClinicalDataService cqs = ClinicalDataServiceFactory.getInstance(); IdMapperFileBasedService idMapper = IdMapperFileBasedService.getInstance(); //Map<String, ClinicalData> clinicalDataMap = cqs.getClinicalDataMapForLabtrackIds(sampleIds); PCAresultEntry entry; //ClinicalData clinData; //PatientData patientData; SampleInfo si; TimepointType timepoint; for (String id : sampleIds) { entry = pcaResultMap.get(id); ISPYPCADataPoint pcaPoint = new ISPYPCADataPoint(id, entry.getPc1(), entry.getPc2(), entry.getPc3()); si = idMapper.getSampleInfoForLabtrackId(id); //clinData = cqs.getClinicalDataForPatientDID(si.getRegistrantId(), si.getTimepoint()); //patientData = cqs.getPatientDataForPatientDID(si.getISPYId()); Set<String> ispyIds = new HashSet<String>(); ispyIds.add(si.getISPYId()); ISPYclinicalDataQueryDTO dto = new ISPYclinicalDataQueryDTO(); dto.setRestrainingSamples(ispyIds); Set<PatientData> pdSet = cqs.getClinicalData(dto); for (PatientData patientData : pdSet) { pcaPoint.setISPY_ID(si.getISPYId()); timepoint = si.getTimepoint(); pcaPoint.setTimepoint(timepoint); if (patientData != null) { pcaPoint.setClinicalStage(patientData.getClinicalStage()); int clinRespVal; Double mriPctChange = null; if (timepoint == TimepointType.T1) { pcaPoint.setClinicalResponse(ClinicalResponseType.NA); pcaPoint.setTumorMRIpctChange(null); } else if (timepoint == TimepointType.T2) { clinRespVal = PatientData.parseValue(patientData.getClinRespT1_T2()); //set the clinical respoinse to the T1_T2 pcaPoint.setClinicalResponse(ClinicalResponseType.getTypeForValue(clinRespVal)); pcaPoint.setTumorMRIpctChange(patientData.getMriPctChangeT1_T2()); } else if (timepoint == TimepointType.T3) { //set the clinical response to T1_T3 clinRespVal = PatientData.parseValue(patientData.getClinRespT1_T3()); pcaPoint.setClinicalResponse(ClinicalResponseType.getTypeForValue(clinRespVal)); pcaPoint.setTumorMRIpctChange(patientData.getMriPctChangeT1_T3()); } else if (timepoint == TimepointType.T4) { //set the clinical response to T1_T4 clinRespVal = PatientData.parseValue(patientData.getClinRespT1_T4()); pcaPoint.setClinicalResponse(ClinicalResponseType.getTypeForValue(clinRespVal)); pcaPoint.setTumorMRIpctChange(patientData.getMriPctChangeT1_T4()); } else { pcaPoint.setClinicalResponse(ClinicalResponseType.UNKNOWN); pcaPoint.setTumorMRIpctChange(null); } } pcaData.add(pcaPoint); } } //check the components to see which graph to get if (components.equalsIgnoreCase("PC1vsPC2")) { ISPYPrincipalComponentAnalysisPlot plot = new ISPYPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC2, PCAcomponent.PC1, ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase())); chart = plot.getChart(); } if (components.equalsIgnoreCase("PC1vsPC3")) { ISPYPrincipalComponentAnalysisPlot plot = new ISPYPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC3, PCAcomponent.PC1, ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase())); chart = plot.getChart(); } if (components.equalsIgnoreCase("PC2vsPC3")) { ISPYPrincipalComponentAnalysisPlot plot = new ISPYPrincipalComponentAnalysisPlot(pcaData, PCAcomponent.PC3, PCAcomponent.PC2, ColorByType.valueOf(ColorByType.class, colorBy.toUpperCase())); chart = plot.getChart(); } ISPYImageFileHandler imageHandler = new ISPYImageFileHandler(session.getId(), "png", 650, 600); //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(); //PrintWriter writer = new PrintWriter(new FileWriter(mapName)); ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 650, 600, info); //ImageMapUtil.writeBoundingRectImageMap(writer,"PCAimageMap",info,true); //writer.close(); /* 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("\\", "/"); long randomness = System.currentTimeMillis(); //prevent image caching out.print("<img id=\"geneChart\" name=\"geneChart\" src=\"" + finalURLpath + "?" + randomness + "\" usemap=\"#" + mapName + "\" border=\"0\" />"); //(imageHandler.getImageTag(mapFileName)); } 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.eclipse.skalli.view.internal.filter.ProjectDetailsFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; String userId = (String) request.getAttribute(Consts.ATTRIBUTE_USERID); Project project = (Project) request.getAttribute(Consts.ATTRIBUTE_PROJECT); boolean isProjectAdmin = BooleanUtils .toBoolean((Boolean) request.getAttribute(Consts.ATTRIBUTE_PROJECTADMIN)); boolean isProjectAdminInParentChain = BooleanUtils .toBoolean((Boolean) request.getAttribute(Consts.ATTRIBUTE_PARENTPROJECTADMIN)); String action = request.getParameter(Consts.PARAM_ACTION); String windowName = StringUtils.strip(httpRequest.getPathInfo(), "/"); //$NON-NLS-1$ if (project != null) { if (!project.isDeleted()) { windowName = project.getProjectId(); } else {//from w w w . ja va 2s . c o m windowName = project.getUuid().toString(); } ProjectTemplateService templateService = Services.getRequiredService(ProjectTemplateService.class); ProjectTemplate projectTemplate = templateService .getProjectTemplateById(project.getProjectTemplateId()); request.setAttribute(Consts.ATTRIBUTE_PROJECTTEMPLATE, projectTemplate); request.setAttribute(Consts.ATTRIBUTE_NATURE, projectTemplate.getProjectNature().toString()); if (userId != null) { FavoritesService favoritesService = Services.getService(FavoritesService.class); Favorites favorites = null; if (favoritesService == null) { favorites = new Favorites(userId); } else { favorites = favoritesService.getFavorites(userId); } request.setAttribute(Consts.ATTRIBUTE_FAVORITES, favorites.asMap()); boolean showIssues = isProjectAdmin || isProjectAdminInParentChain; request.setAttribute(Consts.ATTRIBUTE_SHOW_ISSUES, isProjectAdmin); if (showIssues) { IssuesService issuesService = Services.getService(IssuesService.class); if (issuesService != null) { if (Consts.PARAM_VALUE_VALIDATE.equals(action)) { ValidationService validationService = Services.getService(ValidationService.class); if (validationService != null) { validationService.validate(Project.class, project.getUuid(), Severity.INFO, userId); } } Issues issues = issuesService.getByUUID(project.getUuid()); if (issues != null && issues.hasIssues()) { request.setAttribute(Consts.ATTRIBUTE_ISSUES, issues); request.setAttribute(Consts.ATTRIBUTE_MAX_SEVERITY, issues.getIssues().first().getSeverity().name()); } } } request.setAttribute(Consts.ATTRIBUTE_PROJECTCONTEXTLINKS, getOrderedVisibleProjectContextLinks(project, userId)); } String pathInfo = httpRequest.getPathInfo(); if (pathInfo != null) { int infoBoxIndex = pathInfo.indexOf(Consts.URL_INFOBOXES); if (infoBoxIndex > 0) { if (StringUtils.isNotBlank(action)) { String infoBoxShortName = pathInfo.substring(infoBoxIndex + Consts.URL_INFOBOXES.length()); if (infoBoxShortName.startsWith(FilterUtil.PATH_SEPARATOR)) { infoBoxShortName = infoBoxShortName.substring(1); } filterInfobox(project, infoBoxShortName, action, userId); } } } } request.setAttribute(Consts.ATTRIBUTE_WINDOWNAME, windowName); request.setAttribute(Consts.ATTRIBUTE_EDITMODE, false); String appUri = Consts.URL_VAADIN_PROJECTS + windowName; if (StringUtils.isNotBlank(action)) { if (action.equals(Consts.PARAM_VALUE_EDIT)) { request.setAttribute(Consts.ATTRIBUTE_EDITMODE, true); appUri = appUri + "/edit"; //$NON-NLS-1$ } } request.setAttribute(Consts.ATTRIBUTE_APP_URI, appUri); // proceed along the chain chain.doFilter(request, response); }
From source file:gov.nih.nci.rembrandt.web.taglib.PCAPlotTag.java
public int doStartTag() { chart = null;//from w ww. ja v a 2s.co m pcaResults = null; pcaData.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 PCAData points PrincipalComponentAnalysisFinding principalComponentAnalysisFinding = (PrincipalComponentAnalysisFinding) businessTierCache .getSessionFinding(session.getId(), taskId); Collection<ClinicalFactorType> clinicalFactors = new ArrayList<ClinicalFactorType>(); List<String> sampleIds = new ArrayList<String>(); Map<String, PCAresultEntry> pcaResultMap = new HashMap<String, PCAresultEntry>(); if (principalComponentAnalysisFinding != null) { pcaResults = principalComponentAnalysisFinding.getResultEntries(); for (PCAresultEntry pcaEntry : pcaResults) { sampleIds.add(pcaEntry.getSampleId()); pcaResultMap.put(pcaEntry.getSampleId(), pcaEntry); } Collection<SampleResultset> validatedSampleResultset = ClinicalDataValidator .getValidatedSampleResultsetsFromSampleIDs(sampleIds, clinicalFactors); if (validatedSampleResultset != null) { String id; PCAresultEntry entry; for (SampleResultset rs : validatedSampleResultset) { id = rs.getBiospecimen().getSpecimenName(); entry = pcaResultMap.get(id); PrincipalComponentAnalysisDataPoint pcaPoint = new PrincipalComponentAnalysisDataPoint(id, entry.getPc1(), entry.getPc2(), entry.getPc3()); String diseaseName = rs.getDisease().getValueObject(); if (diseaseName != null) { pcaPoint.setDiseaseName(diseaseName); } else { pcaPoint.setDiseaseName(DiseaseType.NON_TUMOR.name()); } GenderDE genderDE = rs.getGenderCode(); if (genderDE != null && genderDE.getValue() != null) { String gt = genderDE.getValueObject().trim(); if (gt != null) { GenderType genderType = GenderType.valueOf(gt); if (genderType != null) { pcaPoint.setGender(genderType); } } } Long survivalLength = rs.getSurvivalLength(); if (survivalLength != null) { //survival length is stored in days in the DB so divide by 30 to get the //approx survival in months double survivalInMonths = survivalLength.doubleValue() / 30.0; pcaPoint.setSurvivalInMonths(survivalInMonths); } pcaData.add(pcaPoint); } } PCAcomponent pone = PCAcomponent.PC1; PCAcomponent ptwo = PCAcomponent.PC2; //check the components to see which graph to get if (components.equalsIgnoreCase("PC1vsPC2")) { pone = PCAcomponent.PC2; ptwo = PCAcomponent.PC1; //chart = (JFreeChart) CaIntegratorChartFactory.getPrincipalComponentAnalysisGraph(pcaData,PCAcomponent.PC2,PCAcomponent.PC1,PCAcolorByType.valueOf(PCAcolorByType.class,colorBy)); } if (components.equalsIgnoreCase("PC1vsPC3")) { pone = PCAcomponent.PC3; ptwo = PCAcomponent.PC1; //chart = (JFreeChart) CaIntegratorChartFactory.getPrincipalComponentAnalysisGraph(pcaData,PCAcomponent.PC3,PCAcomponent.PC1,PCAcolorByType.valueOf(PCAcolorByType.class,colorBy)); } if (components.equalsIgnoreCase("PC2vsPC3")) { pone = PCAcomponent.PC2; ptwo = PCAcomponent.PC3; //chart = (JFreeChart) CaIntegratorChartFactory.getPrincipalComponentAnalysisGraph(pcaData,PCAcomponent.PC3,PCAcomponent.PC2,PCAcolorByType.valueOf(PCAcolorByType.class,colorBy)); } PrincipalComponentAnalysisPlot plot = new RBTPrincipalComponentAnalysisPlot(pcaData, pone, ptwo, PCAcolorByType.valueOf(PCAcolorByType.class, colorBy)); if (plot != null) { chart = (JFreeChart) plot.getChart(); } RembrandtImageFileHandler imageHandler = new RembrandtImageFileHandler(session.getId(), "png", 650, 600); //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(); //PrintWriter writer = new PrintWriter(new FileWriter(mapName)); ChartUtilities.writeChartAsPNG(new FileOutputStream(finalPath), chart, 650, 600, info); //ImageMapUtil.writeBoundingRectImageMap(writer,"PCAimageMap",info,true); //writer.close(); /* 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("\\", "/"); long randomness = System.currentTimeMillis(); //prevent image caching out.print("<img id=\"geneChart\" name=\"geneChart\" alt=\"geneChart\" src=\"" + finalURLpath + "?" + randomness + "\" usemap=\"#" + mapName + "\" border=\"0\" />"); //(imageHandler.getImageTag(mapFileName)); } } 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:com.day.cq.wcm.foundation.forms.FormsHelper.java
/** * Returns whether there should be a redirect to the HTTP referrer after the * forward of a form POST request./*ww w . j a v a 2s .c o m*/ * * @since 5.5 * * @param request * current request * @return <code>true</code> if there should be a redirect to the referrer */ public static boolean isRedirectToReferrer(ServletRequest request) { return "true".equals(request.getAttribute(REQ_ATTR_REDIRECT_TO_REFERRER)); }
From source file:com.day.cq.wcm.foundation.forms.FormsHelper.java
/** * Returns the redirect to inject as ":redirect" parameter for the Sling * POST servlet, when a form//from w w w .jav a2 s . com * {@link #setForwardPath(SlingHttpServletRequest, String) forward} is done. * * @since 5.5 * * @param request * the current request * @returna redirect path/url */ public static String getForwardRedirect(final ServletRequest request) { return (String) request.getAttribute(REQ_ATTR_REDIRECT); }
From source file:com.sinosoft.one.mvc.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 ww w .j a va2 s . 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("$$one-mvc.attributesBeforeInclude", attributesSnapshot); }
From source file:com.day.cq.wcm.foundation.forms.FormsHelper.java
/** * Gets the Sling {@link RequestDispatcherOptions} to be used when * forwarding to {@link #getForwardPath(SlingHttpServletRequest)}. * //from ww w. j av a2 s .com * @since 5.5 * * @param req * The current request * @return options to use with forward path or <code>null</code> */ public static RequestDispatcherOptions getForwardOptions(final ServletRequest req) { return (RequestDispatcherOptions) req.getAttribute(REQ_ATTR_FORWARD_OPTIONS); }
From source file:net.paoding.rose.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 av 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-rose.attributesBeforeInclude", attributesSnapshot); }
From source file:org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.java
/** * {@inheritDoc}//from w w w . jav a2s . c o m * * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, * javax.servlet.FilterChain) */ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ServletRequest filteredRequest = request; // This filter works only for HTTP requests, because they are the only ones with a session. if (request instanceof HttpServletRequest && !Boolean.valueOf((String) request.getAttribute(ATTRIBUTE_APPLIED))) { // Get the saved request, if any (returns null if not applicable) SavedRequest savedRequest = getSavedRequest((HttpServletRequest) request); // Merge the new and the saved request filteredRequest = new SavedRequestWrapper((HttpServletRequest) request, savedRequest); filteredRequest.setAttribute(ATTRIBUTE_APPLIED, "true"); } // Forward the request chain.doFilter(filteredRequest, response); // Allow multiple calls to this filter as long as they are not nested. filteredRequest.removeAttribute(ATTRIBUTE_APPLIED); }