Class Message
- All Implemented Interfaces:
Closeable
,Serializable
,AutoCloseable
- Direct Known Subclasses:
FileMessage
,PartMessage
,PathMessage
,UrlMessage
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final long
static final long
static final String
static final long
-
Constructor Summary
ConstructorsModifierConstructorDescriptionMessage
(byte[] request) Message
(byte[] request, MessageContext context) Message
(InputStream request) Message
(InputStream request, String charset) Message
(InputStream request, MessageContext context) protected
Message
(InputStream request, MessageContext context, Class<?> requestClass) Message
(Reader request, MessageContext context) Message
(String request, MessageContext context) protected
Message
(ThrowingSupplier<InputStream, Exception> request, MessageContext context, Class<?> requestClass) Constructor for Message using InputStream supplier.protected
Message
(SerializableFileReference request, MessageContext context, Class<?> requestClass) Constructor for Message using aSerializableFileReference
.Message
(Node request, MessageContext context) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]
Return the request object as a byte array.byte[]
asByteArray
(String defaultEncodingCharset) Return the request object as a byte array.return the request object as aInputSource
.Return anInputStream
backed by the data in this message.asInputStream
(String defaultEncodingCharset) Return anInputStream
backed by the data in this message.static Message
Please note that this method should only be used when you don't know the type of object.asObject()
Deprecated.Please avoid the use of the raw object.asReader()
Return aReader
backed by the data in this message.Return aReader
backed by the data in this message.void
asSource()
return the request object as aSource
.asString()
return the request object as a String.return the request object as a String.void
close()
protected String
computeDecodingCharset
(String defaultDecodingCharset) If no Charset was provided when the Message object was created and the requested Charset isauto, try to parse the Charset using
MessageUtils.computeDecodingCharset(Message)
.Creates a copy of this Message object.Representing a charset of binary requestsReturns the message identifier and which resource class it representsboolean
isBinary()
boolean
isEmpty()
Check if a message is empty.static boolean
Check if the message passed is null or empty.static boolean
isFormattedErrorMessage
(Message message) boolean
isNull()
static boolean
boolean
isRequestOfType
(Class<?> clazz) static Message
static Message
nullMessage
(MessageContext context) peek
(int readLimit) boolean
If true, the Message should preferably be read using a streaming method, i.e. asReader() or asInputStream(), to avoid copying it into memory.long
size()
toString()
toString can be used to inspect the message.
-
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
- See Also:
-
MESSAGE_MAX_IN_MEMORY
public static final long MESSAGE_MAX_IN_MEMORY
-
-
Constructor Details
-
Message
-
Message
-
Message
-
Message
-
Message
public Message(byte[] request) -
Message
- Throws:
IOException
-
Message
- Throws:
IOException
-
Message
protected Message(ThrowingSupplier<InputStream, Exception> request, @Nonnull MessageContext context, Class<?> requestClass) Constructor for Message using InputStream supplier. It is assumed the InputStream can be supplied multiple times. -
Message
protected Message(@Nonnull SerializableFileReference request, @Nonnull MessageContext context, Class<?> requestClass) Constructor for Message using aSerializableFileReference
.- Parameters:
request
- Request asSerializableFileReference
context
-MessageContext
requestClass
-Class
of the original request from which theSerializableFileReference
request was created
-
Message
- Throws:
IOException
-
Message
- Throws:
IOException
-
Message
protected Message(@Nonnull InputStream request, @Nonnull MessageContext context, Class<?> requestClass) throws IOException - Throws:
IOException
-
Message
- Throws:
IOException
-
Message
-
Message
-
-
Method Details
-
nullMessage
-
nullMessage
-
copyContext
-
getCharset
Representing a charset of binary requests- Returns:
- the charset provided when the message was created
-
computeDecodingCharset
If no Charset was provided when the Message object was created and the requested Charset isauto, 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.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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
asReader
Return aReader
backed by the data in this message.Reader.markSupported()
is guaranteed to be true for the returned stream.- Throws:
IOException
-
asReader
Return aReader
backed by the data in this message.Reader.markSupported()
is guaranteed to be true for the returned stream.- Parameters:
defaultDecodingCharset
- is only used whenisBinary()
istrue
.- Throws:
IOException
-
asInputStream
Return anInputStream
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 anInputStream
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
- Throws:
IOException
-
asInputSource
return the request object as aInputSource
.- Throws:
IOException
-
asSource
return the request object as aSource
.- Throws:
IOException
SAXException
-
asByteArray
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
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
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
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
- 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
toString can be used to inspect the message. It does not convert the 'request' to a string. -
getObjectId
Returns the message identifier and which resource class it represents- Returns:
- Message[1234abcd:ByteArrayInputStream]
-
asMessage
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 ofMessage
or a more applicable subclass likeFileMessage
orUrlMessage
- Returns:
- a Message of the correct type for the given object
-
isEmpty
Check if the message passed is null or empty.- Parameters:
message
- Message to check. Can benull
.- Returns:
- Returns
true
if the message isnull
, otherwise the result ofisEmpty()
.
-
isNull
-
assertNotClosed
public void assertNotClosed() -
size
public long size()- Returns:
- Message size or -1 if it can't determine the size.
-
copyMessage
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
-