Reputation: 619
I am trying to save the exception stack trace to database for some monitoring purpose and i have below configuration but it only prints first line of exception message not the entire stack trace, what i am doing wrong here?
<int-jdbc:stored-proc-outbound-gateway
id="errorDBLogger"
data-source="dataSource"
request-channel="errorChannel"
reply-channel="errorSaverepply"
stored-procedure-name="some_SP "
ignore-column-meta-data="true">
<int-jdbc:sql-parameter-definition .....parameter mappings..
<int-jdbc:parameter name="errorMessage" expression="payload"/>
</int-jdbc:stored-proc-outbound-gateway>
Also i will like default error handling mechanism to remain unaffected as i also have logger configured to email errros which i want to keep as it is, if you could reply in that scenario please. Thanks
Upvotes: 0
Views: 697
Reputation: 174574
The payload is an Exception
and Throwable.toString()
only includes the class name and message.
You will need a transformer or header-enricher upstream to convert the payload to the stack trace.
EDIT:
To get the stack trace you have to invoke Throwable.printStackTrace(pw)
; by default, Throwable.printStackTreace()
writes to stderr
so you need to create a PrintWriter
to pass in.
Something like...
private String getStackTraceAsString(Throwable cause) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter, true);
cause.printStackTrace(printWriter);
return stringWriter.getBuffer().toString();
}
Upvotes: 1