Class ErrorMessageFormatter
java.lang.Object
org.frankframework.errormessageformatters.ErrorMessageFormatter
- All Implemented Interfaces:
IErrorMessageFormatter, IScopeProvider
- Direct Known Subclasses:
DataSonnetErrorMessageFormatter, FixedErrorMessageFormatter, SoapErrorMessageFormatter, XslErrorMessageFormatter
This is the default
IErrorMessageFormatter implementation that is used when no specific ErrorMessageFormatter has
been configured. It wraps an error in an XML or JSON string. XML is the default.
If the exception is a PipeRunException that has parameters set on it, then these parameters
are added to a params element in the error message. These parameters can be set from an
ExceptionPipe.
If you need more control over the layout of the error message, then configure your Adapter or
Configuration with an ErrorMessageFormatter implementation
that can reformat the error message to the desired layout: the XslErrorMessageFormatter for XML error formats or the
DataSonnetErrorMessageFormatter for JSON error messages.
Sample xml:
<errorMessage>
<message timestamp="Mon Oct 13 12:01:57 CEST 2003"
originator="NN IOS AdapterFramework(set from 'application.name' and 'application.version')"
message="message describing the error that occurred">
<location class="org.frankframework.pipes.SwitchPipe" name="ServiceSwitch"/>
<details>Exception and stacktrace</details>
<params>
<param name="sampleParam">paramValue</param>
<param name="errorCode">535</param>
</params>
<originalMessage messageId="..." receivedTime="Mon Oct 27 12:10:18 CET 2003" >
<![CDATA[contents of message for which the error occurred]]>
</originalMessage>
</errorMessage>
Sample JSON:
{
"errorMessage": {
"timestamp": "Mon Oct 13 12:01:57 CEST 2003",
"originator": "IAF 9.2",
"message": "Message describing error and location",
"location": {
"class": "org.frankframework.pipes.SwitchPipe",
"name": "ServiceSwitch"
},
"details": "Exception and stacktrace",
"params": {
"sampleParam": "paramValue",
"errorCode": 535
},
"originalMessage": {
"messageId": "...",
"receivedTime": "Mon Oct 27 12:10:18 CET 2003",
"message": "contents of message for which the error occurred"
}
}
}
- Author:
- Gerrit van Brakel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull Messageformat(@Nullable String errorMessage, @Nullable Throwable t, @Nullable HasName location, @Nullable Message originalMessage, @NonNull PipeLineSession session) Format the available parameters into an XML or JSON message.protected @Nullable StringgetErrorMessage(@Nullable String message, @Nullable Throwable t) protected final @Nullable StringgetMessageAsString(@Nullable Message originalMessage, @Nullable String messageId) Attempts to convert the originalMessage to a String.voidsetMessageFormat(@NonNull DocumentFormat messageFormat) Format the error message as XML or as JSON.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IScopeProvider
getConfigurationClassLoader
-
Constructor Details
-
ErrorMessageFormatter
public ErrorMessageFormatter()
-
-
Method Details
-
format
public @NonNull Message format(@Nullable String errorMessage, @Nullable Throwable t, @Nullable HasName location, @Nullable Message originalMessage, @NonNull PipeLineSession session) Format the available parameters into an XML or JSON message.
Override this method in subclasses to obtain the required behaviour.- Specified by:
formatin interfaceIErrorMessageFormatter
-
getMessageAsString
protected final @Nullable String getMessageAsString(@Nullable Message originalMessage, @Nullable String messageId) Attempts to convert the originalMessage to a String.
Returns NULL when the Message is null or empty.
Returns the entire Message when it's smaller thanMessage.MESSAGE_MAX_IN_MEMORY.
Returns a shortened Message roughly of lengthMessage.MESSAGE_MAX_IN_MEMORYsuffixed with `...(%d characters remaining)`.NB. Roughly because %d may be n characters long, which influences the lenght a tiny bit.
-
getErrorMessage
-
setMessageFormat
Format the error message as XML or as JSON.- Since:
- 9.2
- Default value
- XML
-