Class Message

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

@NullMarked public class Message extends Object implements Serializable
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

      public static Message nullMessage()
    • nullMessage

      public static Message nullMessage(MessageContext context)
    • copyContext

      public MessageContext copyContext()
    • getCharset

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

      protected String computeDecodingCharset(@Nullable 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 public @Nullable 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.
    • asReader

      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

      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

      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

      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

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

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

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

      public byte @Nullable [] 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

      public byte @Nullable [] 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

      public @Nullable 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

      public @Nullable 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(@Nullable 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
    • isSupportedType

      public static boolean isSupportedType(@Nullable Object request)
    • isEmpty

      public static boolean isEmpty(@Nullable 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)
    • size

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

      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(@Nullable Message message)