You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/08/25 16:56:33 UTC
svn commit: r569684 - in
/jakarta/httpcomponents/httpcore/trunk/module-main/src:
main/java/org/apache/http/message/ test/java/org/apache/http/message/
Author: rolandw
Date: Sat Aug 25 07:56:33 2007
New Revision: 569684
URL: http://svn.apache.org/viewvc?rev=569684&view=rev
Log:
removed static formatting from BasicRequestLine, adjusted test cases
Modified:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.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/TestBasicLineFormatter.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/BasicLineFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java?rev=569684&r1=569683&r2=569684&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicLineFormatter.java Sat Aug 25 07:56:33 2007
@@ -136,16 +136,66 @@
}
+
+ /**
+ * Formats a request line.
+ *
+ * @param reqline the request line to format
+ * @param formatter the formatter to use, or
+ * <code>null</code> for the
+ * {@link #DEFAULT default}
+ *
+ * @return the formatted request line
+ */
+ public final static String formatRequestLine(final RequestLine reqline,
+ LineFormatter formatter) {
+ if (formatter == null)
+ formatter = BasicLineFormatter.DEFAULT;
+ return formatter.formatRequestLine(null, reqline).toString();
+ }
+
+
// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatRequestLine(CharArrayBuffer buffer,
RequestLine reqline) {
+ if (reqline == null) {
+ throw new IllegalArgumentException
+ ("Request line must not be null.");
+ }
CharArrayBuffer result = initBuffer(buffer);
- BasicRequestLine.format(result, reqline); //@@@ move code here
+ doFormatRequestLine(result, reqline);
+
return result;
}
+ /**
+ * Actually formats a request line.
+ * Called from {@link #formatRequestLine}.
+ *
+ * @param buffer the empty buffer into which to format,
+ * never <code>null</code>
+ * @param reqline the request line to format, never <code>null</code>
+ */
+ protected void doFormatRequestLine(CharArrayBuffer buffer,
+ RequestLine reqline) {
+ final String method = reqline.getMethod();
+ final String uri = reqline.getUri();
+ //@@@ let the protocol version length be guessed elsewhere
+ //@@@ guess the length in an extra method?
+ // room for "GET /index.html HTTP/1.1"
+ int len = method.length() + 1 + uri.length() + 1 + 8;
+ buffer.ensureCapacity(len);
+
+ buffer.append(method);
+ buffer.append(' ');
+ buffer.append(uri);
+ buffer.append(' ');
+ appendProtocolVersion(buffer, reqline.getHttpVersion());
+ }
+
+
/**
* Formats a status line.
@@ -186,7 +236,7 @@
*
* @param buffer the empty buffer into which to format,
* never <code>null</code>
- * @param header the status line to format, never <code>null</code>
+ * @param statline the status line to format, never <code>null</code>
*/
protected void doFormatStatusLine(CharArrayBuffer buffer,
StatusLine statline) {
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=569684&r1=569683&r2=569684&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 Sat Aug 25 07:56:33 2007
@@ -56,18 +56,23 @@
private final String method;
private final String uri;
- public BasicRequestLine(final String method, final String uri, final HttpVersion httpversion) {
- super();
- if (method == null) {
- throw new IllegalArgumentException("Method may not be null");
- }
- if (uri == null) {
- throw new IllegalArgumentException("URI may not be null");
- }
- if (httpversion == null) {
- throw new IllegalArgumentException("HTTP version may not be null");
- }
- this.method = method;
+ public BasicRequestLine(final String method,
+ final String uri,
+ final HttpVersion httpversion) {
+ super();
+ if (method == null) {
+ throw new IllegalArgumentException
+ ("Method must not be null.");
+ }
+ if (uri == null) {
+ throw new IllegalArgumentException
+ ("URI must not be null.");
+ }
+ if (httpversion == null) {
+ throw new IllegalArgumentException
+ ("HTTP version must not be null.");
+ }
+ this.method = method;
this.uri = uri;
this.httpversion = httpversion;
}
@@ -93,25 +98,4 @@
buffer.append(this.httpversion);
return buffer.toString();
}
-
- /*public@@@*/ static void format(final CharArrayBuffer buffer, final RequestLine requestline) {
- if (buffer == null) {
- throw new IllegalArgumentException("String buffer may not be null");
- }
- if (requestline == null) {
- throw new IllegalArgumentException("Request line may not be null");
- }
- buffer.append(requestline.getMethod());
- buffer.append(' ');
- buffer.append(requestline.getUri());
- buffer.append(' ');
- BasicHttpVersionFormat.format(buffer, requestline.getHttpVersion());
- }
-
- /*public@@@*/ static String format(final RequestLine requestline) {
- CharArrayBuffer buffer = new CharArrayBuffer(64);
- format(buffer, requestline);
- return buffer.toString();
- }
-
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineFormatter.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineFormatter.java?rev=569684&r1=569683&r2=569684&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineFormatter.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicLineFormatter.java Sat Aug 25 07:56:33 2007
@@ -65,6 +65,31 @@
return new TestSuite(TestBasicLineFormatter.class);
}
+
+ public void testRLFormatting() throws Exception {
+ RequestLine requestline = new BasicRequestLine("GET", "/stuff", HttpVersion.HTTP_1_1);
+ String s = BasicLineFormatter.formatRequestLine(requestline, null);
+ assertEquals("GET /stuff HTTP/1.1", s);
+ }
+
+ public void testRLFormattingInvalidInput() throws Exception {
+ try {
+ BasicLineFormatter.formatRequestLine
+ (null, BasicLineFormatter.DEFAULT);
+ fail("IllegalArgumentException should habe been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ try {
+ BasicLineFormatter.DEFAULT.formatRequestLine
+ (new CharArrayBuffer(10), (RequestLine) null);
+ fail("IllegalArgumentException should habe been thrown");
+ } catch (IllegalArgumentException ex) {
+ // expected
+ }
+ }
+
+
public void testSLFormatting() throws Exception {
StatusLine statusline = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");
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=569684&r1=569683&r2=569684&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 Sat Aug 25 07:56:33 2007
@@ -85,26 +85,4 @@
fail("IllegalArgumentException should have been thrown");
} catch (IllegalArgumentException e) { /* 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
- }
- }
-
}