Class HttpDecoder<T extends HttpMessageHeader,R extends HttpMessageHeader>
java.lang.Object
org.jdrupes.httpcodec.protocols.http.HttpCodec<T>
org.jdrupes.httpcodec.protocols.http.HttpDecoder<T,R>
- Type Parameters:
T
- the type of the message header to be decodedR
- the type of the response message header
- Direct Known Subclasses:
HttpRequestDecoder
,HttpResponseDecoder
public abstract class HttpDecoder<T extends HttpMessageHeader,R extends HttpMessageHeader>
extends HttpCodec<T>
implements Decoder<T,R>
Implements a decoder for HTTP.
The class can be used as base class for both a request and a response decoder.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static enum
static class
HttpDecoder.Result<R extends MessageHeader>
Results fromHttpDecoder
add no additional information toDecoder.Result
.Nested classes/interfaces inherited from interface org.jdrupes.httpcodec.Codec
Codec.ProtocolSwitchResult
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected HttpConstants.HttpProtocol
protected static final String
Fields inherited from class org.jdrupes.httpcodec.protocols.http.HttpCodec
messageHeader
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiondecode
(ByteBuffer in, Buffer out, boolean endOfInput) Decodes the next chunk of data.header()
Returns the message (header) if one exists.protected abstract HttpDecoder.BodyMode
headerReceived
(T message) Informs the derived class that the header has been received completely.boolean
boolean
isClosed()
Returns true if the decoder does not accept further input because the processed data indicated that the connection has been or is to be closed.long
Returns the maximum header length.protected Decoder.Result<R>
messageComplete
(Decoder.Result<R> result) Informs the derived class that a complete message has been received and the given result will be returned.protected abstract T
newMessage
(String startLine) Informs the derived class about the start of a new message.protected abstract HttpDecoder.Result.Factory<R>
Returns the result factory for this codec.void
setMaxHeaderLength
(long maxHeaderLength) Sets the maximum size for the complete header.setPeerEncoder
(Encoder<R, T> encoder) Sets the peer encoder.Methods inherited from class org.jdrupes.httpcodec.protocols.http.HttpCodec
bodyCharset
-
Field Details
-
SP
- See Also:
-
HTTP_VERSION
- See Also:
-
protocolVersion
-
peerEncoder
-
-
Constructor Details
-
HttpDecoder
public HttpDecoder()Creates a new decoder.
-
-
Method Details
-
setPeerEncoder
Description copied from interface:Decoder
Sets the peer encoder.Some decoders need to know the state of the encoder or the last encoded message.
- Specified by:
setPeerEncoder
in interfaceDecoder<T extends HttpMessageHeader,
R extends HttpMessageHeader> - Parameters:
encoder
- the encoder- Returns:
- the decoder
-
isAwaitingMessage
-
resultFactory
Returns the result factory for this codec.- Returns:
- the factory
-
setMaxHeaderLength
Sets the maximum size for the complete header.If the size is exceeded, a
HttpProtocolException
will be thrown. The default size is 4MB (4194304 Byte).- Parameters:
maxHeaderLength
- the maxHeaderLength to set
-
maxHeaderLength
Returns the maximum header length.- Returns:
- the maxHeaderLength
-
header
Returns the message (header) if one exists.- Specified by:
header
in interfaceDecoder<T extends HttpMessageHeader,
R extends HttpMessageHeader> - Returns:
- the result
-
isClosed
Returns true if the decoder does not accept further input because the processed data indicated that the connection has been or is to be closed.- Returns:
- the result
-
newMessage
Informs the derived class about the start of a new message.- Parameters:
startLine
- the start line (first line) of the message- Returns:
- the new HttpMessage object that is to hold the decoded data
- Throws:
HttpProtocolException
- if the input violates the HTTPProtocolException
-
headerReceived
Informs the derived class that the header has been received completely.- Parameters:
message
- the message- Returns:
- indication how the body will be transferred
- Throws:
HttpProtocolException
- if the input violates the HTTPProtocolException
-
messageComplete
Informs the derived class that a complete message has been received and the given result will be returned.The derived class may take additional actions and even modify the result. The default implementation simply returns the given result.
-
decode
public Decoder.Result<R> decode(ByteBuffer in, Buffer out, boolean endOfInput) throws ProtocolException Decodes the next chunk of data.- Specified by:
decode
in interfaceDecoder<T extends HttpMessageHeader,
R extends HttpMessageHeader> - Parameters:
in
- holds the data to be decodedout
- gets the body data (if any) written to itendOfInput
- true if there is no input left beyond the data currently in the in buffer (indicates end of body or no body at all)- Returns:
- the result
- Throws:
ProtocolException
- if the message violates the Protocol
-