Package org.apache.http.impl.io
Class AbstractMessageParser<T extends HttpMessage>
- java.lang.Object
-
- org.apache.http.impl.io.AbstractMessageParser<T>
-
- All Implemented Interfaces:
HttpMessageParser<T>
- Direct Known Subclasses:
DefaultHttpRequestParser
,DefaultHttpResponseParser
,HttpRequestParser
,HttpResponseParser
public abstract class AbstractMessageParser<T extends HttpMessage> extends java.lang.Object implements HttpMessageParser<T>
Abstract base class for HTTP message parsers that obtain input from an instance ofSessionInputBuffer
.- Since:
- 4.0
-
-
Field Summary
Fields Modifier and Type Field Description private static int
HEAD_LINE
private java.util.List<CharArrayBuffer>
headerLines
private static int
HEADERS
protected LineParser
lineParser
private T
message
private MessageConstraints
messageConstraints
private SessionInputBuffer
sessionBuffer
private int
state
-
Constructor Summary
Constructors Constructor Description AbstractMessageParser(SessionInputBuffer buffer, LineParser lineParser, MessageConstraints constraints)
Creates new instance of AbstractMessageParser.AbstractMessageParser(SessionInputBuffer buffer, LineParser parser, HttpParams params)
Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description T
parse()
Generates an instance ofHttpMessage
from the underlying data source.protected abstract T
parseHead(SessionInputBuffer sessionBuffer)
Subclasses must override this method to generate an instance ofHttpMessage
based on the initial input from the session buffer.static Header[]
parseHeaders(SessionInputBuffer inBuffer, int maxHeaderCount, int maxLineLen, LineParser parser)
Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.static Header[]
parseHeaders(SessionInputBuffer inBuffer, int maxHeaderCount, int maxLineLen, LineParser parser, java.util.List<CharArrayBuffer> headerLines)
Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.
-
-
-
Field Detail
-
HEAD_LINE
private static final int HEAD_LINE
- See Also:
- Constant Field Values
-
HEADERS
private static final int HEADERS
- See Also:
- Constant Field Values
-
sessionBuffer
private final SessionInputBuffer sessionBuffer
-
messageConstraints
private final MessageConstraints messageConstraints
-
headerLines
private final java.util.List<CharArrayBuffer> headerLines
-
lineParser
protected final LineParser lineParser
-
state
private int state
-
message
private T extends HttpMessage message
-
-
Constructor Detail
-
AbstractMessageParser
@Deprecated public AbstractMessageParser(SessionInputBuffer buffer, LineParser parser, HttpParams params)
Deprecated.Creates an instance of AbstractMessageParser.- Parameters:
buffer
- the session input buffer.parser
- the line parser.params
- HTTP parameters.
-
AbstractMessageParser
public AbstractMessageParser(SessionInputBuffer buffer, LineParser lineParser, MessageConstraints constraints)
Creates new instance of AbstractMessageParser.- Parameters:
buffer
- the session input buffer.lineParser
- the line parser. Ifnull
BasicLineParser.INSTANCE
will be used.constraints
- the message constraints. Ifnull
MessageConstraints.DEFAULT
will be used.- Since:
- 4.3
-
-
Method Detail
-
parseHeaders
public static Header[] parseHeaders(SessionInputBuffer inBuffer, int maxHeaderCount, int maxLineLen, LineParser parser) throws HttpException, java.io.IOException
Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.- Parameters:
inBuffer
- Session input buffermaxHeaderCount
- maximum number of headers allowed. If the number of headers received from the data stream exceeds maxCount value, an IOException will be thrown. Setting this parameter to a negative value or zero will disable the check.maxLineLen
- maximum number of characters for a header line, including the continuation lines. Setting this parameter to a negative value or zero will disable the check.parser
- line parser to use. Can benull
, in which case the default implementation of this interface will be used.- Returns:
- array of HTTP headers
- Throws:
java.io.IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation
-
parseHeaders
public static Header[] parseHeaders(SessionInputBuffer inBuffer, int maxHeaderCount, int maxLineLen, LineParser parser, java.util.List<CharArrayBuffer> headerLines) throws HttpException, java.io.IOException
Parses HTTP headers from the data receiver stream according to the generic format as given in Section 3.1 of RFC 822, RFC-2616 Section 4 and 19.3.- Parameters:
inBuffer
- Session input buffermaxHeaderCount
- maximum number of headers allowed. If the number of headers received from the data stream exceeds maxCount value, an IOException will be thrown. Setting this parameter to a negative value or zero will disable the check.maxLineLen
- maximum number of characters for a header line, including the continuation lines. Setting this parameter to a negative value or zero will disable the check.parser
- line parser to use.headerLines
- List of header lines. This list will be used to store intermediate results. This makes it possible to resume parsing of headers in case of aInterruptedIOException
.- Returns:
- array of HTTP headers
- Throws:
java.io.IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation- Since:
- 4.1
-
parseHead
protected abstract T parseHead(SessionInputBuffer sessionBuffer) throws java.io.IOException, HttpException, ParseException
Subclasses must override this method to generate an instance ofHttpMessage
based on the initial input from the session buffer.Usually this method is expected to read just the very first line or the very first valid from the data stream and based on the input generate an appropriate instance of
HttpMessage
.- Parameters:
sessionBuffer
- the session input buffer.- Returns:
- HTTP message based on the input from the session buffer.
- Throws:
java.io.IOException
- in case of an I/O error.HttpException
- in case of HTTP protocol violation.ParseException
- in case of a parse error.
-
parse
public T parse() throws java.io.IOException, HttpException
Description copied from interface:HttpMessageParser
Generates an instance ofHttpMessage
from the underlying data source.- Specified by:
parse
in interfaceHttpMessageParser<T extends HttpMessage>
- Returns:
- HTTP message
- Throws:
java.io.IOException
- in case of an I/O errorHttpException
- in case of HTTP protocol violation
-
-