diff --git a/src/main/kotlin/de/gmuth/ipp/client/IppClient.kt b/src/main/kotlin/de/gmuth/ipp/client/IppClient.kt index fcd7e1df..d516d528 100644 --- a/src/main/kotlin/de/gmuth/ipp/client/IppClient.kt +++ b/src/main/kotlin/de/gmuth/ipp/client/IppClient.kt @@ -33,7 +33,7 @@ open class IppClient(val config: IppConfig = IppConfig()) : IppExchange { var responseInterceptor: IppResponseInterceptor? = null var saveMessages: Boolean = false var saveMessagesDirectory = File("ipp-messages") - var onExceptionSaveMessages: Boolean = false + var onExceptionSaveMessages: Boolean = true var throwWhenNotSuccessful: Boolean = true var disconnectAfterHttpPost: Boolean = false @@ -76,7 +76,7 @@ open class IppClient(val config: IppConfig = IppConfig()) : IppExchange { logger.fine { "Send '$operation' request to $printerOrJobUri" } httpPost(toHttpUri(printerOrJobUri), request).also { logger.finer { "Req #${request.requestId} @${printerOrJobUri.host}: $request => $it" } - if(logger.isLoggable(FINEST)) { + if (logger.isLoggable(FINEST)) { request.log(logger, FINEST, ">>> ") it.log(logger, FINEST, "<<< ") } @@ -129,10 +129,13 @@ open class IppClient(val config: IppConfig = IppConfig()) : IppExchange { if (containsGroup(Unsupported)) unsupportedGroup.values.forEach { logger.warning() { "Unsupported: $it" } } if (!isSuccessful()) { IppRegistrationsSection2.validate(request) - if (throwWhenNotSuccessful) { - throw if (status == ClientErrorNotFound) ClientErrorNotFoundException(request, response) + val exception = + if (status == ClientErrorNotFound) ClientErrorNotFoundException(request, response) else IppOperationException(request, response) - } + if (onExceptionSaveMessages) + exception.saveMessages("${request.operation}_${status}_${request.requestId}") + if (throwWhenNotSuccessful) + throw exception } } diff --git a/src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt b/src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt index 5861eafd..9c5903d6 100644 --- a/src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt +++ b/src/main/kotlin/de/gmuth/ipp/client/IppPrinter.kt @@ -477,9 +477,9 @@ class IppPrinter( } fun checkNotifyEvents(notifyEvents: Collection?) = notifyEvents?.let { + if (!attributes.containsKey("notify-events-supported")) + throw IppException("Printer does not support event notifications.") if (it.isNotEmpty() && it.first() != "all") { - if (!attributes.containsKey("notify-events-supported")) - throw IppException("Printer does not support request parameter 'notifyEvents'.") checkIfValueIsSupported("notify-events", it, true) } } diff --git a/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt b/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt index 4133ea62..3bdd424f 100644 --- a/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt +++ b/src/main/kotlin/de/gmuth/ipp/core/IppMessage.kt @@ -1,7 +1,7 @@ package de.gmuth.ipp.core /** - * Copyright (c) 2020-2023 Gerhard Muth + * Copyright (c) 2020-2024 Gerhard Muth */ import de.gmuth.ipp.core.IppTag.* @@ -166,7 +166,7 @@ abstract class IppMessage() { throw IppException("No raw bytes to save. You must call read/decode or write/encode before.") } else { file.writeBytes(rawBytes!!) - logger.fine { "Saved ${file.path} (${file.length()} bytes)" } + logger.info { "Saved ${file.path} (${file.length()} bytes)" } } fun write(bufferedWriter: BufferedWriter, title: String? = null) {