Esempio n. 1
0
  /**
   * Parse the parameters of this request, if it has not already occurred. If parameters are present
   * in both the query string and the request content, they are merged.
   */
  protected void parseParameters() {
    if (parsed) return;
    ParameterMap results = parameters;
    if (results == null) results = new ParameterMap();
    results.setLocked(false);
    String encoding = getCharacterEncoding();
    if (encoding == null) encoding = "ISO-8859-1";

    // Parse any parameters specified in the query string
    String queryString = getQueryString();
    try {
      RequestUtil.parseParameters(results, queryString, encoding);
    } catch (UnsupportedEncodingException e) {;
    }

    // Parse any parameters specified in the input stream
    String contentType = getContentType();
    if (contentType == null) contentType = "";
    int semicolon = contentType.indexOf(';');
    if (semicolon >= 0) {
      contentType = contentType.substring(0, semicolon).trim();
    } else {
      contentType = contentType.trim();
    }
    if ("POST".equals(getMethod())
        && (getContentLength() > 0)
        && "application/x-www-form-urlencoded".equals(contentType)) {
      try {
        int max = getContentLength();
        int len = 0;
        byte buf[] = new byte[getContentLength()];
        ServletInputStream is = getInputStream();
        while (len < max) {
          int next = is.read(buf, len, max - len);
          if (next < 0) {
            break;
          }
          len += next;
        }
        is.close();
        if (len < max) {
          throw new RuntimeException("Content length mismatch");
        }
        RequestUtil.parseParameters(results, buf, encoding);
      } catch (UnsupportedEncodingException ue) {;
      } catch (IOException e) {
        throw new RuntimeException("Content read fail");
      }
    }

    // Store the final results
    results.setLocked(true);
    parsed = true;
    parameters = results;
  }
Esempio n. 2
0
 public String[] getParameterValues(String name) {
   parseParameters();
   String values[] = (String[]) parameters.get(name);
   if (values != null) return (values);
   else return null;
 }
Esempio n. 3
0
 public Enumeration getParameterNames() {
   parseParameters();
   return (new Enumerator(parameters.keySet()));
 }
Esempio n. 4
0
 public String getParameter(String name) {
   parseParameters();
   String values[] = (String[]) parameters.get(name);
   if (values != null) return (values[0]);
   else return (null);
 }