Package org.apache.http

Examples of org.apache.http.ParseException


            skipWhitespace(buffer, cursor);
            int i = cursor.getPos();

            int blank = buffer.indexOf(' ', i, indexTo);
            if (blank < 0) {
                throw new ParseException("Invalid request line: " +
                        buffer.substring(indexFrom, indexTo));
            }
            String method = buffer.substringTrimmed(i, blank);
            cursor.updatePos(blank);

            skipWhitespace(buffer, cursor);
            i = cursor.getPos();

            blank = buffer.indexOf(' ', i, indexTo);
            if (blank < 0) {
                throw new ParseException("Invalid request line: " +
                        buffer.substring(indexFrom, indexTo));
            }
            String uri = buffer.substringTrimmed(i, blank);
            cursor.updatePos(blank);

            ProtocolVersion ver = parseProtocolVersion(buffer, cursor);

            skipWhitespace(buffer, cursor);
            if (!cursor.atEnd()) {
                throw new ParseException("Invalid request line: " +
                        buffer.substring(indexFrom, indexTo));
            }

            return createRequestLine(method, uri, ver);
        } catch (IndexOutOfBoundsException e) {
            throw new ParseException("Invalid request line: " +
                                     buffer.substring(indexFrom, indexTo));
        }
    } // parseRequestLine
View Full Code Here


            }
            int statusCode = 0;
            String s = buffer.substringTrimmed(i, blank);
            for (int j = 0; j < s.length(); j++) {
                if (!Character.isDigit(s.charAt(j))) {
                    throw new ParseException(
                            "Status line contains invalid status code: "
                            + buffer.substring(indexFrom, indexTo));
                }
            }
            try {
                statusCode = Integer.parseInt(s);
            } catch (NumberFormatException e) {
                throw new ParseException(
                        "Status line contains invalid status code: "
                        + buffer.substring(indexFrom, indexTo));
            }
            //handle the Reason-Phrase
            i = blank;
            String reasonPhrase = null;
            if (i < indexTo) {
                reasonPhrase = buffer.substringTrimmed(i, indexTo);
            } else {
                reasonPhrase = "";
            }
            return createStatusLine(ver, statusCode, reasonPhrase);

        } catch (IndexOutOfBoundsException e) {
            throw new ParseException("Invalid status line: " +
                                     buffer.substring(indexFrom, indexTo));
        }
    } // parseStatusLine
View Full Code Here

        }
        HeaderElement[] elements = BasicHeaderValueParser.parseElements(s, null);
        if (elements.length > 0) {
            return create(elements[0]);
        } else {
            throw new ParseException("Invalid content type: " + s);
        }
    }
View Full Code Here

  {
    if (paramCharArrayBuffer == null)
      throw new IllegalArgumentException("Char array buffer may not be null");
    int i = paramCharArrayBuffer.indexOf(58);
    if (i == -1)
      throw new ParseException("Invalid header: " + paramCharArrayBuffer.toString());
    String str = paramCharArrayBuffer.substringTrimmed(0, i);
    if (str.length() == 0)
      throw new ParseException("Invalid header: " + paramCharArrayBuffer.toString());
    this.buffer = paramCharArrayBuffer;
    this.name = str;
    this.valuePos = (i + 1);
  }
View Full Code Here

        if ((isTokenSeparator(c)) || (isWhitespace(c)))
          paramInt++;
        else if (isTokenChar(this.currentHeader.charAt(paramInt)))
          i = 1;
        else
          throw new ParseException("Invalid character before token (pos " + paramInt + "): " + this.currentHeader);
      }
      if (i == 0)
        if (this.headerIt.hasNext())
        {
          this.currentHeader = this.headerIt.nextHeader().getValue();
View Full Code Here

        paramInt++;
      }
      else
      {
        if (isTokenChar(c))
          throw new ParseException("Tokens without separator (pos " + paramInt + "): " + this.currentHeader);
        throw new ParseException("Invalid character after token (pos " + paramInt + "): " + this.currentHeader);
      }
    }
    return paramInt;
  }
