From 44d6a9d7c1a1beb05af64d4f1183af0d6fd84130 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Sat, 5 Nov 2016 18:31:26 +0100 Subject: [PATCH] Improve logging of IoTProvisioningManager --- .../provisioning/IoTProvisioningManager.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java index 349296379..2f4d855e9 100644 --- a/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java +++ b/smack-experimental/src/main/java/org/jivesoftware/smackx/iot/provisioning/IoTProvisioningManager.java @@ -122,7 +122,7 @@ public final class IoTProvisioningManager extends Manager { connection.addAsyncStanzaListener(new StanzaListener() { @Override public void processPacket(Stanza stanza) throws NotConnectedException, InterruptedException { - if (!isFromProvisioningService(stanza)) { + if (!isFromProvisioningService(stanza, true)) { return; } @@ -152,7 +152,7 @@ public final class IoTProvisioningManager extends Manager { final Friend friend = Friend.from(friendMessage); final BareJid friendJid = friend.getFriend(); - if (isFromProvisioningService(friendMessage)) { + if (isFromProvisioningService(friendMessage, false)) { // We received a recommendation from a provisioning server. // Notify the recommended friend that we will now accept his // friendship requests. @@ -178,6 +178,10 @@ public final class IoTProvisioningManager extends Manager { // the bare 'from' JID should be equals to the JID of the // recommended friend. if (!bareFrom.equals(friendJid)) { + LOGGER.log(Level.WARNING, + "Ignoring friendship recommendation " + friendMessage + + " because it does not recommend itself, but " + + friendJid + '.'); return; } @@ -191,7 +195,7 @@ public final class IoTProvisioningManager extends Manager { new AbstractIqRequestHandler(ClearCache.ELEMENT, ClearCache.NAMESPACE, Type.set, Mode.async) { @Override public IQ handleIQRequest(IQ iqRequest) { - if (!isFromProvisioningService(iqRequest)) { + if (!isFromProvisioningService(iqRequest, true)) { return null; } @@ -391,7 +395,7 @@ public final class IoTProvisioningManager extends Manager { return wasUnfriendedListeners.remove(wasUnfriendedListener); } - private boolean isFromProvisioningService(Stanza stanza) { + private boolean isFromProvisioningService(Stanza stanza, boolean log) { Jid provisioningServer; try { provisioningServer = getConfiguredProvisioningServer(); @@ -401,13 +405,18 @@ public final class IoTProvisioningManager extends Manager { return false; } if (provisioningServer == null) { - LOGGER.warning("Ignoring request '" + stanza - + "' because no provisioning server configured."); + if (log) { + LOGGER.warning("Ignoring request '" + stanza + + "' because no provisioning server configured."); + } return false; } if (!provisioningServer.equals(stanza.getFrom())) { - LOGGER.warning("Ignoring request '" + stanza + "' because not from provising server '" - + provisioningServer + "'."); + if (log) { + LOGGER.warning("Ignoring request '" + stanza + + "' because not from provising server '" + provisioningServer + + "'."); + } return false; } return true;