Class Message

java.lang.Object
com.predic8.membrane.core.http.Message
Direct Known Subclasses:
Request, Response

public abstract class Message extends Object
A HTTP message (request or response).
  • Field Details

  • Constructor Details

    • Message

      public Message()
  • Method Details

    • read

      public void read(InputStream in, boolean createBody) throws IOException, EndOfStreamException
      If the message is HTTP 1.1 but the header has no information about the content length, then an assumption is made that after the body the server will send an EOF. So the body is read till end of the stream. See http://www.ietf.org/rfc/rfc2145.txt
      Throws:
      IOException
      EndOfStreamException
    • readBody

      public void readBody() throws IOException
      Throws:
      IOException
    • discardBody

      public void discardBody()
    • getBody

      public AbstractBody getBody()
    • getBodyAsStream

      public InputStream getBodyAsStream()

      Probably you want to use getBodyAsStreamDecoded() instead:

      Transfer-Encodings (e.g. chunking) have been unapplied, but Content-Encodings (e.g. gzip) have not.

      Returns the body as a stream.

      Supports streaming: The HTTP message does not have to be completely received yet for this method to return.

      See Also:
    • getBodyAsStreamDecoded

      public InputStream getBodyAsStreamDecoded()

      Returns the logical body content.

      Any Transfer-Encodings (e.g. chunking) and/or Content-Encodings (e.g. gzip) have been unapplied.

      Supports streaming: The HTTP message does not have to be completely received yet for this method to return.

    • getBodyAsStringDecoded

      public String getBodyAsStringDecoded()

      As this method has bad performance, it should not be used in any critical component. (Use getBodyAsStreamDecoded() instead.)

      Allocates a new String object for the whole body (potentially performing charset conversion).

      Blocks until the body has been fully received.

      (... and more bad internal performance)

      Returns:
      the message's body as a Java String.
    • setBody

      public void setBody(AbstractBody b)
      Sets the body. Does NOT adjust the header fields (Content-Length etc.): Use setBodyContent(byte[]) instead.
    • setBodyContent

      public void setBodyContent(byte[] content)
      Sets the body. Also adjusts the header fields (Content-Length, Content-Encoding, Transfer-Encoding).
    • createBody

      protected void createBody(InputStream in) throws IOException
      Throws:
      IOException
    • parseStartLine

      protected abstract void parseStartLine(InputStream in) throws IOException, EndOfStreamException
      Throws:
      IOException
      EndOfStreamException
    • getHeader

      public Header getHeader()
    • release

      public void release()
      preserve synchronized keyword, notify method is called
    • hasMsgReleased

      public boolean hasMsgReleased()
    • setHeader

      public void setHeader(Header srcHeader)
    • write

      public final void write(OutputStream out, boolean retainBody) throws IOException
      Throws:
      IOException
    • writeStartLine

      public void writeStartLine(OutputStream out) throws IOException
      The start line supposedly only contains ASCII characters. But since HttpUtil.readLine(InputStream) converts the input byte-by-byte to char-by-char, we use ISO-8859-1 for output.
      Throws:
      IOException
    • getStartLine

      public abstract String getStartLine()
    • isHTTP11

      public boolean isHTTP11()
    • isHTTP10

      public boolean isHTTP10()
    • getVersion

      public String getVersion()
    • setVersion

      public void setVersion(String version)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isKeepAlive

      public boolean isKeepAlive()
    • getErrorMessage

      public String getErrorMessage()
    • setErrorMessage

      public void setErrorMessage(String errorMessage)
    • getName

      public String getName()
    • isBodyEmpty

      public boolean isBodyEmpty() throws IOException
      Throws:
      IOException
    • shouldNotContainBody

      public abstract boolean shouldNotContainBody()
    • isImage

      public boolean isImage()
    • isXML

      public boolean isXML()
    • isJSON

      public boolean isJSON()
    • isHTML

      public boolean isHTML()
    • isCSS

      public boolean isCSS()
    • isJavaScript

      public boolean isJavaScript()
    • isGzip

      public boolean isGzip()
    • isDeflate

      public boolean isDeflate()
    • getCharset

      public String getCharset()
    • addObserver

      public void addObserver(MessageObserver observer)
    • estimateHeapSize

      public int estimateHeapSize()
    • createSnapshot

      public abstract <T extends Message> T createSnapshot(Runnable bodyUpdatedCallback, BodyCollectingMessageObserver.Strategy strategy, long limit) throws Exception
      Throws:
      Exception
    • createMessageSnapshot

      public <T extends Message> T createMessageSnapshot(T result, Runnable bodyUpdatedCallback, BodyCollectingMessageObserver.Strategy strategy, long limit)
    • isReleased

      public boolean isReleased()
    • setReleased

      public void setReleased(boolean released)
    • containsObserver

      public boolean containsObserver(MessageObserver obs)