Class Message

java.lang.Object
org.frankframework.stream.Message
All Implemented Interfaces:
Closeable, Serializable, AutoCloseable
Direct Known Subclasses:
FileMessage, PartMessage, PathMessage, UrlMessage

public class Message extends Object implements Serializable, Closeable
A Serializable wrapper around data passed to the Frank!Framework and between pipes in the pipeline.

Regardless of the original format of the data, the system will always allow repeatable access to the data in multiple formats, such as InputStream, Reader, byte[], String and for XML data, also as InputSource or Source.

The Frank!Framework will intelligently buffer message data to memory or disk depending on size and configured limits. The limit for data held in memory is controlled via property "message.max.memory.size". The default value is 5242880L.

Operations on a Message that change state, such as preserve(boolean) (and implicitly serializing the Message) are not thread-safe. If there is a chance that these operations are simultaneously executed from multiple threads, they need to be wrapped in a synchronized block that synchronizes on the message instance.

See Also:
  • Field Details

    • MESSAGE_SIZE_UNKNOWN

      public static final long MESSAGE_SIZE_UNKNOWN
      See Also:
    • MESSAGE_MAX_IN_MEMORY_DEFAULT

      public static final long MESSAGE_MAX_IN_MEMORY_DEFAULT
      See Also:
    • MESSAGE_MAX_IN_MEMORY_PROPERTY

      public static final String MESSAGE_MAX_IN_MEMORY_PROPERTY
      See Also:
    • MESSAGE_MAX_IN_MEMORY

      public static final long MESSAGE_MAX_IN_MEMORY
  • Constructor Details

  • Method Details

    • nullMessage

      @Nonnull public static Message nullMessage()
    • nullMessage

      @Nonnull public static Message nullMessage(@Nonnull MessageContext context)
    • copyContext

      @Nonnull public MessageContext copyContext()
    • getCharset

      @Nullable public String getCharset()
      Representing a charset of binary requests
      Returns:
      the charset provided when the message was created
    • computeDecodingCharset

      @Nonnull protected String computeDecodingCharset(String defaultDecodingCharset) throws IOException
      If no Charset was provided when the Message object was created and the requested Charset is auto, try to parse the Charset using MessageUtils.computeDecodingCharset(Message). If unsuccessful return the default Charset: UTF_8.
      Parameters:
      defaultDecodingCharset - The 'I know better' Charset, only used when no Charset is provided when the Message was created.
      Throws:
      IOException
    • asObject

      @Deprecated @Nullable public Object asObject()
      Deprecated.
      Please avoid the use of the raw object.
    • isBinary

      public boolean isBinary()
    • requiresStream

      public boolean requiresStream()
      If true, the Message should preferably be read using a streaming method, i.e. asReader() or asInputStream(), to avoid copying it into memory.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • asReader

      @Nullable public Reader asReader() throws IOException
      Return a Reader backed by the data in this message. Reader.markSupported() is guaranteed to be true for the returned stream.
      Throws:
      IOException
    • asReader

      @Nullable public Reader asReader(@Nullable String defaultDecodingCharset) throws IOException
      Return a Reader backed by the data in this message. Reader.markSupported() is guaranteed to be true for the returned stream.
      Parameters:
      defaultDecodingCharset - is only used when isBinary() is true.
      Throws:
      IOException
    • asInputStream

      @Nullable public InputStream asInputStream() throws IOException
      Return an InputStream backed by the data in this message. InputStream.markSupported() is guaranteed to be true for the returned stream.
      Throws:
      IOException
    • asInputStream

      @Nullable public InputStream asInputStream(@Nullable String defaultEncodingCharset) throws IOException
      Return an InputStream backed by the data in this message. InputStream.markSupported() is guaranteed to be true for the returned stream.
      Parameters:
      defaultEncodingCharset - is only used when the Message object is of character type (String)
      Throws:
      IOException
    • peek

      @Nonnull public String peek(int readLimit) throws IOException
      Throws:
      IOException
    • asInputSource

      @Nullable public InputSource asInputSource() throws IOException
      return the request object as a InputSource.
      Throws:
      IOException
    • asSource

      @Nullable public Source asSource() throws IOException, SAXException
      return the request object as a Source.
      Throws:
      IOException
      SAXException
    • asByteArray

      @Nullable public byte[] asByteArray() throws IOException
      Return the request object as a byte array. This may have the side effect of preserving the input as byte array. This operation is not thread-safe.
      Throws:
      IOException
    • asByteArray

      @Nullable public byte[] asByteArray(@Nullable String defaultEncodingCharset) throws IOException
      Return the request object as a byte array. This may have the side effect of preserving the input as byte array. This operation is not thread-safe.
      Throws:
      IOException
    • asString

      @Nullable public String asString() throws IOException
      return the request object as a String. This may have the side effect of preserving the input as a String, thus modifying the state of the Message object. This operation is not thread-safe.
      Throws:
      IOException
    • asString

      @Nullable public String asString(@Nullable String decodingCharset) throws IOException
      return the request object as a String. This may have the side effect of preserving the input as a String, thus modifying the state of the Message object. This operation is not thread-safe.
      Throws:
      IOException
    • isNull

      public boolean isNull()
    • isRequestOfType

      public boolean isRequestOfType(Class<?> clazz)
      Returns:
      true if the request is or extends of the specified type at parameter clazz
    • isEmpty

      public boolean isEmpty()
      Check if a message is empty. If message size cannot be determined, check if any data can be read from the message.
      Returns:
      true if the message is empty or no data can be read from it, false if the size if larger than 0 or data can be read from it.
    • toString

      public String toString()
      toString can be used to inspect the message. It does not convert the 'request' to a string.
      Overrides:
      toString in class Object
    • getObjectId

      public String getObjectId()
      Returns the message identifier and which resource class it represents
      Returns:
      Message[1234abcd:ByteArrayInputStream]
    • asMessage

      public static Message asMessage(Object object)
      Please note that this method should only be used when you don't know the type of object. In all other cases, use the constructor of Message or a more applicable subclass like FileMessage or UrlMessage
      Returns:
      a Message of the correct type for the given object
    • isEmpty

      public static boolean isEmpty(Message message)
      Check if the message passed is null or empty.
      Parameters:
      message - Message to check. Can be null.
      Returns:
      Returns true if the message is null, otherwise the result of isEmpty().
    • isNull

      public static boolean isNull(@Nullable Message message)
    • assertNotClosed

      public void assertNotClosed()
    • size

      public long size()
      Returns:
      Message size or -1 if it can't determine the size.
    • copyMessage

      @Nonnull public Message copyMessage() throws IOException
      Creates a copy of this Message object.

      NB: To copy the underlying value of the message object, the message may be preserved if it was not repeatable. Thus this operation may modify the state of the message object.

      Returns:
      A new Message object that is a copy of this Message.
      Throws:
      IOException - If an I/O error occurs during the copying process.
    • isFormattedErrorMessage

      public static boolean isFormattedErrorMessage(Message message)