hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rola...@apache.org
Subject svn commit: r568051 - 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:28:38 GMT
Author: rolandw
Date: Tue Aug 21 03:28:24 2007
New Revision: 568051

URL: http://svn.apache.org/viewvc?rev=568051&view=rev
Log:
removed static parser code from BasicRequestLine, adjusted test cases

Added:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java
      - copied, changed from r568005, jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java
Modified:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElement.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderValueParser.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineParser.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java
    jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java?rev=568051&r1=568050&r2=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeader.java
Tue Aug 21 03:28:24 2007
@@ -126,7 +126,7 @@
     /**
      * Returns an array of {@link HeaderElement}s constructed from my value.
      *
-     * @see BasicHeaderElement#parseAll
+     * @see BasicHeaderValueParser#parseElements
      * 
      * @return an array of header elements
      */

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElement.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElement.java?rev=568051&r1=568050&r2=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElement.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElement.java
Tue Aug 21 03:28:24 2007
@@ -71,10 +71,6 @@
  * both a name/value pair (value may be <tt>null</tt>) and optionally
  * a set of additional parameters.
  * </p>
- * <p>
- * This class also exposes a {@link #parse} method for parsing a
- * {@link org.apache.http.Header} value into an array of elements.
- * </p>
  *
  * @author <a href="mailto:bcholmes@interlog.com">B.C. Holmes</a>
  * @author <a href="mailto:jericho@thinkfree.com">Park, Sung-Gu</a>

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderValueParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderValueParser.java?rev=568051&r1=568050&r2=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderValueParser.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderValueParser.java
Tue Aug 21 03:28:24 2007
@@ -381,7 +381,7 @@
 
     /**
      * Creates a name-value pair.
-     * Called from {@link #parseNameValue}.
+     * Called from {@link #parseNameValuePair}.
      *
      * @param name      the name
      * @param value     the value, or <code>null</code>

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineParser.java?rev=568051&r1=568050&r2=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineParser.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineParser.java
Tue Aug 21 03:28:24 2007
@@ -78,6 +78,25 @@
     // public default constructor
 
 
+    public final static
+        HttpVersion parseProtocolVersion(String value,
+                                         LineParser parser)
+        throws ProtocolException {
+
+        if (value == null) {
+            throw new IllegalArgumentException
+                ("Value to parse may not be null.");
+        }
+
+        if (parser == null)
+            parser = BasicLineParser.DEFAULT;
+
+        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
+        buffer.append(value);
+        return parser.parseProtocolVersion(buffer, 0, buffer.length());
+    }
+
+
     // non-javadoc, see interface LineParser
     public HttpVersion parseProtocolVersion(final CharArrayBuffer buffer,
                                             final int indexFrom,
@@ -153,6 +172,26 @@
     }
 
 
+
+    public final static
+        RequestLine parseRequestLine(String value,
+                                     LineParser parser)
+        throws ProtocolException {
+
+        if (value == null) {
+            throw new IllegalArgumentException
+                ("Value to parse may not be null.");
+        }
+
+        if (parser == null)
+            parser = BasicLineParser.DEFAULT;
+
+        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
+        buffer.append(value);
+        return parser.parseRequestLine(buffer, 0, buffer.length());
+    }
+
+
     /**
      * Parses a request line.
      *
@@ -228,6 +267,26 @@
     }
 
 
+
+    public final static
+        StatusLine parseStatusLine(String value,
+                                   LineParser parser)
+        throws ProtocolException {
+
+        if (value == null) {
+            throw new IllegalArgumentException
+                ("Value to parse may not be null.");
+        }
+
+        if (parser == null)
+            parser = BasicLineParser.DEFAULT;
+
+        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
+        buffer.append(value);
+        return parser.parseStatusLine(buffer, 0, buffer.length());
+    }
+
+
     // non-javadoc, see interface LineParser
     public StatusLine parseStatusLine(final CharArrayBuffer buffer,
                                       final int indexFrom,
@@ -312,6 +371,26 @@
     protected StatusLine createStatusLine(HttpVersion ver,
                                           int status, String reason) {
         return new BasicStatusLine(ver, status, reason);
+    }
+
+
+
+    public final static
+        Header parseHeader(String value, 
+                           LineParser parser)
+        throws ProtocolException {
+
+        if (value == null) {
+            throw new IllegalArgumentException
+                ("Value to parse may not be null.");
+        }
+
+        if (parser == null)
+            parser = BasicLineParser.DEFAULT;
+
+        CharArrayBuffer buffer = new CharArrayBuffer(value.length());
+        buffer.append(value);
+        return parser.parseHeader(buffer);
     }
 
 

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java?rev=568051&r1=568050&r2=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicRequestLine.java
Tue Aug 21 03:28:24 2007
@@ -94,60 +94,6 @@
         return buffer.toString();
     }
     
-    public static RequestLine 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 i = indexFrom;
-            while (HTTP.isWhitespace(buffer.charAt(i))) {
-                i++;
-            }
-            int blank = buffer.indexOf(' ', i, indexTo);
-            if (blank < 0) {
-                throw new ProtocolException("Invalid request line: " + 
-                        buffer.substring(indexFrom, indexTo));
-            }
-            String method = buffer.substringTrimmed(i, blank);
-            i = blank;
-            while (HTTP.isWhitespace(buffer.charAt(i))) {
-                i++;
-            }
-            blank = buffer.indexOf(' ', i, indexTo);
-            if (blank < 0) {
-                throw new ProtocolException("Invalid request line: " + 
-                        buffer.substring(indexFrom, indexTo));
-            }
-            String uri = buffer.substringTrimmed(i, blank);
-            HttpVersion ver = BasicHttpVersionFormat.parse(buffer, blank, indexTo);
-            return new BasicRequestLine(method, uri, ver);
-        } catch (IndexOutOfBoundsException e) {
-            throw new ProtocolException("Invalid request line: " + 
-                    buffer.substring(indexFrom, indexTo)); 
-        }
-    }
-
-    public static final RequestLine 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());
-    }
-    
     public static void format(final CharArrayBuffer buffer, final RequestLine requestline)
{
         if (buffer == null) {
             throw new IllegalArgumentException("String buffer may not be null");

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java?rev=568051&r1=568050&r2=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java
Tue Aug 21 03:28:24 2007
@@ -47,6 +47,7 @@
         suite.addTest(TestStatusLine.suite());
         suite.addTest(TestRequestLine.suite());
         suite.addTest(TestHttpVersion.suite());
+        suite.addTest(TestBasicLineParser.suite());
         suite.addTest(TestAbstractMessage.suite());
         suite.addTest(TestBasicMessages.suite());
 

Copied: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java
(from r568005, jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java?p2=jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java&p1=jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java&r1=568005&r2=568051&rev=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineParser.java
Tue Aug 21 03:28:24 2007
@@ -39,149 +39,110 @@
 import junit.framework.*;
 
 /**
- * Simple tests for {@link RequestLine}.
+ * Tests for {@link BasicLineParser}.
  *
  * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
  *
  * @version $Revision$
  */
-public class TestRequestLine extends TestCase {
+public class TestBasicLineParser extends TestCase {
 
     // ------------------------------------------------------------ Constructor
-    public TestRequestLine(String testName) {
+    public TestBasicLineParser(String testName) {
         super(testName);
     }
 
     // ------------------------------------------------------------------- Main
     public static void main(String args[]) {
-        String[] testCaseName = { TestRequestLine.class.getName() };
+        String[] testCaseName = { TestBasicLineParser.class.getName() };
         junit.textui.TestRunner.main(testCaseName);
     }
 
     // ------------------------------------------------------- TestCase Methods
 
     public static Test suite() {
-        return new TestSuite(TestRequestLine.class);
+        return new TestSuite(TestBasicLineParser.class);
     }
 
-    public void testConstructor() {
-        RequestLine requestline = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
-        assertEquals("GET", requestline.getMethod()); 
-        assertEquals("/stuff", requestline.getUri()); 
-        assertEquals(HttpVersion.HTTP_1_1, requestline.getHttpVersion()); 
-    }
-        
-    public void testConstructorInvalidInput() {
-        try {
-            new BasicRequestLine(null, "/stuff", HttpVersion.HTTP_1_1);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) { /* expected */ }
-        try {
-            new BasicRequestLine("GEt", null, HttpVersion.HTTP_1_1);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) { /* expected */ }
-        try {
-            new BasicRequestLine("GET", "/stuff", (HttpVersion)null);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException e) { /* expected */ }
-    }
         
-    public void testParseSuccess() throws Exception {
+    public void testRLParseSuccess() throws Exception {
         //typical request line
-        RequestLine requestline = BasicRequestLine.parse("GET /stuff HTTP/1.1");
+        RequestLine requestline = BasicLineParser.parseRequestLine
+            ("GET /stuff HTTP/1.1", null);
         assertEquals("GET /stuff HTTP/1.1", requestline.toString());
         assertEquals("GET", requestline.getMethod());
         assertEquals("/stuff", requestline.getUri());
         assertEquals(HttpVersion.HTTP_1_1, requestline.getHttpVersion());
 
         //Lots of blanks
-        requestline = BasicRequestLine.parse("  GET    /stuff   HTTP/1.1   ");
+        requestline = BasicLineParser.parseRequestLine
+            ("  GET    /stuff   HTTP/1.1   ", null);
         assertEquals("GET /stuff HTTP/1.1", requestline.toString());
         assertEquals("GET", requestline.getMethod());
         assertEquals("/stuff", requestline.getUri());
         assertEquals(HttpVersion.HTTP_1_1, requestline.getHttpVersion());
 
         //this is not strictly valid, but is lienent
-        requestline = BasicRequestLine.parse("\rGET /stuff HTTP/1.1");
+        requestline = BasicLineParser.parseRequestLine
+            ("\rGET /stuff HTTP/1.1", null);
         assertEquals("GET", requestline.getMethod());
         assertEquals("/stuff", requestline.getUri());
         assertEquals(HttpVersion.HTTP_1_1, requestline.getHttpVersion());
     }
 
-    public void testParseFailure() throws Exception {
+    public void testRLParseFailure() throws Exception {
         try {
-            BasicRequestLine.parse("    ");
+            BasicLineParser.parseRequestLine("    ", null);
             fail();
         } catch (HttpException e) { /* expected */ }
 
         try {
-            BasicRequestLine.parse("  GET");
+            BasicLineParser.parseRequestLine("  GET", null);
             fail();
         } catch (HttpException e) { /* expected */ }
 
         try {
-            BasicRequestLine.parse("GET /stuff");
+            BasicLineParser.parseRequestLine("GET /stuff", null);
             fail();
         } catch (HttpException e) { /* expected */ }
 
         try {
-            BasicRequestLine.parse("GET/stuff HTTP/1.1");
+            BasicLineParser.parseRequestLine("GET/stuff HTTP/1.1", null);
             fail();
         } catch (HttpException e) { /* expected */ }
     }
 
-    public void testParseInvalidInput() throws Exception {
+    public void testRLParseInvalidInput() throws Exception {
         CharArrayBuffer buffer = new CharArrayBuffer(32);
         buffer.append("GET /stuff HTTP/1.1");
         try {
-            BasicRequestLine.parse(null, 0, 0);
+            BasicLineParser.parseRequestLine(null, null);
             fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {
-            BasicRequestLine.parse(null);
+            BasicLineParser.DEFAULT.parseRequestLine(null, 0, 0);
             fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException ex) {
             // expected
         }
         try {
-            BasicRequestLine.parse(buffer, -1, 0);
+            BasicLineParser.DEFAULT.parseRequestLine(buffer, -1, 0);
             fail("IllegalArgumentException should have been thrown");
         } catch (IndexOutOfBoundsException ex) {
             // expected
         }
         try {
-            BasicRequestLine.parse(buffer, 0, 1000);
+            BasicLineParser.DEFAULT.parseRequestLine(buffer, 0, 1000);
             fail("IllegalArgumentException should have been thrown");
         } catch (IndexOutOfBoundsException ex) {
             // expected
         }
         try {
-            BasicRequestLine.parse(buffer, 2, 1);
+            BasicLineParser.DEFAULT.parseRequestLine(buffer, 2, 1);
             fail("IllegalArgumentException should have been thrown");
         } catch (IndexOutOfBoundsException ex) {
-            // expected
-        }
-    }
-
-    public void testFormatting() throws Exception {
-        RequestLine requestline = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
-        String s = BasicRequestLine.format(requestline);
-        assertEquals("GET /stuff HTTP/1.1", s);
-    }
-    
-    public void testFormattingInvalidInput() throws Exception {
-        try {
-            BasicRequestLine.format(null, new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1));
-            fail("IllegalArgumentException should habe been thrown");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            BasicRequestLine.format(new CharArrayBuffer(10), (RequestLine) null);
-            fail("IllegalArgumentException should habe been thrown");
-        } catch (IllegalArgumentException ex) {
             // expected
         }
     }

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java?rev=568051&r1=568050&r2=568051&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java
(original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestRequestLine.java
Tue Aug 21 03:28:24 2007
@@ -77,92 +77,13 @@
             fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException e) { /* expected */ }
         try {
-            new BasicRequestLine("GEt", null, HttpVersion.HTTP_1_1);
+            new BasicRequestLine("GET", null, HttpVersion.HTTP_1_1);
             fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException e) { /* expected */ }
         try {
             new BasicRequestLine("GET", "/stuff", (HttpVersion)null);
             fail("IllegalArgumentException should have been thrown");
         } catch (IllegalArgumentException e) { /* expected */ }
-    }
-        
-    public void testParseSuccess() throws Exception {
-        //typical request line
-        RequestLine requestline = BasicRequestLine.parse("GET /stuff HTTP/1.1");
-        assertEquals("GET /stuff HTTP/1.1", requestline.toString());
-        assertEquals("GET", requestline.getMethod());
-        assertEquals("/stuff", requestline.getUri());
-        assertEquals(HttpVersion.HTTP_1_1, requestline.getHttpVersion());
-
-        //Lots of blanks
-        requestline = BasicRequestLine.parse("  GET    /stuff   HTTP/1.1   ");
-        assertEquals("GET /stuff HTTP/1.1", requestline.toString());
-        assertEquals("GET", requestline.getMethod());
-        assertEquals("/stuff", requestline.getUri());
-        assertEquals(HttpVersion.HTTP_1_1, requestline.getHttpVersion());
-
-        //this is not strictly valid, but is lienent
-        requestline = BasicRequestLine.parse("\rGET /stuff HTTP/1.1");
-        assertEquals("GET", requestline.getMethod());
-        assertEquals("/stuff", requestline.getUri());
-        assertEquals(HttpVersion.HTTP_1_1, requestline.getHttpVersion());
-    }
-
-    public void testParseFailure() throws Exception {
-        try {
-            BasicRequestLine.parse("    ");
-            fail();
-        } catch (HttpException e) { /* expected */ }
-
-        try {
-            BasicRequestLine.parse("  GET");
-            fail();
-        } catch (HttpException e) { /* expected */ }
-
-        try {
-            BasicRequestLine.parse("GET /stuff");
-            fail();
-        } catch (HttpException e) { /* expected */ }
-
-        try {
-            BasicRequestLine.parse("GET/stuff HTTP/1.1");
-            fail();
-        } catch (HttpException e) { /* expected */ }
-    }
-
-    public void testParseInvalidInput() throws Exception {
-        CharArrayBuffer buffer = new CharArrayBuffer(32);
-        buffer.append("GET /stuff HTTP/1.1");
-        try {
-            BasicRequestLine.parse(null, 0, 0);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            BasicRequestLine.parse(null);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IllegalArgumentException ex) {
-            // expected
-        }
-        try {
-            BasicRequestLine.parse(buffer, -1, 0);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IndexOutOfBoundsException ex) {
-            // expected
-        }
-        try {
-            BasicRequestLine.parse(buffer, 0, 1000);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IndexOutOfBoundsException ex) {
-            // expected
-        }
-        try {
-            BasicRequestLine.parse(buffer, 2, 1);
-            fail("IllegalArgumentException should have been thrown");
-        } catch (IndexOutOfBoundsException ex) {
-            // expected
-        }
     }
 
     public void testFormatting() throws Exception {



Mime
View raw message