Class MessageUtils
java.lang.Object
org.frankframework.util.MessageUtils
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic @Nullable StringDeprecated.static @Nullable CharsetcomputeDecodingCharset(Message message) Reads the first 10k bytes of (binary) messages to determine the charset when not present in theMessageContext.static @Nullable CharsetcomputeDecodingCharset(Message message, int confidence) Reads the first 10k bytes of (binary) messages to determine the charset when not present in theMessageContext.static @Nullable org.springframework.util.MimeTypecomputeMimeType(@Nullable Message message) Computes theMimeTypewhen not available.static @Nullable org.springframework.util.MimeTypecomputeMimeType(@Nullable Message message, @Nullable String filename) Computes theMimeTypewhen not already available, attempts to resolve the Charset when of type TEXT.static longcomputeSize(@NonNull Message message) Resource intensive operation, calculates the binary size of a Message.static @NonNull MessageconvertToJsonMessage(@NonNull Object value) Convert input value to a message in JSON format and mimetype.static @NonNull MessageconvertToJsonMessage(@NonNull Object value, @NonNull String valueName) Convert input value to a message in JSON format and mimetype.static @NonNull MessagefromInputStream(@NonNull InputStream inputStream) Fully readInputStreamand create a message from it, so that the InputStream can be closed without losing the message contents.static @NonNull MessagefromReader(@NonNull Reader reader) Fully readReaderand create a Message from it, so that the Reader can be closed without losing the message contents.static @Nullable LonggenerateCRC32(@NonNull Message message) Resource intensive operation, preserves the message and calculates an CRC32 checksum over the entire message.static @NonNull Stringstatic @Nullable StringgenerateMD5Hash(@NonNull Message message) Resource intensive operation, preserves the message and calculates an MD5 hash over the entire message.static @NonNull Stringstatic @NonNull StringgenerateMessageId(String prefix) static @NonNull MessageContextgetContext(@NonNull jakarta.servlet.http.HttpServletRequest request) Fetch metadata from theHttpServletRequestsuch as Content-Length, Content-Type (mimetype + charset)static @NonNull MessageContextgetContext(@NonNull Iterator<jakarta.xml.soap.MimeHeader> mimeHeaders) static @NonNull MessageContextgetContext(@NonNull org.apache.http.HttpResponse httpResponse) static @Nullable org.springframework.util.MimeTypegetMimeType(Message message) Returns theMimeTypeif present in theMessageContext.static booleanisFallbackMessageId(@NonNull String messageId) static booleanisMimeType(@NonNull Message message, @Nullable org.springframework.util.MimeType compareTo) static @NonNull Messageparse(jakarta.xml.soap.AttachmentPart soapAttachment) static @NonNull MessageparseContentAsMessage(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 is0anullMessagewill be returned.
-
Field Details
-
CHARSET_CONFIDENCE_LEVEL
public static final int CHARSET_CONFIDENCE_LEVEL -
JSON_TEMPLATE_VALUE_QUOTED
- See Also:
-
JSON_TEMPLATE_VALUE_UNQUOTED
- See Also:
-
DEFAULT_MESSAGE_ID_PREFIX
- See Also:
-
FALLBACK_MESSAGE_ID_PREFIX
- See Also:
-
-
Method Details
-
fromInputStream
Fully readInputStreamand create a message from it, so that the InputStream can be closed without losing the message contents.- Throws:
IOException
-
fromReader
Fully readReaderand create a Message from it, so that the Reader can be closed without losing the message contents.- Throws:
IOException
-
getContext
public static @NonNull MessageContext getContext(@NonNull jakarta.servlet.http.HttpServletRequest request) Fetch metadata from theHttpServletRequestsuch as Content-Length, Content-Type (mimetype + charset) -
getContext
public static @NonNull MessageContext getContext(@NonNull Iterator<jakarta.xml.soap.MimeHeader> mimeHeaders) -
getContext
public static @NonNull MessageContext getContext(@NonNull org.apache.http.HttpResponse httpResponse) -
parseContentAsMessage
public static @NonNull 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 is0anullMessagewill be returned.- Throws:
IOException- See Also:
-
parse
public static @NonNull 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
public static @Nullable Charset computeDecodingCharset(Message message, int confidence) throws IOException 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 theMimeTypeif present in theMessageContext. -
isMimeType
public static boolean isMimeType(@NonNull Message message, @Nullable org.springframework.util.MimeType compareTo) -
computeMimeType
public static @Nullable org.springframework.util.MimeType computeMimeType(@Nullable Message message) Computes theMimeTypewhen not available.NOTE: This is a resource intensive operation, the first 64k is being read and stored in memory.
-
computeMimeType
public static @Nullable org.springframework.util.MimeType computeMimeType(@Nullable Message message, @Nullable String filename) Computes theMimeTypewhen 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 '{' the mime type application/json is returned. Otherwise it will be text/plain as Apache TIKA returned.
-
generateMD5Hash
-
generateCRC32
-
computeSize
Resource intensive operation, calculates the binary size of a Message. -
asString
-
convertToJsonMessage
public static @NonNull 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:
IOExceptionXmlException
-
convertToJsonMessage
public static @NonNull 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 parametervalueNameas name of the object.- Throws:
IOExceptionXmlException
-
generateMessageId
-
generateMessageId
-
generateFallbackMessageId
-
isFallbackMessageId
-