From dc256e12c096e1323efb8f032547e0861d5a66a4 Mon Sep 17 00:00:00 2001 From: andan67 Date: Sun, 3 Apr 2022 17:05:28 +0200 Subject: [PATCH] Added debug output --- .../binding/sony/internal/SonyAuthChecker.java | 12 ++++++++++++ .../binding/sony/internal/ircc/IrccProtocol.java | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/SonyAuthChecker.java b/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/SonyAuthChecker.java index c0dab6351f6ed..74b5859521f05 100644 --- a/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/SonyAuthChecker.java +++ b/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/SonyAuthChecker.java @@ -20,6 +20,8 @@ import org.openhab.binding.sony.internal.scalarweb.ScalarWebConstants; import org.openhab.binding.sony.internal.transports.SonyTransport; import org.openhab.binding.sony.internal.transports.TransportOptionHeader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * This class contains the logic to determine if an authorization call is needed (via {@link SonyAuth}) @@ -28,6 +30,10 @@ */ @NonNullByDefault public class SonyAuthChecker { + + /** The logger */ + private final Logger logger = LoggerFactory.getLogger(SonyAuthChecker.class); + /** The transport to use for check authorization */ private final SonyTransport transport; @@ -69,8 +75,10 @@ public CheckResult checkResult(final CheckResultCallback callback) { final TransportOptionHeader authHeader = new TransportOptionHeader( NetUtil.createAccessCodeHeader(localAccessCode)); try { + logger.debug("localAccessCode: '{}'", localAccessCode); transport.setOption(authHeader); if (AccessResult.OK.equals(callback.checkResult())) { + logger.debug("checkResult: '{}'", CheckResult.OK_HEADER.getCode()); return CheckResult.OK_HEADER; } } finally { @@ -81,16 +89,20 @@ public CheckResult checkResult(final CheckResultCallback callback) { // If we made it here - we are likely not header based but cookie based (or we are not even authenticated) // Attempt the check result without the auth header and return OK_COOKIE is good final AccessResult res = callback.checkResult(); + logger.debug("res: '{}'", res.getCode()); if (res == null) { + logger.debug("checkResult: '{}'", CheckResult.OTHER); return new CheckResult(CheckResult.OTHER, "Check result returned null"); } if (AccessResult.OK.equals(res)) { + logger.debug("checkResult: '{}'", CheckResult.OK_COOKIE.getCode()); return CheckResult.OK_COOKIE; } // We aren't either cookie or header based - return the results (likely needs pairing or the screen is off or // not on the main screen) + logger.debug("checkResult: '{}'", new CheckResult(res).getCode()); return new CheckResult(res); } diff --git a/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/ircc/IrccProtocol.java b/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/ircc/IrccProtocol.java index f608a7192e3fd..a5c923c290ebc 100644 --- a/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/ircc/IrccProtocol.java +++ b/bundles/org.openhab.binding.sony/src/main/java/org/openhab/binding/sony/internal/ircc/IrccProtocol.java @@ -163,10 +163,11 @@ T getCallback() { */ @Nullable LoginUnsuccessfulResponse login() throws IOException { + logger.debug("Starting ircc login..."); transport.setOption(TransportOptionAutoAuth.FALSE); final String accessCode = config.getAccessCode(); - + logger.debug("accessCode = '{}'", SonyUtil.defaultIfEmpty(accessCode, "")); final SonyAuthChecker authChecker = new SonyAuthChecker(transport, accessCode); final CheckResult checkResult = authChecker.checkResult(() -> { // To check our authorization, we execute a non-existent command. @@ -176,8 +177,10 @@ LoginUnsuccessfulResponse login() throws IOException { // If we have 200 (good) or 500 (command not found), we return OK // If we have 403 (unauthorized) or 503 (service not available), we need pairing HttpResponse status = irccClient.executeSoap(transport, "nonexistentcommand"); + logger.debug("Response status of calling non existing command: '{}'", status.getHttpCode()); if (status.getHttpCode() == HttpStatus.OK_200) { status = getStatus(); + logger.debug("Response status of calling ircc status: '{}'", status.getHttpCode()); } if (status.getHttpCode() == HttpStatus.OK_200 @@ -190,6 +193,7 @@ LoginUnsuccessfulResponse login() throws IOException { } return new AccessResult(status); }); + logger.debug("checkResult: '{}'", checkResult.getCode()); if (CheckResult.OK_HEADER.equals(checkResult)) { if (accessCode == null || accessCode.isEmpty()) { @@ -200,9 +204,11 @@ LoginUnsuccessfulResponse login() throws IOException { return new LoginUnsuccessfulResponse(ThingStatusDetail.CONFIGURATION_ERROR, "Access code cannot be blank"); } else { + logger.debug("setup header auth"); SonyAuth.setupHeader(accessCode, transport); } } else if (CheckResult.OK_COOKIE.equals(checkResult)) { + logger.debug("setup cookie auth"); SonyAuth.setupCookie(transport); } else if (AccessResult.NEEDSPAIRING.equals(checkResult)) { if (accessCode == null || accessCode.isEmpty()) { @@ -219,6 +225,7 @@ LoginUnsuccessfulResponse login() throws IOException { } } else { final AccessResult resp = sonyAuth.registerRenewal(transport); + logger.debug("register renewal"); if (AccessResult.OK.equals(resp)) { SonyAuth.setupCookie(transport); } else {