Return-Path: Delivered-To: apmail-jakarta-httpcomponents-commits-archive@www.apache.org Received: (qmail 38443 invoked from network); 21 Aug 2007 10:53:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Aug 2007 10:53:36 -0000 Received: (qmail 92983 invoked by uid 500); 21 Aug 2007 10:53:28 -0000 Delivered-To: apmail-jakarta-httpcomponents-commits-archive@jakarta.apache.org Received: (qmail 92970 invoked by uid 500); 21 Aug 2007 10:53:28 -0000 Mailing-List: contact httpcomponents-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpcomponents-dev@jakarta.apache.org Delivered-To: mailing list httpcomponents-commits@jakarta.apache.org Received: (qmail 92960 invoked by uid 99); 21 Aug 2007 10:53:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Aug 2007 03:53:28 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Aug 2007 10:54:02 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 45D9A1A981C; Tue, 21 Aug 2007 03:53:07 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r568056 - in /jakarta/httpcomponents/httpcore/trunk/module-main/src: main/java/org/apache/http/message/ test/java/org/apache/http/message/ Date: Tue, 21 Aug 2007 10:53:05 -0000 To: httpcomponents-commits@jakarta.apache.org From: rolandw@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070821105307.45D9A1A981C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rolandw Date: Tue Aug 21 03:53:00 2007 New Revision: 568056 URL: http://svn.apache.org/viewvc?rev=568056&view=rev Log: removed static parser code from BasicHttpVersionFormat, adjusted test cases Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHttpVersionFormat.java jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestHttpVersion.java Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHttpVersionFormat.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHttpVersionFormat.java?rev=568056&r1=568055&r2=568056&view=diff ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHttpVersionFormat.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHttpVersionFormat.java Tue Aug 21 03:53:00 2007 @@ -50,77 +50,9 @@ */ public class BasicHttpVersionFormat { - /** - * Parses the textual representation of the given HTTP protocol version. - * - * @return HTTP protocol version. - * - * @throws ProtocolException if the string is not a valid HTTP protocol version. - */ - public static HttpVersion parse( - final CharArrayBuffer buffer, final int indexFrom, final int indexTo) - throws ProtocolException { - if (buffer == null) { - throw new IllegalArgumentException("Char array buffer may not be null"); - } - if (indexFrom < 0) { - throw new IndexOutOfBoundsException(); - } - if (indexTo > buffer.length()) { - throw new IndexOutOfBoundsException(); - } - if (indexFrom > indexTo) { - throw new IndexOutOfBoundsException(); - } - try { - int major, minor; - - int i = indexFrom; - while (HTTP.isWhitespace(buffer.charAt(i))) { - i++; - } - if (buffer.charAt(i ) != 'H' - || buffer.charAt(i + 1) != 'T' - || buffer.charAt(i + 2) != 'T' - || buffer.charAt(i + 3) != 'P' - || buffer.charAt(i + 4) != '/') { - throw new ProtocolException("Not a valid HTTP version string: " + - buffer.substring(indexFrom, indexTo)); - } - i += 5; - int period = buffer.indexOf('.', i, indexTo); - if (period == -1) { - throw new ProtocolException("Invalid HTTP version number: " + - buffer.substring(indexFrom, indexTo)); - } - try { - major = Integer.parseInt(buffer.substringTrimmed(i, period)); - } catch (NumberFormatException e) { - throw new ProtocolException("Invalid HTTP major version number: " + - buffer.substring(indexFrom, indexTo)); - } - try { - minor = Integer.parseInt(buffer.substringTrimmed(period + 1, indexTo)); - } catch (NumberFormatException e) { - throw new ProtocolException("Invalid HTTP minor version number: " + - buffer.substring(indexFrom, indexTo)); - } - return new HttpVersion(major, minor); - - } catch (IndexOutOfBoundsException e) { - throw new ProtocolException("Invalid HTTP version string: " + - buffer.substring(indexFrom, indexTo)); - } - } - - public static final HttpVersion parse(final String s) - throws ProtocolException { - if (s == null) { - throw new IllegalArgumentException("String may not be null"); - } - CharArrayBuffer buffer = new CharArrayBuffer(s.length()); - buffer.append(s); - return parse(buffer, 0, buffer.length()); + /** Disabled default constructor. */ + private BasicHttpVersionFormat() { + // no body } public static void format(final CharArrayBuffer buffer, final HttpVersion ver) { Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java?rev=568056&r1=568055&r2=568056&view=diff ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java Tue Aug 21 03:53:00 2007 @@ -32,6 +32,7 @@ import org.apache.http.HttpException; import org.apache.http.HttpVersion; +import org.apache.http.ProtocolException; import org.apache.http.RequestLine; import org.apache.http.StatusLine; import org.apache.http.message.BasicRequestLine; @@ -274,6 +275,137 @@ } try { BasicLineParser.DEFAULT.parseStatusLine(buffer, 2, 1); + fail("IllegalArgumentException should have been thrown"); + } catch (IndexOutOfBoundsException ex) { + // expected + } + } + + + + public void testHttpVersionParsing() throws Exception { + new HttpVersion(1, 1); + String s = "HTTP/1.1"; + HttpVersion version = BasicLineParser.parseProtocolVersion(s, null); + assertEquals("HTTP major version number", 1, version.getMajor()); + assertEquals("HTTP minor version number", 1, version.getMinor()); + assertEquals("HTTP version number", s, version.toString()); + + s = "HTTP/123.4567"; + version = BasicLineParser.parseProtocolVersion(s, null); + assertEquals("HTTP major version number", 123, version.getMajor()); + assertEquals("HTTP minor version number", 4567, version.getMinor()); + assertEquals("HTTP version number", s, version.toString()); + } + + public void testInvalidHttpVersionParsing() throws Exception { + try { + BasicLineParser.parseProtocolVersion(null, null); + fail("IllegalArgumentException should have been thrown"); + } catch (IllegalArgumentException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + (" ", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTT", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("crap", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTTP/crap", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTTP/1", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTTP/1234 ", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTTP/1.", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTTP/1.1 crap", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTTP/whatever.whatever whatever", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + try { + BasicLineParser.parseProtocolVersion + ("HTTP/1.whatever whatever", null); + fail("ProtocolException should have been thrown"); + } catch (ProtocolException e) { + //expected + } + } + + public void testHttpVersionParsingInvalidInput() throws Exception { + CharArrayBuffer buffer = new CharArrayBuffer(32); + buffer.append("HTTP/1.1"); + try { + BasicLineParser.parseProtocolVersion(null, null); + fail("IllegalArgumentException should have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + BasicLineParser.DEFAULT.parseProtocolVersion(null, 0, 0); + fail("IllegalArgumentException should have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + BasicLineParser.DEFAULT.parseProtocolVersion(buffer, -1, 0); + fail("IllegalArgumentException should have been thrown"); + } catch (IndexOutOfBoundsException ex) { + // expected + } + try { + BasicLineParser.DEFAULT.parseProtocolVersion(buffer, 0, 1000); + fail("IllegalArgumentException should have been thrown"); + } catch (IndexOutOfBoundsException ex) { + // expected + } + try { + BasicLineParser.DEFAULT.parseProtocolVersion(buffer, 2, 1); fail("IllegalArgumentException should have been thrown"); } catch (IndexOutOfBoundsException ex) { // expected Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestHttpVersion.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestHttpVersion.java?rev=568056&r1=568055&r2=568056&view=diff ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestHttpVersion.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestHttpVersion.java Tue Aug 21 03:53:00 2007 @@ -59,125 +59,6 @@ } // ------------------------------------------------------------------ Tests - - public void testHttpVersionParsing() throws Exception { - new HttpVersion(1, 1); - String s = "HTTP/1.1"; - HttpVersion version = BasicHttpVersionFormat.parse(s); - assertEquals("HTTP major version number", 1, version.getMajor()); - assertEquals("HTTP minor version number", 1, version.getMinor()); - assertEquals("HTTP version number", s, version.toString()); - - s = "HTTP/123.4567"; - version = BasicHttpVersionFormat.parse(s); - assertEquals("HTTP major version number", 123, version.getMajor()); - assertEquals("HTTP minor version number", 4567, version.getMinor()); - assertEquals("HTTP version number", s, version.toString()); - } - - public void testInvalidHttpVersionParsing() throws Exception { - try { - BasicHttpVersionFormat.parse(null); - fail("IllegalArgumentException should have been thrown"); - } catch (IllegalArgumentException e) { - //expected - } - try { - BasicHttpVersionFormat.parse(" "); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTT"); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("crap"); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTTP/crap"); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTTP/1"); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTTP/1234 "); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTTP/1."); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTTP/1.1 crap"); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTTP/whatever.whatever whatever"); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - try { - BasicHttpVersionFormat.parse("HTTP/1.whatever whatever"); - fail("ProtocolException should have been thrown"); - } catch (ProtocolException e) { - //expected - } - } - - public void testHttpVersionParsingInvalidInput() throws Exception { - CharArrayBuffer buffer = new CharArrayBuffer(32); - buffer.append("HTTP/1.1"); - try { - BasicHttpVersionFormat.parse(null, 0, 0); - fail("IllegalArgumentException should have been thrown"); - } catch (IllegalArgumentException ex) { - // expected - } - try { - BasicHttpVersionFormat.parse(null); - fail("IllegalArgumentException should have been thrown"); - } catch (IllegalArgumentException ex) { - // expected - } - try { - BasicHttpVersionFormat.parse(buffer, -1, 0); - fail("IllegalArgumentException should have been thrown"); - } catch (IndexOutOfBoundsException ex) { - // expected - } - try { - BasicHttpVersionFormat.parse(buffer, 0, 1000); - fail("IllegalArgumentException should have been thrown"); - } catch (IndexOutOfBoundsException ex) { - // expected - } - try { - BasicHttpVersionFormat.parse(buffer, 2, 1); - fail("IllegalArgumentException should have been thrown"); - } catch (IndexOutOfBoundsException ex) { - // expected - } - } public void testHttpVersionFormatting() throws Exception { String s = BasicHttpVersionFormat.format(HttpVersion.HTTP_1_1);