List of usage examples for javax.servlet.http HttpServletRequest getParameterNames
public Enumeration<String> getParameterNames();
Enumeration
of String
objects containing the names of the parameters contained in this request. From source file:eionet.cr.web.action.CustomSearchActionBean.java
/** * *//*from www . j ava 2s .c om*/ private void populateSelectedFilters() { Map<String, String> selectedFilters = getSelectedFilters(); if (!selectedFilters.isEmpty()) { System.out.println("*******************************************"); HttpServletRequest request = getContext().getRequest(); Enumeration paramNames = request.getParameterNames(); while (paramNames != null && paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); String paramValue = request.getParameter(paramName); System.out.println("Request parameter " + paramName + " = " + paramValue); if (paramName.startsWith(SELECTED_VALUE_PREFIX)) { String filterKey = paramName.substring(SELECTED_VALUE_PREFIX.length()); if (filterKey != null && filterKey.length() > 0 && selectedFilters.containsKey(filterKey)) { selectedFilters.put(filterKey, paramValue); } } } System.out.println("*******************************************"); } }
From source file:com.google.reducisaurus.servlets.BaseServlet.java
private Collection<String> getSortedParameterNames(HttpServletRequest req) { // We want a deterministic order so that dependencies can span input files. // We don't trust the servlet container to return query parameters in any // order, so we impose our own ordering. In this case, we use natural String // ordering./*from w w w .j a v a2 s. c o m*/ List<String> list = Lists .newArrayList(Iterators.forEnumeration((Enumeration<String>) req.getParameterNames())); // Some parameter names should be ignored. Iterable<String> filtered = Collections2.filter(list, new Predicate<String>() { @Override public boolean apply(@Nullable String s) { return !(s.contains("_") || s.contains("-")); } }); return Ordering.natural().sortedCopy(filtered); }
From source file:edu.cornell.mannlib.vedit.controller.OperationController.java
private boolean populateObjectFromRequestParamsAndValidate(EditProcessObject epo, Object newObj, HttpServletRequest request) { boolean valid = true; String currParam = ""; Enumeration penum = request.getParameterNames(); while (penum.hasMoreElements()) { currParam = (String) penum.nextElement(); if (!(currParam.indexOf("_") == 0)) { String currValue = request.getParameterValues(currParam)[0]; // "altnew" values come in with the same input name but at position 1 of the array if (currValue.length() == 0 && request.getParameterValues(currParam).length > 1) { currValue = request.getParameterValues(currParam)[1]; }/* www . j a va 2s. co m*/ //validate the entry boolean fieldValid = true; if (request.getParameter("_delete") == null) { // don't do validation if we're deleting List validatorList = (List) epo.getValidatorMap().get(currParam); if (validatorList != null) { Iterator valIt = validatorList.iterator(); String errMsg = ""; while (valIt.hasNext()) { Validator val = (Validator) valIt.next(); ValidationObject vo = val.validate(currValue); if (!vo.getValid()) { valid = false; fieldValid = false; errMsg += vo.getMessage() + " "; epo.getBadValueMap().put(currParam, currValue); } else { try { epo.getBadValueMap().remove(currParam); epo.getErrMsgMap().remove(currParam); } catch (Exception e) { } } } if (errMsg.length() > 0) { epo.getErrMsgMap().put(currParam, errMsg); log.info("doPost() putting error message " + errMsg + " for " + currParam); } } } if (fieldValid) { if (currValue.length() == 0) { Map<String, String> defaultHash = epo.getDefaultValueMap(); try { String defaultValue = defaultHash.get(currParam); if (defaultValue != null) currValue = defaultValue; } catch (Exception e) { } } try { FormUtils.beanSet(newObj, currParam, currValue, epo); epo.getErrMsgMap().remove(currParam); epo.getBadValueMap().remove(currParam); } catch (NumberFormatException e) { if (currValue.length() > 0) { valid = false; epo.getErrMsgMap().put(currParam, "Please enter an integer"); epo.getBadValueMap().put(currParam, currValue); } } catch (NegativeIntegerException nie) { valid = false; epo.getErrMsgMap().put(currParam, "Please enter a positive integer"); epo.getBadValueMap().put(currParam, currValue); } catch (IllegalArgumentException f) { valid = false; log.error("doPost() reports IllegalArgumentException for " + currParam); log.debug("doPost() error message: " + f.getMessage()); epo.getErrMsgMap().put(currParam, f.getMessage()); epo.getBadValueMap().put(currParam, currValue); } } } } return valid; }
From source file:org.apache.shindig.social.core.oauth2.OAuth2NormalizedRequest.java
@SuppressWarnings("unchecked") public OAuth2NormalizedRequest(HttpServletRequest request) throws OAuth2Exception { super();/* w w w .jav a2 s. c o m*/ setHttpServletRequest(request); String contentType = request.getContentType(); if (contentType != null) { Matcher match = FORM_URL_REGEX.matcher(contentType); if (match.matches()) { normalizeBody(getBodyAsString(request)); } } Enumeration<String> keys = request.getParameterNames(); while (keys.hasMoreElements()) { String key = keys.nextElement(); put(key, request.getParameter(key)); } normalizeClientSecret(request); normalizeAccessToken(request); }
From source file:com.jaspersoft.jasperserver.rest.services.RESTReport.java
/** * This method allows the user to create (run/fill) a new report. * /*from ww w . ja va 2 s.co m*/ * * @param req * @param resp * @throws ServiceException */ @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { // We are creating a new report here... // Add all the options... Map<String, String> options = new HashMap<String, String>(); // Add as option all the GET parameters... Enumeration en = req.getParameterNames(); while (en.hasMoreElements()) { String key = (String) en.nextElement(); options.put(key, req.getParameter(key)); } Map<String, Object> parameters = new HashMap<String, Object>(); // We expect the user to send us a ResourceDescriptor with some parameters in it... HttpServletRequest mreq = restUtils.extractAttachments(runReportService, req); String resourceDescriptorXml = null; // get the resource descriptor... if (mreq instanceof MultipartHttpServletRequest) { resourceDescriptorXml = mreq.getParameter(restUtils.REQUEST_PARAMENTER_RD); } else { try { resourceDescriptorXml = IOUtils.toString(req.getInputStream()); } catch (IOException ex) { throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage()); } } if (resourceDescriptorXml == null) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Missing parameter " + restUtils.REQUEST_PARAMENTER_RD + " " + runReportService.getInputAttachments()); return; } // Parse the resource descriptor... InputSource is = new InputSource(new StringReader(resourceDescriptorXml)); Document doc = null; ResourceDescriptor rd = null; try { doc = XMLUtil.getNewDocumentBuilder().parse(is); rd = Unmarshaller.readResourceDescriptor(doc.getDocumentElement()); } catch (SAXException ex) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Invalid resource descriptor"); return; } catch (ServiceException se) { if (se.getErrorCode() == ServiceException.RESOURCE_NOT_FOUND) { restUtils.setStatusAndBody(HttpServletResponse.SC_NOT_FOUND, resp, se.getLocalizedMessage()); throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, se.getMessage()); } else { throw se; } } catch (Exception ex) { throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage()); } // At this point we have a resource descriptor, find the parameters in it and the uri String uri = rd.getUriString(); List params = rd.getParameters(); for (int i = 0; i < params.size(); ++i) { ListItem parameter = (ListItem) params.get(i); if (parameter.isIsListItem()) { // Check if a collection exists for this parameter.. List collection = (List) parameters.get(parameter.getLabel()); if (collection == null) { collection = new ArrayList<String>(); parameters.put(parameter.getLabel(), collection); } collection.add(parameter.getValue()); } else { parameters.put(parameter.getLabel(), parameter.getValue()); } } if (log.isDebugEnabled()) log.debug("Running report " + uri + " with parameters: " + parameters + " and options: " + options); // highcharts report for REST v1 is by default noninteractive. if (!options.containsKey(Argument.PARAM_INTERACTIVE)) { options.put(Argument.PARAM_INTERACTIVE, Boolean.FALSE.toString()); } Map<String, DataSource> attachments = new ConcurrentHashMap<String, DataSource>(); OperationResult or = runReportService.runReport(uri, parameters, options, attachments); if (or.getReturnCode() != 0) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, or.getMessage()); return; } else { JasperPrint jp = (JasperPrint) runReportService.getAttributes().get("jasperPrint"); // Store the attachments in the session, with proper keys... HttpSession session = req.getSession(); String executionId = UUID.randomUUID().toString(); Report report = new Report(); report.setUuid(executionId); report.setOriginalUri(uri); report.setAttachments(attachments); report.setJasperPrint(jp); session.setAttribute(report.getUuid(), report); // Send out the xml... resp.setContentType("text/xml; charset=UTF-8"); restUtils.setStatusAndBody(HttpServletResponse.SC_CREATED, resp, report.toXml()); } }
From source file:net.sourceforge.subsonic.backend.controller.RedirectionController.java
private String getFullRequestURL(HttpServletRequest request) throws UnsupportedEncodingException { StringBuilder builder = new StringBuilder(request.getRequestURL()); // For backwards compatibility; return query parameters in exact same sequence. if ("GET".equalsIgnoreCase(request.getMethod())) { if (request.getQueryString() != null) { builder.append("?").append(request.getQueryString()); }/* w w w. j a v a 2 s . co m*/ return builder.toString(); } builder.append("?"); Enumeration<?> paramNames = request.getParameterNames(); while (paramNames.hasMoreElements()) { String paramName = (String) paramNames.nextElement(); String[] paramValues = request.getParameterValues(paramName); for (String paramValue : paramValues) { String p = URLEncoder.encode(paramValue, "UTF-8"); builder.append(paramName).append("=").append(p).append("&"); } } return builder.toString(); }
From source file:org.jamwiki.servlets.TranslationServlet.java
/** * *//*from ww w. ja v a 2 s . c om*/ private void translate(HttpServletRequest request, WikiPageInfo pageInfo) throws Exception { // first load existing translations SortedProperties translations = new SortedProperties(); String language = this.retrieveLanguage(request); if (!StringUtils.isBlank(language)) { String filename = filename(language); translations.putAll(Environment.loadProperties(filename)); } // now update with translations from the request Enumeration names = request.getParameterNames(); String name; while (names.hasMoreElements()) { name = (String) names.nextElement(); if (!name.startsWith("translations[") || !name.endsWith("]")) { continue; } String key = name.substring("translations[".length(), name.length() - "]".length()); String value = request.getParameter(name); translations.setProperty(key, value); } Environment.saveProperties(filename(language), translations, null); this.writeTopic(request, pageInfo); }
From source file:net.riezebos.thoth.testutil.ThothTestBase.java
protected HttpServletRequest createHttpRequest(String contextName, String path) throws IOException { String fullPath = ThothUtil.prefix(contextName, "/") + path; HttpServletRequest request = mock(HttpServletRequest.class); when(request.getRequestURI()).thenReturn(path); when(request.getContextPath()).thenReturn(ThothUtil.prefix(contextName, "/")); when(request.getServletPath()).thenReturn(path); when(request.getPathInfo()).thenReturn(fullPath); when(request.getParameterNames()).thenReturn(getParameterNames()); recordGetParameter(request);/* w w w .j ava 2s .co m*/ return request; }
From source file:com.github.fge.jsonschema.servlets.SyntaxValidateServlet.java
@Override public void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final Set<String> params = Sets.newHashSet(); /*//from ww w . j ava 2s . co m * First, check our parameters */ /* * Why, in 2013, doesn't servlet-api provide an Iterator<String>? * * Well, at least, Jetty's implementation has a generified Enumeration. * Still, that sucks. */ final Enumeration<String> enumeration = req.getParameterNames(); // FIXME: no duplicates, it seems, but I cannot find the spec which // guarantees that while (enumeration.hasMoreElements()) params.add(enumeration.nextElement()); // We have required parameters if (!params.containsAll(Request.required())) { log.warn("Missing parameters! Someone using me as a web service?"); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing parameters"); return; } // We don't want extraneous parameters params.removeAll(Request.valid()); if (!params.isEmpty()) { log.warn("Invalid parameters! Someone using me as a web service?"); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid parameters"); return; } final String rawSchema = req.getParameter(Request.SCHEMA); // Set correct content type resp.setContentType(MediaType.JSON_UTF_8.toString()); final JsonNode ret; try { ret = buildResult(rawSchema); } catch (ProcessingException e) { // Should not happen! log.error("Uh, syntax validation failed!", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } final OutputStream out = resp.getOutputStream(); try { out.write(ret.toString().getBytes(Charset.forName("UTF-8"))); out.flush(); } finally { Closeables.closeQuietly(out); } }
From source file:org.wso2.carbon.core.transports.CarbonServlet.java
private void processWithGetProcessor(HttpServletRequest request, HttpServletResponse response, String item) throws Exception { OverflowBlob temporaryData = new OverflowBlob(256, 4048, "_servlet", ".dat"); try {// w ww .j a va2 s . c o m CarbonHttpRequest carbonHttpRequest = new CarbonHttpRequest("GET", request.getRequestURI(), request.getRequestURL().toString()); Enumeration names = request.getParameterNames(); while (names.hasMoreElements()) { Object name = names.nextElement(); if (name != null && name instanceof String) { carbonHttpRequest.setParameter((String) name, request.getParameter((String) name)); } } carbonHttpRequest.setContextPath(request.getContextPath()); carbonHttpRequest.setQueryString(request.getQueryString()); CarbonHttpResponse carbonHttpResponse = new CarbonHttpResponse(temporaryData.getOutputStream()); (getRequestProcessors.get(item)).process(carbonHttpRequest, carbonHttpResponse, configContext); // adding headers Map responseHeaderMap = carbonHttpResponse.getHeaders(); for (Object obj : responseHeaderMap.entrySet()) { Map.Entry entry = (Map.Entry) obj; response.setHeader(entry.getKey().toString(), entry.getValue().toString()); } // setting status code response.setStatus(carbonHttpResponse.getStatusCode()); // setting error codes if (carbonHttpResponse.isError()) { if (carbonHttpResponse.getStatusMessage() != null) { response.sendError(carbonHttpResponse.getStatusCode(), carbonHttpResponse.getStatusMessage()); } else { response.sendError(carbonHttpResponse.getStatusCode()); } } if (carbonHttpResponse.isRedirect()) { response.sendRedirect(carbonHttpResponse.getRedirect()); } if (carbonHttpResponse.getHeaders().get(HTTP.CONTENT_TYPE) != null) { response.setContentType(carbonHttpResponse.getHeaders().get(HTTP.CONTENT_TYPE)); } temporaryData.writeTo(response.getOutputStream()); } finally { temporaryData.release(); } }