Added parsed received segments to MessageLog
This commit is contained in:
parent
3d385b5bdf
commit
d8b0c89be7
|
@ -12,6 +12,7 @@ import net.dankito.banking.fints.webclient.IWebClient
|
|||
import net.dankito.banking.fints.webclient.KtorWebClient
|
||||
import net.dankito.banking.fints.webclient.WebClientResponse
|
||||
import net.dankito.banking.fints.extensions.getAllExceptionMessagesJoined
|
||||
import net.dankito.banking.fints.response.segments.ReceivedSegment
|
||||
|
||||
|
||||
open class RequestExecutor(
|
||||
|
@ -104,9 +105,11 @@ open class RequestExecutor(
|
|||
try {
|
||||
val decodedResponse = decodeBase64Response(responseBody)
|
||||
|
||||
addMessageLog(context, MessageLogEntryType.Received, decodedResponse)
|
||||
val parsedResponse = context.responseParser.parse(decodedResponse)
|
||||
|
||||
return context.responseParser.parse(decodedResponse)
|
||||
addMessageLog(context, MessageLogEntryType.Received, decodedResponse, parsedResponse.receivedSegments)
|
||||
|
||||
return parsedResponse
|
||||
} catch (e: Exception) {
|
||||
logError(context, "Could not decode responseBody:\r\n'$responseBody'", e)
|
||||
|
||||
|
@ -164,8 +167,8 @@ open class RequestExecutor(
|
|||
}
|
||||
|
||||
|
||||
protected open fun addMessageLog(context: JobContext, type: MessageLogEntryType, message: String) {
|
||||
context.addMessageLog(type, message)
|
||||
protected open fun addMessageLog(context: JobContext, type: MessageLogEntryType, message: String, parsedSegments: List<ReceivedSegment> = emptyList()) {
|
||||
context.addMessageLog(type, message, parsedSegments)
|
||||
}
|
||||
|
||||
protected open fun logError(context: JobContext, message: String, e: Exception?) {
|
||||
|
|
|
@ -10,6 +10,7 @@ import net.dankito.banking.fints.model.MessageLogEntryType
|
|||
import net.dankito.banking.fints.extensions.getInnerException
|
||||
import net.dankito.banking.fints.extensions.nthIndexOf
|
||||
import net.dankito.banking.fints.extensions.toStringWithMinDigits
|
||||
import net.dankito.banking.fints.response.segments.ReceivedSegment
|
||||
import net.dankito.banking.fints.util.FinTsUtils
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
|
@ -37,7 +38,7 @@ open class MessageLogCollector(
|
|||
// in either case remove sensitive data after response is parsed as otherwise some information like account holder name and accounts may is not set yet on BankData
|
||||
open val messageLog: List<MessageLogEntry>
|
||||
// safe CPU cycles by only formatting and removing sensitive data if messageLog is really requested
|
||||
get() = _messageLog.map { MessageLogEntry(it.type, it.context, it.messageTrace, createMessageForLog(it), it.error, it.time) }
|
||||
get() = _messageLog.map { MessageLogEntry(it.type, it.context, it.messageTrace, createMessageForLog(it), it.error, it.parsedSegments, it.time) }
|
||||
|
||||
private fun createMessageForLog(logEntry: MessageLogEntry): String {
|
||||
val message = if (logEntry.type == MessageLogEntryType.Error) {
|
||||
|
@ -54,7 +55,7 @@ open class MessageLogCollector(
|
|||
}
|
||||
|
||||
|
||||
open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext) {
|
||||
open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext, parsedSegments: List<ReceivedSegment> = emptyList()) {
|
||||
val messageTrace = createMessageTraceString(type, context)
|
||||
|
||||
val prettyPrintMessage = if (options.collectMessageLog || options.fireCallbackOnMessageLogs || log.isDebugEnabled) { // only use CPU cycles if message will ever be used / displayed
|
||||
|
@ -65,7 +66,7 @@ open class MessageLogCollector(
|
|||
|
||||
log.debug { "$messageTrace\n$prettyPrintMessage" }
|
||||
|
||||
addMessageLogEntry(type, context, messageTrace, prettyPrintMessage)
|
||||
addMessageLogEntry(type, context, messageTrace, prettyPrintMessage, null, parsedSegments)
|
||||
}
|
||||
|
||||
open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Exception? = null) {
|
||||
|
@ -77,9 +78,9 @@ open class MessageLogCollector(
|
|||
addMessageLogEntry(type, context, messageTrace, message, e)
|
||||
}
|
||||
|
||||
protected open fun addMessageLogEntry(type: MessageLogEntryType, context: MessageContext, messageTrace: String, message: String, error: Throwable? = null) {
|
||||
protected open fun addMessageLogEntry(type: MessageLogEntryType, context: MessageContext, messageTrace: String, message: String, error: Throwable? = null, parsedSegments: List<ReceivedSegment> = emptyList()) {
|
||||
if (options.collectMessageLog || options.fireCallbackOnMessageLogs) {
|
||||
val newEntry = MessageLogEntry(type, context, messageTrace, message, error)
|
||||
val newEntry = MessageLogEntry(type, context, messageTrace, message, error, parsedSegments)
|
||||
|
||||
if (options.collectMessageLog) {
|
||||
_messageLog.add(newEntry)
|
||||
|
|
|
@ -9,6 +9,7 @@ import net.dankito.banking.fints.log.MessageLogCollector
|
|||
import net.dankito.banking.fints.messages.datenelemente.implementierte.signatur.VersionDesSicherheitsverfahrens
|
||||
import net.dankito.banking.fints.response.BankResponse
|
||||
import net.dankito.banking.fints.response.ResponseParser
|
||||
import net.dankito.banking.fints.response.segments.ReceivedSegment
|
||||
import net.dankito.banking.fints.transactions.IAccountTransactionsParser
|
||||
import net.dankito.banking.fints.transactions.Mt940AccountTransactionsParser
|
||||
import net.dankito.banking.fints.transactions.mt940.Mt940Parser
|
||||
|
@ -72,8 +73,8 @@ open class JobContext(
|
|||
}
|
||||
|
||||
|
||||
open fun addMessageLog(type: MessageLogEntryType, message: String) {
|
||||
messageLogCollector.addMessageLog(type, message, createMessageContext())
|
||||
open fun addMessageLog(type: MessageLogEntryType, message: String, parsedSegments: List<ReceivedSegment> = emptyList()) {
|
||||
messageLogCollector.addMessageLog(type, message, createMessageContext(), parsedSegments)
|
||||
}
|
||||
|
||||
override fun logError(loggingClass: KClass<*>, message: String, e: Exception?) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.dankito.banking.fints.model
|
|||
import kotlinx.datetime.Clock
|
||||
import kotlinx.datetime.Instant
|
||||
import net.dankito.banking.fints.log.MessageContext
|
||||
import net.dankito.banking.fints.response.segments.ReceivedSegment
|
||||
|
||||
|
||||
open class MessageLogEntry(
|
||||
|
@ -11,6 +12,12 @@ open class MessageLogEntry(
|
|||
open val messageTrace: String,
|
||||
open val message: String,
|
||||
open val error: Throwable? = null,
|
||||
/**
|
||||
* Parsed received segments.
|
||||
*
|
||||
* Is only set if [type] is set to [MessageLogEntryType.Received] and response parsing was successful.
|
||||
*/
|
||||
open val parsedSegments: List<ReceivedSegment> = emptyList(),
|
||||
open val time: Instant = Clock.System.now()
|
||||
) {
|
||||
|
||||
|
|
Loading…
Reference in New Issue