Package org.frankframework.util
Class MessageUtils
java.lang.Object
org.frankframework.util.MessageUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Deprecated.static Charset
computeDecodingCharset
(Message message) Reads the first 10k bytes of (binary) messages to determine the charset when not present in theMessageContext
.static Charset
computeDecodingCharset
(Message message, int confidence) Reads the first 10k bytes of (binary) messages to determine the charset when not present in theMessageContext
.static org.springframework.util.MimeType
computeMimeType
(Message message) Computes theMimeType
when not available.static org.springframework.util.MimeType
computeMimeType
(Message message, String filename) Computes theMimeType
when not already available, attempts to resolve the Charset when of type TEXT.static long
computeSize
(Message message) Resource intensive operation, calculates the binary size of a Message.static Message
convertToJsonMessage
(Object value) Convert input value to a message in JSON format and mimetype.static Message
convertToJsonMessage
(Object value, String valueName) Convert input value to a message in JSON format and mimetype.static Long
generateCRC32
(Message message) Resource intensive operation, preserves the message and calculates an CRC32 checksum over the entire message.static String
generateMD5Hash
(Message message) Resource intensive operation, preserves the message and calculates an MD5 hash over the entire message.static MessageContext
getContext
(jakarta.servlet.http.HttpServletRequest request) Fetch metadata from theHttpServletRequest
such as Content-Length, Content-Type (mimetype + charset)static MessageContext
getContext
(Iterator<jakarta.xml.soap.MimeHeader> mimeHeaders) static MessageContext
getContext
(org.apache.http.HttpResponse httpResponse) static org.springframework.util.MimeType
getMimeType
(Message message) Returns theMimeType
if present in theMessageContext
.static boolean
isMimeType
(Message message, org.springframework.util.MimeType compareTo) static Message
parse
(jakarta.xml.soap.AttachmentPart soapAttachment) static Message
parseContentAsMessage
(jakarta.servlet.http.HttpServletRequest request) If content is present (POST/PUT) one of the following headers must be set:
Content-Length / Transfer-Encoding
If neither header is present, or the size is0
anullMessage
will be returned.
-
Field Details
-
JSON_TEMPLATE_VALUE_QUOTED
- See Also:
-
JSON_TEMPLATE_VALUE_UNQUOTED
- See Also:
-
-
Method Details
-
getContext
Fetch metadata from theHttpServletRequest
such as Content-Length, Content-Type (mimetype + charset) -
getContext
-
getContext
-
parseContentAsMessage
public static Message parseContentAsMessage(jakarta.servlet.http.HttpServletRequest request) throws IOException If content is present (POST/PUT) one of the following headers must be set:
Content-Length / Transfer-Encoding
If neither header is present, or the size is0
anullMessage
will be returned.- Throws:
IOException
- See Also:
-
parse
public static Message parse(jakarta.xml.soap.AttachmentPart soapAttachment) throws jakarta.xml.soap.SOAPException - Throws:
jakarta.xml.soap.SOAPException
-
computeDecodingCharset
Reads the first 10k bytes of (binary) messages to determine the charset when not present in theMessageContext
.- Throws:
IOException
- when it cannot read the first 10k bytes.
-
computeDecodingCharset
Reads the first 10k bytes of (binary) messages to determine the charset when not present in theMessageContext
.- Parameters:
confidence
- percentage required to successfully determine the charset.- Throws:
IOException
- when it cannot read the first 10k bytes.
-
getMimeType
Returns theMimeType
if present in theMessageContext
. -
isMimeType
-
computeMimeType
Computes theMimeType
when not available.NOTE: This is a resource intensive operation, the first 64k is being read and stored in memory.
-
computeMimeType
Computes theMimeType
when not already available, attempts to resolve the Charset when of type TEXT.When there is no filename for the Message and Apache TIKA deduces mime type text/plain, a heuristic is applied. If the message starts with '<' the mime type application/xml is returned. If the message starts with '[' or invalid input: '{@literal '{'} the mime type {@literal application/json} is returned. Otherwise it will be {@literal text/plain} as Apache TIKA returned. </p> @ff.note This might be a resource intensive operation, the first kilobytes of the message are potentially being read and stored in memory.'
-
generateMD5Hash
Resource intensive operation, preserves the message and calculates an MD5 hash over the entire message. -
generateCRC32
Resource intensive operation, preserves the message and calculates an CRC32 checksum over the entire message. -
computeSize
Resource intensive operation, calculates the binary size of a Message. -
asString
Deprecated.Convert an object to a string. Does not close object when it is of type Message or MessageWrapper.- Throws:
IOException
-
convertToJsonMessage
@Nonnull public static Message convertToJsonMessage(@Nonnull Object value) throws IOException, XmlException Convert input value to a message in JSON format and mimetype. If the input value is already JSON, then it is returned as-is. If the value is in XML format, it will be converted to JSON usingUtilityTransformerPools.getXml2JsonTransformerPool()
. Otherwise the string-value of the input-value will be wrapped as JSON as{"value": value}
.- Throws:
IOException
XmlException
-
convertToJsonMessage
@Nonnull public static Message convertToJsonMessage(@Nonnull Object value, @Nonnull String valueName) throws IOException, XmlException Convert input value to a message in JSON format and mimetype. If the input value is already JSON, then it is returned as-is. If the value is in XML format, it will be converted to JSON usingUtilityTransformerPools.getXml2JsonTransformerPool()
. Otherwise the string-value of the input-value will be wrapped as JSON as{"valueName": value}
, using parametervalueName
as name of the object.- Throws:
IOException
XmlException
-