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 09:59:03 UTC
svn commit: r569638 - in /jakarta/httpcomponents/httpcore/trunk:
module-main/src/main/java/org/apache/http/impl/io/
module-main/src/main/java/org/apache/http/message/
module-nio/src/main/java/org/apache/http/impl/nio/codecs/
Author: rolandw
Date: Sat Aug 25 00:59:03 2007
New Revision: 569638
URL: http://svn.apache.org/viewvc?rev=569638&view=rev
Log:
LineParser throws ParseException instead of ProtocolException
Modified:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestParser.java
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.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/LineParser.java
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestParser.java
jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseParser.java
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java?rev=569638&r1=569637&r2=569638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/AbstractMessageParser.java Sat Aug 25 00:59:03 2007
@@ -37,6 +37,7 @@
import org.apache.http.Header;
import org.apache.http.HttpException;
import org.apache.http.HttpMessage;
+import org.apache.http.ParseException;
import org.apache.http.ProtocolException;
import org.apache.http.io.HttpMessageParser;
import org.apache.http.io.SessionInputBuffer;
@@ -157,7 +158,7 @@
CharArrayBuffer buffer = (CharArrayBuffer) headerLines.get(i);
try {
headers[i] = parser.parseHeader(buffer);
- } catch (IllegalArgumentException ex) {
+ } catch (ParseException ex) {
throw new ProtocolException(ex.getMessage());
}
}
@@ -177,10 +178,15 @@
}
protected abstract HttpMessage parseHead(SessionInputBuffer sessionBuffer)
- throws IOException, HttpException;
+ throws IOException, HttpException, ParseException;
public HttpMessage parse() throws IOException, HttpException {
- HttpMessage message = parseHead(this.sessionBuffer);
+ HttpMessage message = null;
+ try {
+ message = parseHead(this.sessionBuffer);
+ } catch (ParseException px) {
+ throw new ProtocolException(px.getMessage(), px);
+ }
Header[] headers = AbstractMessageParser.parseHeaders(
this.sessionBuffer,
this.maxHeaderCount,
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestParser.java?rev=569638&r1=569637&r2=569638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestParser.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpRequestParser.java Sat Aug 25 00:59:03 2007
@@ -38,6 +38,7 @@
import org.apache.http.HttpMessage;
import org.apache.http.HttpRequestFactory;
import org.apache.http.RequestLine;
+import org.apache.http.ParseException;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.message.LineParser;
import org.apache.http.params.HttpParams;
@@ -62,7 +63,9 @@
}
protected HttpMessage parseHead(
- final SessionInputBuffer sessionBuffer) throws IOException, HttpException {
+ final SessionInputBuffer sessionBuffer)
+ throws IOException, HttpException, ParseException {
+
this.lineBuf.clear();
int i = sessionBuffer.readLine(this.lineBuf);
if (i == -1) {
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java?rev=569638&r1=569637&r2=569638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/HttpResponseParser.java Sat Aug 25 00:59:03 2007
@@ -38,6 +38,7 @@
import org.apache.http.HttpResponseFactory;
import org.apache.http.NoHttpResponseException;
import org.apache.http.StatusLine;
+import org.apache.http.ParseException;
import org.apache.http.io.SessionInputBuffer;
import org.apache.http.message.LineParser;
import org.apache.http.params.HttpParams;
@@ -62,7 +63,9 @@
}
protected HttpMessage parseHead(
- final SessionInputBuffer sessionBuffer) throws IOException, HttpException {
+ final SessionInputBuffer sessionBuffer)
+ throws IOException, HttpException, ParseException {
+
this.lineBuf.clear();
int i = sessionBuffer.readLine(this.lineBuf);
if (i == -1) {
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=569638&r1=569637&r2=569638&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 Sat Aug 25 00:59:03 2007
@@ -33,7 +33,6 @@
import org.apache.http.HttpVersion;
import org.apache.http.ParseException;
-import org.apache.http.ProtocolException;
import org.apache.http.RequestLine;
import org.apache.http.StatusLine;
import org.apache.http.Header;
@@ -81,7 +80,7 @@
public final static
HttpVersion parseProtocolVersion(String value,
LineParser parser)
- throws ProtocolException {
+ throws ParseException {
if (value == null) {
throw new IllegalArgumentException
@@ -101,7 +100,7 @@
public HttpVersion parseProtocolVersion(final CharArrayBuffer buffer,
final int indexFrom,
final int indexTo)
- throws ProtocolException {
+ throws ParseException {
if (buffer == null) {
throw new IllegalArgumentException
@@ -128,31 +127,33 @@
|| buffer.charAt(i + 2) != 'T'
|| buffer.charAt(i + 3) != 'P'
|| buffer.charAt(i + 4) != '/') {
- throw new ProtocolException("Not a valid HTTP version string: " +
+ throw new ParseException("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: " +
+ throw new ParseException("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));
+ throw new ParseException
+ ("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));
+ throw new ParseException(
+ "Invalid HTTP minor version number: " +
+ buffer.substring(indexFrom, indexTo));
}
return createProtocolVersion(major, minor);
} catch (IndexOutOfBoundsException e) {
- throw new ProtocolException("Invalid HTTP version string: " +
+ throw new ParseException("Invalid HTTP version string: " +
buffer.substring(indexFrom, indexTo));
}
} // parseProtocolVersion
@@ -176,7 +177,7 @@
public final static
RequestLine parseRequestLine(String value,
LineParser parser)
- throws ProtocolException {
+ throws ParseException {
if (value == null) {
throw new IllegalArgumentException
@@ -199,12 +200,12 @@
*
* @return the parsed request line
*
- * @throws ProtocolException in case of a parse error
+ * @throws ParseException in case of a parse error
*/
public RequestLine parseRequestLine(final CharArrayBuffer buffer,
final int indexFrom,
final int indexTo)
- throws ProtocolException {
+ throws ParseException {
if (buffer == null) {
throw new IllegalArgumentException
@@ -227,7 +228,7 @@
}
int blank = buffer.indexOf(' ', i, indexTo);
if (blank < 0) {
- throw new ProtocolException("Invalid request line: " +
+ throw new ParseException("Invalid request line: " +
buffer.substring(indexFrom, indexTo));
}
String method = buffer.substringTrimmed(i, blank);
@@ -237,15 +238,15 @@
}
blank = buffer.indexOf(' ', i, indexTo);
if (blank < 0) {
- throw new ProtocolException("Invalid request line: " +
+ throw new ParseException("Invalid request line: " +
buffer.substring(indexFrom, indexTo));
}
String uri = buffer.substringTrimmed(i, blank);
HttpVersion ver = parseProtocolVersion(buffer, blank, indexTo);
return createRequestLine(method, uri, ver);
} catch (IndexOutOfBoundsException e) {
- throw new ProtocolException("Invalid request line: " +
- buffer.substring(indexFrom, indexTo));
+ throw new ParseException("Invalid request line: " +
+ buffer.substring(indexFrom, indexTo));
}
} // parseRequestLine
@@ -271,7 +272,7 @@
public final static
StatusLine parseStatusLine(String value,
LineParser parser)
- throws ProtocolException {
+ throws ParseException {
if (value == null) {
throw new IllegalArgumentException
@@ -291,7 +292,7 @@
public StatusLine parseStatusLine(final CharArrayBuffer buffer,
final int indexFrom,
final int indexTo)
- throws ProtocolException {
+ throws ParseException {
if (buffer == null) {
throw new IllegalArgumentException
@@ -315,7 +316,7 @@
}
int blank = buffer.indexOf(' ', i, indexTo);
if (blank <= 0) {
- throw new ProtocolException(
+ throw new ParseException(
"Unable to parse HTTP-Version from the status line: "
+ buffer.substring(indexFrom, indexTo));
}
@@ -337,7 +338,7 @@
statusCode =
Integer.parseInt(buffer.substringTrimmed(i, blank));
} catch (NumberFormatException e) {
- throw new ProtocolException(
+ throw new ParseException(
"Unable to parse status code from status line: "
+ buffer.substring(indexFrom, indexTo));
}
@@ -352,8 +353,8 @@
return createStatusLine(ver, statusCode, reasonPhrase);
} catch (IndexOutOfBoundsException e) {
- throw new ProtocolException("Invalid status line: " +
- buffer.substring(indexFrom, indexTo));
+ throw new ParseException("Invalid status line: " +
+ buffer.substring(indexFrom, indexTo));
}
} // parseStatusLine
@@ -378,7 +379,7 @@
public final static
Header parseHeader(String value,
LineParser parser)
- throws ProtocolException {
+ throws ParseException {
if (value == null) {
throw new IllegalArgumentException
@@ -396,16 +397,10 @@
// non-javadoc, see interface LineParser
public Header parseHeader(CharArrayBuffer buffer)
- throws ProtocolException {
+ throws ParseException {
- Header result = null;
- try {
- // the actual parser code is in the constructor of BufferedHeader
- result = new BufferedHeader(buffer, getHeaderValueParser());
- } catch (ParseException px) {
- throw new ProtocolException(px.getMessage(), px);
- }
- return result;
+ // the actual parser code is in the constructor of BufferedHeader
+ return new BufferedHeader(buffer, getHeaderValueParser());
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java?rev=569638&r1=569637&r2=569638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/LineParser.java Sat Aug 25 00:59:03 2007
@@ -33,7 +33,7 @@
import org.apache.http.HttpVersion;
-import org.apache.http.ProtocolException;
+import org.apache.http.ParseException;
import org.apache.http.RequestLine;
import org.apache.http.StatusLine;
import org.apache.http.Header;
@@ -66,12 +66,12 @@
*
* @return the parsed protocol version
*
- * @throws ProtocolException in case of a parse error
+ * @throws ParseException in case of a parse error
*/
HttpVersion parseProtocolVersion(CharArrayBuffer buffer,
int indexFrom,
int indexTo)
- throws ProtocolException
+ throws ParseException
;
@@ -82,12 +82,12 @@
*
* @return the parsed request line
*
- * @throws ProtocolException in case of a parse error
+ * @throws ParseException in case of a parse error
*/
RequestLine parseRequestLine(CharArrayBuffer buffer,
int indexFrom,
int indexTo)
- throws ProtocolException
+ throws ParseException
;
@@ -98,12 +98,12 @@
*
* @return the parsed status line
*
- * @throws ProtocolException in case of a parse error
+ * @throws ParseException in case of a parse error
*/
StatusLine parseStatusLine(CharArrayBuffer buffer,
int indexFrom,
int indexTo)
- throws ProtocolException
+ throws ParseException
;
@@ -120,10 +120,10 @@
* The returned object MAY be a wrapper for the argument buffer.
* The argument buffer MUST NOT be re-used or changed afterwards.
*
- * @throws ProtocolException in case of a parse error
+ * @throws ParseException in case of a parse error
*/
Header parseHeader(CharArrayBuffer buffer)
- throws ProtocolException
+ throws ParseException
;
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java?rev=569638&r1=569637&r2=569638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/AbstractMessageParser.java Sat Aug 25 00:59:03 2007
@@ -38,6 +38,7 @@
import org.apache.http.HttpException;
import org.apache.http.HttpMessage;
+import org.apache.http.ParseException;
import org.apache.http.ProtocolException;
import org.apache.http.message.LineParser;
import org.apache.http.message.BasicLineParser;
@@ -101,9 +102,9 @@
}
protected abstract HttpMessage createMessage(CharArrayBuffer buffer)
- throws HttpException;
+ throws HttpException, ParseException;
- private void parseHeadLine() throws HttpException {
+ private void parseHeadLine() throws HttpException, ParseException {
this.message = createMessage(this.lineBuf);
}
@@ -152,7 +153,11 @@
switch (this.state) {
case READ_HEAD_LINE:
- parseHeadLine();
+ try {
+ parseHeadLine();
+ } catch (ParseException px) {
+ throw new ProtocolException(px.getMessage(), px);
+ }
this.state = READ_HEADERS;
break;
case READ_HEADERS:
@@ -176,8 +181,8 @@
CharArrayBuffer buffer = (CharArrayBuffer) this.headerBufs.get(i);
try {
this.message.addHeader(lineParser.parseHeader(buffer));
- } catch (IllegalArgumentException ex) {
- throw new ProtocolException(ex.getMessage());
+ } catch (ParseException ex) {
+ throw new ProtocolException(ex.getMessage(), ex);
}
}
return this.message;
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestParser.java?rev=569638&r1=569637&r2=569638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestParser.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpRequestParser.java Sat Aug 25 00:59:03 2007
@@ -35,6 +35,7 @@
import org.apache.http.HttpMessage;
import org.apache.http.HttpRequestFactory;
import org.apache.http.RequestLine;
+import org.apache.http.ParseException;
import org.apache.http.message.LineParser;
import org.apache.http.nio.reactor.SessionInputBuffer;
import org.apache.http.params.HttpParams;
@@ -57,7 +58,7 @@
}
protected HttpMessage createMessage(final CharArrayBuffer buffer)
- throws HttpException {
+ throws HttpException, ParseException {
RequestLine requestLine = lineParser.parseRequestLine(buffer, 0, buffer.length());
return this.requestFactory.newHttpRequest(requestLine);
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseParser.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseParser.java?rev=569638&r1=569637&r2=569638&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseParser.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/impl/nio/codecs/HttpResponseParser.java Sat Aug 25 00:59:03 2007
@@ -35,6 +35,7 @@
import org.apache.http.HttpMessage;
import org.apache.http.HttpResponseFactory;
import org.apache.http.StatusLine;
+import org.apache.http.ParseException;
import org.apache.http.message.LineParser;
import org.apache.http.nio.reactor.SessionInputBuffer;
import org.apache.http.params.HttpParams;
@@ -57,7 +58,7 @@
}
protected HttpMessage createMessage(final CharArrayBuffer buffer)
- throws HttpException {
+ throws HttpException, ParseException {
StatusLine statusline = lineParser.parseStatusLine(buffer, 0, buffer.length());
return this.responseFactory.newHttpResponse(statusline, null);
}