Added messageLogAdded() to FinTsClientCallback to get instantly notified of sent, received and error messages
This commit is contained in:
parent
da50b72898
commit
850beb8421
|
@ -27,4 +27,11 @@ interface FinTsClientCallback {
|
||||||
*/
|
*/
|
||||||
suspend fun enterTanGeneratorAtc(bank: BankData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult
|
suspend fun enterTanGeneratorAtc(bank: BankData, tanMedium: TanGeneratorTanMedium): EnterTanGeneratorAtcResult
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets fired when a FinTS message get sent to bank server, a FinTS message is received from bank server or an error occurred.
|
||||||
|
*
|
||||||
|
* Be aware, in order that this message gets fired [net.dankito.banking.fints.config.FinTsClientOptions.fireCallbackOnMessageLogs] has to be set to true.
|
||||||
|
*/
|
||||||
|
fun messageLogAdded(messageLogEntry: MessageLogEntry)
|
||||||
|
|
||||||
}
|
}
|
|
@ -18,4 +18,8 @@ open class NoOpFinTsClientCallback : FinTsClientCallback {
|
||||||
return EnterTanGeneratorAtcResult.userDidNotEnterAtc()
|
return EnterTanGeneratorAtcResult.userDidNotEnterAtc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun messageLogAdded(messageLogEntry: MessageLogEntry) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -5,14 +5,15 @@ import net.dankito.banking.fints.model.*
|
||||||
|
|
||||||
|
|
||||||
open class SimpleFinTsClientCallback(
|
open class SimpleFinTsClientCallback(
|
||||||
protected open val enterTan: ((tanChallenge: TanChallenge) -> Unit)? = null,
|
protected open val askUserForTanMethod: ((supportedTanMethods: List<TanMethod>, suggestedTanMethod: TanMethod?) -> TanMethod?)? = null,
|
||||||
|
protected open val messageLogAdded: ((MessageLogEntry) -> Unit)? = null,
|
||||||
protected open val enterTanGeneratorAtc: ((bank: BankData, tanMedium: TanGeneratorTanMedium) -> EnterTanGeneratorAtcResult)? = null,
|
protected open val enterTanGeneratorAtc: ((bank: BankData, tanMedium: TanGeneratorTanMedium) -> EnterTanGeneratorAtcResult)? = null,
|
||||||
protected open val askUserForTanMethod: ((supportedTanMethods: List<TanMethod>, suggestedTanMethod: TanMethod?) -> TanMethod?)? = null
|
protected open val enterTan: ((tanChallenge: TanChallenge) -> Unit)? = null
|
||||||
) : FinTsClientCallback {
|
) : FinTsClientCallback {
|
||||||
|
|
||||||
constructor() : this(null) // Swift does not support default parameter values -> create constructor overloads
|
constructor() : this(null as ((tanChallenge: TanChallenge) -> Unit)?) // Swift does not support default parameter values -> create constructor overloads
|
||||||
|
|
||||||
constructor(enterTan: ((tanChallenge: TanChallenge) -> Unit)?) : this(enterTan, null)
|
constructor(enterTan: ((tanChallenge: TanChallenge) -> Unit)?) : this(null, null, null, enterTan)
|
||||||
|
|
||||||
|
|
||||||
override suspend fun askUserForTanMethod(supportedTanMethods: List<TanMethod>, suggestedTanMethod: TanMethod?): TanMethod? {
|
override suspend fun askUserForTanMethod(supportedTanMethods: List<TanMethod>, suggestedTanMethod: TanMethod?): TanMethod? {
|
||||||
|
@ -28,4 +29,8 @@ open class SimpleFinTsClientCallback(
|
||||||
return enterTanGeneratorAtc?.invoke(bank, tanMedium) ?: EnterTanGeneratorAtcResult.userDidNotEnterAtc()
|
return enterTanGeneratorAtc?.invoke(bank, tanMedium) ?: EnterTanGeneratorAtcResult.userDidNotEnterAtc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun messageLogAdded(messageLogEntry: MessageLogEntry) {
|
||||||
|
messageLogAdded?.invoke(messageLogEntry)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,6 +3,19 @@ package net.dankito.banking.fints.config
|
||||||
import net.dankito.banking.fints.model.ProductData
|
import net.dankito.banking.fints.model.ProductData
|
||||||
|
|
||||||
data class FinTsClientOptions(
|
data class FinTsClientOptions(
|
||||||
|
/**
|
||||||
|
* If set to true then [net.dankito.banking.fints.callback.FinTsClientCallback.messageLogAdded] get fired when a
|
||||||
|
* FinTS message get sent to bank server, a FinTS message is received from bank server or an error occurred.
|
||||||
|
*
|
||||||
|
* Defaults to false.
|
||||||
|
*/
|
||||||
|
val fireCallbackOnMessageLogs: Boolean = false,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If sensitive data like user name, password, login name should be removed from FinTS messages before being logged.
|
||||||
|
*
|
||||||
|
* Defaults to true.
|
||||||
|
*/
|
||||||
val removeSensitiveDataFromMessageLog: Boolean = true,
|
val removeSensitiveDataFromMessageLog: Boolean = true,
|
||||||
val version: String = "1.0.0", // TODO: get version dynamically
|
val version: String = "1.0.0", // TODO: get version dynamically
|
||||||
val productName: String = "15E53C26816138699C7B6A3E8"
|
val productName: String = "15E53C26816138699C7B6A3E8"
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.dankito.banking.fints.log
|
||||||
|
|
||||||
import net.codinux.log.LoggerFactory
|
import net.codinux.log.LoggerFactory
|
||||||
import net.codinux.log.logger
|
import net.codinux.log.logger
|
||||||
|
import net.dankito.banking.fints.callback.FinTsClientCallback
|
||||||
import net.dankito.banking.fints.config.FinTsClientOptions
|
import net.dankito.banking.fints.config.FinTsClientOptions
|
||||||
import net.dankito.banking.fints.model.BankData
|
import net.dankito.banking.fints.model.BankData
|
||||||
import net.dankito.banking.fints.model.MessageLogEntry
|
import net.dankito.banking.fints.model.MessageLogEntry
|
||||||
|
@ -14,6 +15,7 @@ import kotlin.reflect.KClass
|
||||||
|
|
||||||
|
|
||||||
open class MessageLogCollector(
|
open class MessageLogCollector(
|
||||||
|
private val callback: FinTsClientCallback,
|
||||||
private val options: FinTsClientOptions = FinTsClientOptions(),
|
private val options: FinTsClientOptions = FinTsClientOptions(),
|
||||||
private val finTsUtils: FinTsUtils = FinTsUtils()
|
private val finTsUtils: FinTsUtils = FinTsUtils()
|
||||||
) {
|
) {
|
||||||
|
@ -55,9 +57,9 @@ open class MessageLogCollector(
|
||||||
open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext) {
|
open fun addMessageLog(type: MessageLogEntryType, message: String, context: MessageContext) {
|
||||||
val messageTrace = createMessageTraceString(type, context)
|
val messageTrace = createMessageTraceString(type, context)
|
||||||
|
|
||||||
addMessageLogEntry(type, context, messageTrace, message)
|
|
||||||
|
|
||||||
log.debug { "$messageTrace\n${prettyPrintFinTsMessage(message)}" }
|
log.debug { "$messageTrace\n${prettyPrintFinTsMessage(message)}" }
|
||||||
|
|
||||||
|
addMessageLogEntry(type, context, messageTrace, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Exception? = null) {
|
open fun logError(loggingClass: KClass<*>, message: String, context: MessageContext, e: Exception? = null) {
|
||||||
|
@ -70,7 +72,14 @@ open class MessageLogCollector(
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
_messageLog.add(MessageLogEntry(type, context, messageTrace, message, error))
|
val newEntry = MessageLogEntry(type, context, messageTrace, message, error)
|
||||||
|
|
||||||
|
_messageLog.add(newEntry)
|
||||||
|
|
||||||
|
if (options.fireCallbackOnMessageLogs) {
|
||||||
|
// TODO: pretty print message
|
||||||
|
callback.messageLogAdded(newEntry)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ open class JobContext(
|
||||||
* Only set if the current context is for a specific account (like get account's transactions).
|
* Only set if the current context is for a specific account (like get account's transactions).
|
||||||
*/
|
*/
|
||||||
open val account: AccountData? = null,
|
open val account: AccountData? = null,
|
||||||
protected open val messageLogCollector: MessageLogCollector = MessageLogCollector(config.options)
|
protected open val messageLogCollector: MessageLogCollector = MessageLogCollector(callback, config.options)
|
||||||
) : MessageBaseData(bank, config.options.product), IMessageLogAppender {
|
) : MessageBaseData(bank, config.options.product), IMessageLogAppender {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
Loading…
Reference in New Issue