List of usage examples for javax.servlet.http HttpServletRequest getParameter
public String getParameter(String name);
String
, or null
if the parameter does not exist. From source file:com.ibm.jaggr.service.impl.transport.AbstractHttpTransport.java
/** * This method checks the request for the has conditions which may either be contained in URL * query arguments or in a cookie sent from the client. * //from w w w . j a v a 2 s . com * @return The has conditions from the request. * @throws UnsupportedEncodingException */ protected static String getHasConditionsFromRequest(HttpServletRequest request) throws IOException { String ret = null; if (request.getParameter(FEATUREMAPHASH_REQPARAM) != null) { // The cookie called 'has' contains the has conditions Cookie[] cookies = request.getCookies(); if (cookies != null) { for (int i = 0; ret == null && i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(FEATUREMAP_REQPARAM) && cookie.getValue() != null) { ret = URLDecoder.decode(cookie.getValue(), "US-ASCII"); //$NON-NLS-1$ break; } } } if (ret == null) { if (log.isLoggable(Level.WARNING)) { StringBuffer url = request.getRequestURL(); if (url != null) { // might be null if using mock request for unit testing url.append("?").append(request.getQueryString()).toString(); //$NON-NLS-1$ log.warning(MessageFormat.format(Messages.AbstractHttpTransport_0, new Object[] { url, request.getHeader("User-Agent") })); //$NON-NLS-1$ } } } } else ret = request.getParameter(FEATUREMAP_REQPARAM); return ret; }
From source file:com.vmware.identity.SharedUtils.java
/** * Create mock request based on the url/* w ww .j a v a 2 s . co m*/ * * @param string * @return * @throws MalformedURLException * @throws UnsupportedEncodingException */ public static HttpServletRequest buildMockRequestObjectFromUrl(String string) throws MalformedURLException, UnsupportedEncodingException { Cookie[] expectedCookies = new Cookie[] {}; URL url = new URL(string); Map<String, String> queryMap = getQueryMap(url.getQuery()); String samlRequestParameter = getParameterFromQueryMap(queryMap, Shared.SAML_REQUEST_PARAMETER); String relayStateParameter = getParameterFromQueryMap(queryMap, Shared.RELAY_STATE_PARAMETER); String sigAlgParameter = getParameterFromQueryMap(queryMap, Shared.SIGNATURE_ALGORITHM_PARAMETER); String signatureParameter = getParameterFromQueryMap(queryMap, Shared.SIGNATURE_PARAMETER); StringBuffer sbRequestUrl = new StringBuffer(); sbRequestUrl.append(string.replace("?" + url.getQuery(), "")); // build mock request object HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getCookies()).andReturn(expectedCookies).anyTimes(); expect(request.getParameter(Shared.SAML_REQUEST_PARAMETER)).andReturn(samlRequestParameter).anyTimes(); expect(request.getParameter(Shared.RELAY_STATE_PARAMETER)).andReturn(relayStateParameter).anyTimes(); expect(request.getParameter(Shared.SIGNATURE_ALGORITHM_PARAMETER)).andReturn(sigAlgParameter).anyTimes(); expect(request.getParameter(Shared.SIGNATURE_PARAMETER)).andReturn(signatureParameter).anyTimes(); expect(request.getRequestURL()).andReturn(sbRequestUrl).anyTimes(); expect(request.getParameter(Shared.REQUEST_AUTH_PARAM)).andReturn(TestConstants.AUTHORIZATION).anyTimes(); String queryString = Shared.SAML_REQUEST_PARAMETER + "=" + samlRequestParameter; if (relayStateParameter != null) { queryString = queryString + "&" + Shared.RELAY_STATE_PARAMETER + "=" + relayStateParameter; } if (sigAlgParameter != null) { queryString = queryString + "&" + Shared.SIGNATURE_ALGORITHM_PARAMETER + "=" + sigAlgParameter; } if (signatureParameter != null) { queryString = queryString + "&" + Shared.SIGNATURE_PARAMETER + "=" + signatureParameter; } expect(request.getQueryString()).andReturn(queryString).anyTimes(); replay(request); return request; }
From source file:ispyb.client.common.util.FileUtil.java
public static boolean isJpgForImage(Image3VO imageVO, HttpServletRequest request) throws Exception { boolean isJpg = false; Integer proposalId = (Integer) request.getSession().getAttribute(Constants.PROPOSAL_ID); if (proposalId == null) { try {//from w ww . j av a 2s .c o m proposalId = new Integer(request.getParameter(Constants.PROPOSAL_ID)); } catch (NumberFormatException e) { if (Confidentiality.isManager(request) || Confidentiality.isLocalContact(request)) { // isLocalContact or isManager = true; String sourceFileName = imageVO.getJpegFileFullPath(); sourceFileName = PathUtils.FitPathToOS(sourceFileName); isJpg = FileUtil.fileExists(sourceFileName); return isJpg; } return false; } } // Ejb3ServiceLocator ejb3ServiceLocator = Ejb3ServiceLocator.getInstance(); // Image3Service imageService = (Image3Service) ejb3ServiceLocator.getLocalService(Image3Service.class); // two variables to guarantee the user fecths only its own images // ArrayList imageFetchedList = (ArrayList) imgFacade.findByImageIdAndProposalId(imageId, proposalId); // List<Image3VO> imageFetchedList = imageService.findByImageIdAndProposalId(imageId, proposalId); // Image3VO imgValue = imageService.findByPk(imageId); Integer proposalIdFromImage = imageVO.getDataCollectionVO().getDataCollectionGroupVO().getSessionVO() .getProposalVOId(); if (proposalIdFromImage.equals(proposalId)) { String sourceFileName = imageVO.getJpegFileFullPath(); sourceFileName = PathUtils.FitPathToOS(sourceFileName); isJpg = FileUtil.fileExists(sourceFileName); } return isJpg; }
From source file:net.duckling.ddl.util.ResourceQuery.java
private static List<Integer> getTagIds(HttpServletRequest request) { String tagIdsStr = StringUtils.defaultIfBlank(request.getParameter("tagId"), null); if (tagIdsStr == null) { int[] tagIds = WebParamUtil.getIntegerValues(request, "tag"); List<Integer> ids = new ArrayList<Integer>(); for (int i : tagIds) { ids.add(i);//from w w w. j a v a 2s. co m } return ids; } String[] tagIdsArray = tagIdsStr.split("_"); List<Integer> tagIds = new ArrayList<Integer>(); if (tagIdsArray != null && tagIdsArray.length > 0) { for (String tagIdTemp : tagIdsArray) { tagIds.add(Integer.parseInt(tagIdTemp)); } } return tagIds; }
From source file:com.feilong.servlet.http.RequestUtil.java
/** * request?./*from ww w .j av a 2s .c o m*/ * * @param request * ? * @param paramName * ??? * @return request? */ public static String getParameter(HttpServletRequest request, String paramName) { return request.getParameter(paramName); }
From source file:com.redhat.rhn.frontend.taglibs.list.ListTagUtil.java
/** * Renders the filter UI//from w w w. j ava 2 s. c o m * @param pageContext caller's page context * @param filter ListFilter instance * @param uniqueName name of the list * @param width width of the list * @param columnCount list's column count * @param searchParent true if list tag allows searching of parent * @param searchChild true if the list tag allows searching of child * @throws JspException if something bad happens writing to the page */ public static void renderFilterUI(PageContext pageContext, ListFilter filter, String uniqueName, String width, int columnCount, boolean searchParent, boolean searchChild) throws JspException { LocalizationService ls = LocalizationService.getInstance(); HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String filterByKey = makeFilterByLabel(uniqueName); String filterBy = request.getParameter(filterByKey); String filterValueKey = makeFilterValueByLabel(uniqueName); String filterName = makeFilterNameByLabel(uniqueName); String filterValue = ListTagHelper.getFilterValue(pageContext.getRequest(), uniqueName); //We set this so we know next time around what the old filter value was ListTagUtil.write(pageContext, String.format(HIDDEN_TEXT, makeOldFilterValueByLabel(uniqueName), StringEscapeUtils.escapeHtml(filterValue))); List fields = filter.getFieldNames(); if (fields == null || fields.size() == 0) { throw new JspException("ListFilter.getFieldNames() returned no field names"); } else if (fields.size() == 1) { ListTagUtil.write(pageContext, "<input type=\"hidden\" name=\""); ListTagUtil.write(pageContext, filterByKey); ListTagUtil.write(pageContext, "\" value=\""); ListTagUtil.write(pageContext, fields.get(0).toString()); ListTagUtil.write(pageContext, "\" />"); } else { ListTagUtil.write(pageContext, ls.getMessage("message.filterby.multiple")); ListTagUtil.write(pageContext, "<select name=\""); ListTagUtil.write(pageContext, filterByKey); ListTagUtil.write(pageContext, "\">"); for (Iterator iter = fields.iterator(); iter.hasNext();) { String field = (String) iter.next(); ListTagUtil.write(pageContext, "<option value=\""); ListTagUtil.write(pageContext, field); ListTagUtil.write(pageContext, "\" "); if (field.equals(filterBy)) { ListTagUtil.write(pageContext, "selected"); } ListTagUtil.write(pageContext, ">"); ListTagUtil.write(pageContext, field); ListTagUtil.write(pageContext, "</option>"); } ListTagUtil.write(pageContext, "</select>"); } filterValue = StringUtil.nullOrValue(filterValue); StringBuilder sb = new StringBuilder(); // create a new row sb.append("<div class=\"input-group input-group-sm\">"); String placeHolder = StringUtils.defaultString(ls.getMessage("message.filterby", fields.get(0).toString())); sb.append(String.format( "<input autofocus=\"autofocus\" type=\"text\" " + " name=\"%s\" value=\"%s\" class=\"form-control\" placeholder=\"%s\"/>", filterValueKey, (filterValue != null ? StringEscapeUtils.escapeHtml(filterValue) : ""), StringEscapeUtils.escapeHtml(placeHolder))); sb.append("<span class=\"input-group-btn\">"); sb.append(String.format( "<button value=\"%s\" type=\"submit\" name=\"%s\" " + " class=\"btn btn-default spacewalk-button-filter\"><i class=\"fa fa-eye\"></i>", ls.getMessage(RequestContext.FILTER_KEY), filterName)); sb.append("</button>"); sb.append("</span>"); sb.append("</div>"); ListTagUtil.write(pageContext, sb.toString()); }
From source file:info.magnolia.cms.Aggregator.java
/** * Collect content from the pre configured repository and attach it to the HttpServletRequest. * @throws PathNotFoundException//w w w . j av a 2 s .c om * @throws RepositoryException */ public static boolean collect(HttpServletRequest request) throws PathNotFoundException, RepositoryException { String uri = StringUtils.substringBeforeLast(Path.getURI(request), "."); //$NON-NLS-1$ String extension = StringUtils.substringAfterLast(Path.getURI(request), "."); //$NON-NLS-1$ HierarchyManager hierarchyManager = MgnlContext.getHierarchyManager(ContentRepository.WEBSITE); Content requestedPage = null; NodeData requestedData = null; Template template = null; if (hierarchyManager.isPage(uri)) { requestedPage = hierarchyManager.getContent(uri); // ATOM // check if its a request for a versioned page if (request.getParameter(VERSION_NUMBER) != null) { // get versioned state try { requestedPage = requestedPage.getVersionedContent(request.getParameter(VERSION_NUMBER)); } catch (RepositoryException re) { log.debug(re.getMessage(), re); log.error("Unable to get versioned state, rendering current state of " + uri); } } String templateName = requestedPage.getMetaData().getTemplate(); if (StringUtils.isBlank(templateName)) { log.error("No template configured for page [{}].", requestedPage.getHandle()); //$NON-NLS-1$ } template = TemplateManager.getInstance().getInfo(templateName, extension); if (template == null) { log.error("Template [{}] for page [{}] not found.", //$NON-NLS-1$ templateName, requestedPage.getHandle()); } } else { if (hierarchyManager.isNodeData(uri)) { requestedData = hierarchyManager.getNodeData(uri); } else { // check again, resource might have different name int lastIndexOfSlash = uri.lastIndexOf("/"); //$NON-NLS-1$ if (lastIndexOfSlash > 0) { uri = StringUtils.substringBeforeLast(uri, "/"); //$NON-NLS-1$ try { requestedData = hierarchyManager.getNodeData(uri); } catch (PathNotFoundException e) { // no page available return false; } catch (RepositoryException e) { log.debug(e.getMessage(), e); return false; } } } if (requestedData != null) { String templateName = requestedData.getAttribute("nodeDataTemplate"); //$NON-NLS-1$ if (!StringUtils.isEmpty(templateName)) { template = TemplateManager.getInstance().getInfo(templateName, extension); } } else { return false; } } // Attach all collected information to the HttpServletRequest. if (requestedPage != null) { request.setAttribute(Aggregator.ACTPAGE, requestedPage); request.setAttribute(Aggregator.CURRENT_ACTPAGE, requestedPage); } if ((requestedData != null) && (requestedData.getType() == PropertyType.BINARY)) { File file = new File(); file.setProperties(requestedData); file.setNodeData(requestedData); request.setAttribute(Aggregator.FILE, file); } request.setAttribute(Aggregator.HANDLE, uri); request.setAttribute(Aggregator.EXTENSION, extension); request.setAttribute(Aggregator.HIERARCHY_MANAGER, hierarchyManager); request.setAttribute(Aggregator.TEMPLATE, template); return true; }
From source file:edu.stanford.epad.epadws.handlers.HandlerUtil.java
public static File getUploadedFile(HttpServletRequest httpRequest) { String uploadDirPath = EPADConfig.getEPADWebServerFileUploadDir() + "temp" + Long.toString(System.currentTimeMillis()); File uploadDir = new File(uploadDirPath); uploadDir.mkdirs();/*from www . j a v a2 s . c om*/ String fileName = httpRequest.getParameter("fileName"); String tempXMLFileName = "temp" + System.currentTimeMillis() + "-annotation.xml"; if (fileName != null) tempXMLFileName = "temp" + System.currentTimeMillis() + "-" + fileName; File uploadedFile = new File(uploadDir, tempXMLFileName); try { // opens input stream of the request for reading data InputStream inputStream = httpRequest.getInputStream(); // opens an output stream for writing file FileOutputStream outputStream = new FileOutputStream(uploadedFile); byte[] buffer = new byte[4096]; int bytesRead = -1; log.info("Receiving data..."); int len = 0; while ((bytesRead = inputStream.read(buffer)) != -1) { len = len + bytesRead; outputStream.write(buffer, 0, bytesRead); } log.debug("Data received, len:" + len); outputStream.close(); inputStream.close(); if (len == 0) { try { uploadedFile.delete(); uploadDir.delete(); } catch (Exception x) { } uploadedFile = null; } else log.debug("Created File:" + uploadedFile.getAbsolutePath()); if (len > 0 && (tempXMLFileName.endsWith(".xml") || tempXMLFileName.endsWith(".txt"))) { log.debug("PUT Data:" + readFile(uploadedFile)); } // if (fileType != null) // { // File changeFileExt = new File(uploadedFile.getParentFile(), tempXMLFileName.substring(0, tempXMLFileName.length()-3) + fileType); // uploadedFile.renameTo(changeFileExt); // uploadedFile = changeFileExt; // } return uploadedFile; } catch (Exception x) { log.warning("Error receiving Annotations file", x); } return null; }
From source file:org.openmrs.module.webservices.rest.web.RestUtil.java
/** * Convenience method to get the given param out of the given request. * /*from w w w . ja v a2 s. co m*/ * @param request the WebRequest to look in * @param param the string name to fetch * @return null if the param doesn't exist or is not a valid integer */ private static Integer getIntegerParam(HttpServletRequest request, String param) { String paramString = request.getParameter(param); if (paramString != null) { try { Integer tempInt = new Integer(paramString); return tempInt; // return the valid value } catch (NumberFormatException e) { log.debug("unable to parse '" + param + "' parameter into a valid integer: " + paramString); } } return null; }
From source file:fr.paris.lutece.plugins.mylutece.web.MyLuteceApp.java
/** * Set the current url// w ww . j ava2 s. c o m * @param request The Http request * */ public static void setCurrentUrl(HttpServletRequest request) { String strCurrentUrl = request.getRequestURI(); UrlItem url = new UrlItem(strCurrentUrl); Enumeration enumParams = request.getParameterNames(); while (enumParams.hasMoreElements()) { String strParamName = (String) enumParams.nextElement(); url.addParameter(strParamName, request.getParameter(strParamName)); } HttpSession session = request.getSession(true); session.setAttribute(ATTRIBUTE_CURRENT_URL, url.getUrl()); }