View Full Code Here

    int j = paramParserCursor.getPos();
    int k = paramParserCursor.getUpperBound();
    skipWhitespace(paramCharArrayBuffer, paramParserCursor);
    int m = paramParserCursor.getPos();
    if (m + i + 4 > k)
      throw new ParseException("Not a valid protocol version: " + paramCharArrayBuffer.substring(j, k));
    int n = 1;
    for (int i1 = 0; (n != 0) && (i1 < i); i1++)
      n = paramCharArrayBuffer.charAt(m + i1) == str.charAt(i1) ? 1 : 0;
    if (n != 0)
      n = paramCharArrayBuffer.charAt(m + i) == '/' ? 1 : 0;
    if (n == 0)
      throw new ParseException("Not a valid protocol version: " + paramCharArrayBuffer.substring(j, k));
    m += i + 1;
    i1 = paramCharArrayBuffer.indexOf(46, m, k);
    if (i1 == -1)
      throw new ParseException("Invalid protocol version number: " + paramCharArrayBuffer.substring(j, k));
    int i2;
    try
    {
      i2 = Integer.parseInt(paramCharArrayBuffer.substringTrimmed(m, i1));
    }
    catch (NumberFormatException localNumberFormatException1)
    {
      throw new ParseException("Invalid protocol major version number: " + paramCharArrayBuffer.substring(j, k));
    }
    m = i1 + 1;
    int i3 = paramCharArrayBuffer.indexOf(32, m, k);
    if (i3 == -1)
      i3 = k;
    int i4;
    try
    {
      i4 = Integer.parseInt(paramCharArrayBuffer.substringTrimmed(m, i3));
    }
    catch (NumberFormatException localNumberFormatException2)
    {
      throw new ParseException("Invalid protocol minor version number: " + paramCharArrayBuffer.substring(j, k));
    }
    paramParserCursor.updatePos(i3);
    return createProtocolVersion(i2, i4);
  }
View Full Code Here

        m = j;
      int n = 0;
      String str1 = paramCharArrayBuffer.substringTrimmed(k, m);
      for (int i1 = 0; i1 < str1.length(); i1++)
        if (!Character.isDigit(str1.charAt(i1)))
          throw new ParseException("Status line contains invalid status code: " + paramCharArrayBuffer.substring(i, j));
      try
      {
        n = Integer.parseInt(str1);
      }
      catch (NumberFormatException localNumberFormatException)
      {
        throw new ParseException("Status line contains invalid status code: " + paramCharArrayBuffer.substring(i, j));
      }
      k = m;
      String str2 = null;
      if (k < j)
        str2 = paramCharArrayBuffer.substringTrimmed(k, j);
      else
        str2 = "";
      return createStatusLine(localProtocolVersion, n, str2);
    }
    catch (IndexOutOfBoundsException localIndexOutOfBoundsException)
    {
    }
    throw new ParseException("Invalid status line: " + paramCharArrayBuffer.substring(i, j));
  }
View Full Code Here

        super();
        Args.notNull(buffer, "Char array buffer");
        final int colon = buffer.indexOf(':');
        if (colon == -1) {
            throw new ParseException
                ("Invalid header: " + buffer.toString());
        }
        final String s = buffer.substringTrimmed(0, colon);
        if (s.length() == 0) {
            throw new ParseException
                ("Invalid header: " + buffer.toString());
        }
        this.buffer = buffer;
        this.name = s;
        this.valuePos = colon + 1;
View Full Code Here

        final ParserCursor cursor = new ParserCursor(0, s.length());
        final HeaderElement[] elements = BasicHeaderValueParser.INSTANCE.parseElements(buf, cursor);
        if (elements.length > 0) {
            return create(elements[0]);
        } else {
            throw new ParseException("Invalid content type: " + s);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.http.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.