From 8594d902f49bd732173d1dcbe642ce5ebeb75582 Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sat, 14 Jan 2023 21:07:28 +0100 Subject: [PATCH 1/8] Add null annotations Signed-off-by: lsiepel --- .../xmppclient/internal/XMPPClient.java | 60 ++++++++++++------- .../internal/XMPPClientBindingConstants.java | 2 + .../internal/XMPPClientHandlerFactory.java | 5 +- .../internal/action/XMPPActions.java | 10 +--- .../handler/PublishTriggerChannel.java | 2 + .../handler/XMPPClientConfiguration.java | 8 +++ .../internal/handler/XMPPClientHandler.java | 15 +++-- .../handler/XMPPClientMessageSubscriber.java | 3 + 8 files changed, 67 insertions(+), 38 deletions(-) diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java index ec739938b903c..5f1869a744da6 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java @@ -18,6 +18,8 @@ import java.util.HashSet; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.jivesoftware.smack.AbstractXMPPConnection; import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.ReconnectionManager; @@ -45,11 +47,12 @@ * * @author Pavel Gololobov - Initial contribution */ +@NonNullByDefault public class XMPPClient implements IncomingChatMessageListener, ConnectionListener { private final Logger logger = LoggerFactory.getLogger(XMPPClient.class); - private AbstractXMPPConnection connection; - private ChatManager chatManager; - private HttpFileUploadManager httpFileUploadManager; + private @Nullable AbstractXMPPConnection connection; + private @Nullable ChatManager chatManager; + private @Nullable HttpFileUploadManager httpFileUploadManager; private Set subscribers = new HashSet<>(); public void subscribe(XMPPClientMessageSubscriber channel) { @@ -66,7 +69,7 @@ public void connect(String host, Integer port, String login, String domain, Stri throws XMPPException, SmackException, IOException { disconnect(); String serverHost = domain; - if ((host != null) && !host.isEmpty()) { + if (!host.isBlank()) { serverHost = host; } @@ -77,10 +80,11 @@ public void connect(String host, Integer port, String login, String domain, Stri .setXmppDomain(domain) // .build(); - connection = new XMPPTCPConnection(config); - connection.addConnectionListener(this); + AbstractXMPPConnection connectionLocal = new XMPPTCPConnection(config); + connection = connectionLocal; + connectionLocal.addConnectionListener(this); - ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor(connection); + ReconnectionManager reconnectionManager = ReconnectionManager.getInstanceFor(connectionLocal); reconnectionManager.enableAutomaticReconnection(); Identity identity = new Identity("client", "openHAB", "bot"); @@ -88,18 +92,20 @@ public void connect(String host, Integer port, String login, String domain, Stri sdm.setIdentity(identity); try { - connection.connect().login(); + connectionLocal.connect().login(); } catch (InterruptedException ex) { } - chatManager = ChatManager.getInstanceFor(connection); - chatManager.addIncomingListener(this); + ChatManager chatManagerLocal = ChatManager.getInstanceFor(connection); + chatManagerLocal.addIncomingListener(this); + chatManager = chatManagerLocal; httpFileUploadManager = HttpFileUploadManager.getInstanceFor(connection); } public void disconnect() { - if (connection != null) { - connection.disconnect(); + AbstractXMPPConnection connectionLocal = connection; + if (connectionLocal != null) { + connectionLocal.disconnect(); } } @@ -108,13 +114,14 @@ public void sendMessage(String to, String message) { logger.warn("XMPP connection is null"); return; } - if (chatManager == null) { + ChatManager chatManagerLocal = chatManager; + if (chatManagerLocal == null) { logger.warn("XMPP chatManager is null"); return; } try { EntityBareJid jid = JidCreate.entityBareFrom(to); - Chat chat = chatManager.chatWith(jid); + Chat chat = chatManagerLocal.chatWith(jid); chat.send(message); } catch (XmppStringprepException | SmackException.NotConnectedException | InterruptedException e) { logger.info("XMPP message sending error", e); @@ -126,12 +133,13 @@ public void sendImageByHTTP(String to, String filename) { logger.warn("XMPP connection is null"); return; } - if (httpFileUploadManager == null) { + HttpFileUploadManager httpFileUploadManagerLocal = httpFileUploadManager; + if (httpFileUploadManagerLocal == null) { logger.warn("XMPP httpFileUploadManager is null"); return; } try { - URL u = httpFileUploadManager.uploadFile(new File(filename)); + URL u = httpFileUploadManagerLocal.uploadFile(new File(filename)); // Use Stanza oob this.sendMessage(to, u.toString()); } catch (XMPPException.XMPPErrorException | SmackException | InterruptedException | IOException e) { @@ -140,7 +148,12 @@ public void sendImageByHTTP(String to, String filename) { } @Override - public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) { + public void newIncomingMessage(@Nullable EntityBareJid from, @Nullable Message message, @Nullable Chat chat) { + if (from == null || message == null || chat == null) { + logger.debug("newIncomingMessage with atleast one null argument, should not happen"); + return; + } + logger.debug("XMPP {} says {}", from.asBareJid().toString(), message.getBody()); for (XMPPClientMessageSubscriber subscriber : subscribers) { logger.debug("Push to subscriber {}", subscriber.getName()); @@ -149,12 +162,12 @@ public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) { } @Override - public void connected(XMPPConnection connection) { + public void connected(@Nullable XMPPConnection connection) { logger.debug("Connected to XMPP server."); } @Override - public void authenticated(XMPPConnection connection, boolean resumed) { + public void authenticated(@Nullable XMPPConnection connection, boolean resumed) { logger.debug("Authenticated to XMPP server."); } @@ -164,12 +177,13 @@ public void connectionClosed() { } @Override - public void connectionClosedOnError(Exception e) { + public void connectionClosedOnError(@Nullable Exception e) { logger.debug("Connection to XMPP server was lost."); - if (connection != null) { - connection.disconnect(); + AbstractXMPPConnection connectionLocal = connection; + if (connectionLocal != null) { + connectionLocal.disconnect(); try { - connection.connect().login(); + connectionLocal.connect().login(); } catch (SmackException | IOException | XMPPException | InterruptedException ex) { logger.info("XMPP connection error", ex); } diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientBindingConstants.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientBindingConstants.java index 3d99777171fd4..329e13fadda5a 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientBindingConstants.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientBindingConstants.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.xmppclient.internal; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.core.thing.ThingTypeUID; /** @@ -20,6 +21,7 @@ * * @author Pavel Gololobov - Initial contribution */ +@NonNullByDefault public class XMPPClientBindingConstants { private static final String BINDING_ID = "xmppclient"; diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java index db5283895bca8..e88ea97e98a10 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClientHandlerFactory.java @@ -15,6 +15,8 @@ import java.util.Collections; import java.util.Set; +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; import org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Thing; @@ -30,6 +32,7 @@ * * @author Pavel Gololobov - Initial contribution */ +@NonNullByDefault @Component(configurationPid = "binding.xmppclient", service = ThingHandlerFactory.class) public class XMPPClientHandlerFactory extends BaseThingHandlerFactory { private static final Set SUPPORTED_THING_TYPES_UIDS = Collections @@ -41,7 +44,7 @@ public boolean supportsThingType(ThingTypeUID thingTypeUID) { } @Override - protected ThingHandler createHandler(Thing thing) { + protected @Nullable ThingHandler createHandler(Thing thing) { ThingTypeUID thingTypeUID = thing.getThingTypeUID(); if (thingTypeUID.equals(XMPPClientBindingConstants.BRIDGE_TYPE_XMPP)) { diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java index 6976178eb7031..00e319507c93c 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java @@ -32,7 +32,7 @@ @ThingActionsScope(name = "xmppclient") @NonNullByDefault public class XMPPActions implements ThingActions { - private static final Logger logger = LoggerFactory.getLogger(XMPPActions.class); + private final Logger logger = LoggerFactory.getLogger(XMPPActions.class); private @Nullable XMPPClientHandler handler; @Override @@ -55,10 +55,6 @@ public void publishXMPP(@ActionInput(name = "to", label = "To", description = "S } XMPPClient connection = clientHandler.getXMPPClient(); - if (connection == null) { - logger.warn("XMPP ThingHandler connection is null"); - return; - } if ((to == null) || (text == null)) { logger.info("Skipping XMPP messaging to {} value {}", to, text); return; @@ -77,10 +73,6 @@ public void publishXMPPImageByHTTP( } XMPPClient connection = clientHandler.getXMPPClient(); - if (connection == null) { - logger.warn("XMPP ThingHandler connection is null"); - return; - } if ((to == null) || (filename == null)) { logger.warn("Skipping XMPP messaging to {} value {}", to, filename); return; diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java index bc73a2f87eedb..76b7a3ac37d66 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java @@ -12,6 +12,7 @@ */ package org.openhab.binding.xmppclient.internal.handler; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.openhab.binding.xmppclient.internal.XMPPClient; import org.openhab.core.thing.ChannelUID; @@ -21,6 +22,7 @@ * * @author Pavel Gololobov - Initial contribution */ +@NonNullByDefault public class PublishTriggerChannel implements XMPPClientMessageSubscriber { private final XMPPClient connection; private final PublishTriggerChannelConfig config; diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java index 74285c4a9145a..5045e102dbf2e 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java @@ -27,4 +27,12 @@ public class XMPPClientConfiguration { public String username = ""; public String password = ""; public String domain = ""; + + public boolean isValid() { + String hostLocal = host; + if (hostLocal == null) { + return false; + } + return !hostLocal.isBlank(); + } } diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java index d28b9d63f86b9..308f7d24601e7 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java @@ -19,6 +19,7 @@ import java.util.Map; import java.util.concurrent.TimeUnit; +import org.eclipse.jdt.annotation.NonNullByDefault; import org.jivesoftware.smack.SmackException; import org.jivesoftware.smack.XMPPException; import org.openhab.binding.xmppclient.internal.XMPPClient; @@ -40,15 +41,15 @@ * * @author Pavel Gololobov - Initial contribution */ - +@NonNullByDefault public class XMPPClientHandler extends BaseBridgeHandler { private final Logger logger = LoggerFactory.getLogger(XMPPClientHandler.class); private XMPPClient xmppClient; - private XMPPClientConfiguration config; private final Map channelStateByChannelUID = new HashMap<>(); public XMPPClientHandler(Bridge thing) { super(thing); + xmppClient = new XMPPClient(); } public XMPPClient getXMPPClient() { @@ -85,10 +86,14 @@ public void dispose() { } private void doConnect() { - config = getConfigAs(XMPPClientConfiguration.class); - xmppClient = new XMPPClient(); + XMPPClientConfiguration config = getConfigAs(XMPPClientConfiguration.class); + if (!config.isValid()) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Please check host configuration"); + return; + } + String host = config.host; try { - xmppClient.connect(config.host, config.port, config.username, config.domain, config.password); + xmppClient.connect(host != null ? host : "", config.port, config.username, config.domain, config.password); } catch (SmackException | IOException | XMPPException e) { logger.info("XMPP connection error", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientMessageSubscriber.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientMessageSubscriber.java index 1cb66a163fc79..3fe0a1e226ffd 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientMessageSubscriber.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientMessageSubscriber.java @@ -12,11 +12,14 @@ */ package org.openhab.binding.xmppclient.internal.handler; +import org.eclipse.jdt.annotation.NonNullByDefault; + /** * Subscriber interface * * @author Pavel Gololobov - Initial contribution */ +@NonNullByDefault public interface XMPPClientMessageSubscriber { public void processMessage(String from, String payload); From b480b5cefff15f3c41e93d2dd8aa351677b570d6 Mon Sep 17 00:00:00 2001 From: lsiepel Date: Sat, 14 Jan 2023 21:57:22 +0100 Subject: [PATCH 2/8] Introduce re-connect logic Signed-off-by: lsiepel --- .../xmppclient/internal/XMPPClient.java | 55 ++++++++++++++++--- 1 file changed, 46 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java index 5f1869a744da6..199f4399540bd 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java @@ -17,6 +17,9 @@ import java.net.URL; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; @@ -39,6 +42,7 @@ import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.stringprep.XmppStringprepException; import org.openhab.binding.xmppclient.internal.handler.XMPPClientMessageSubscriber; +import org.openhab.core.common.ThreadPoolManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,14 +50,18 @@ * The {@link XMPPClient} is lib for handling XMPP connection and messaging * * @author Pavel Gololobov - Initial contribution + * @author Leo Siepel - Add reconnection logic */ @NonNullByDefault public class XMPPClient implements IncomingChatMessageListener, ConnectionListener { + private static final int CONNECTION_CHECK_INTERVAL = 180; private final Logger logger = LoggerFactory.getLogger(XMPPClient.class); private @Nullable AbstractXMPPConnection connection; private @Nullable ChatManager chatManager; private @Nullable HttpFileUploadManager httpFileUploadManager; private Set subscribers = new HashSet<>(); + private @Nullable ScheduledFuture connectionCheckJob; + protected final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("ConnectionCheck"); public void subscribe(XMPPClientMessageSubscriber channel) { logger.debug("Channel {} subscribed", channel.getName()); @@ -100,9 +108,46 @@ public void connect(String host, Integer port, String login, String domain, Stri chatManagerLocal.addIncomingListener(this); chatManager = chatManagerLocal; httpFileUploadManager = HttpFileUploadManager.getInstanceFor(connection); + + scheduleConnectionCheck(); + } + + private void checkAndReconnect() { + AbstractXMPPConnection connectionLocal = connection; + if (connectionLocal == null) { + logger.warn("XMPP connection is null, cannot automatic recover from this permanent failure"); + return; + } + + if (!connectionLocal.isConnected()) { + connectionLocal.disconnect(); + try { + connectionLocal.connect().login(); + } catch (SmackException | IOException | XMPPException | InterruptedException ex) { + logger.info("XMPP connection error", ex); + } + } + } + + private synchronized void scheduleConnectionCheck() { + if (this.connectionCheckJob == null) { + logger.debug("Scheduling connection check job every {}s", CONNECTION_CHECK_INTERVAL); + this.connectionCheckJob = scheduler.scheduleWithFixedDelay(this::checkAndReconnect, 0, + CONNECTION_CHECK_INTERVAL, TimeUnit.SECONDS); + } + } + + private synchronized void cancelConnectionCheck() { + ScheduledFuture connectionCheckJobLocal = connectionCheckJob; + if (connectionCheckJobLocal != null) { + logger.debug("Cancelling connection check job"); + connectionCheckJobLocal.cancel(true); + this.connectionCheckJob = null; + } } public void disconnect() { + cancelConnectionCheck(); AbstractXMPPConnection connectionLocal = connection; if (connectionLocal != null) { connectionLocal.disconnect(); @@ -179,14 +224,6 @@ public void connectionClosed() { @Override public void connectionClosedOnError(@Nullable Exception e) { logger.debug("Connection to XMPP server was lost."); - AbstractXMPPConnection connectionLocal = connection; - if (connectionLocal != null) { - connectionLocal.disconnect(); - try { - connectionLocal.connect().login(); - } catch (SmackException | IOException | XMPPException | InterruptedException ex) { - logger.info("XMPP connection error", ex); - } - } + checkAndReconnect(); } } From 20863089f76e6bd9d1f6e25522a6ab6de7c3967e Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Sat, 29 Jun 2024 23:29:20 +0200 Subject: [PATCH 3/8] Refactoring connection logic Signed-off-by: Leo Siepel --- .../internal/action/XMPPActions.java | 2 +- .../internal/{ => client}/XMPPClient.java | 109 +++++++----------- .../client/XMPPClientConfigException.java | 40 +++++++ .../client/XMPPClientEventlistener.java | 29 +++++ .../internal/client/XMPPClientException.java | 40 +++++++ .../handler/PublishTriggerChannel.java | 2 +- .../handler/XMPPClientConfiguration.java | 9 +- .../internal/handler/XMPPClientHandler.java | 38 ++++-- .../resources/OH-INF/thing/thing-types.xml | 13 +++ 9 files changed, 197 insertions(+), 85 deletions(-) rename bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/{ => client}/XMPPClient.java (66%) create mode 100644 bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientConfigException.java create mode 100644 bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java create mode 100644 bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientException.java diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java index cd2c355ac0202..cc6eb8e2c3adc 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java @@ -14,7 +14,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; -import org.openhab.binding.xmppclient.internal.XMPPClient; +import org.openhab.binding.xmppclient.internal.client.XMPPClient; import org.openhab.binding.xmppclient.internal.handler.XMPPClientHandler; import org.openhab.core.automation.annotation.ActionInput; import org.openhab.core.automation.annotation.RuleAction; diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClient.java similarity index 66% rename from bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java rename to bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClient.java index 88bc2323dc55c..00fe9567840c6 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/XMPPClient.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClient.java @@ -10,20 +10,19 @@ * * SPDX-License-Identifier: EPL-2.0 */ -package org.openhab.binding.xmppclient.internal; +package org.openhab.binding.xmppclient.internal.client; import java.io.File; import java.io.IOException; import java.net.URL; import java.util.HashSet; +import java.util.Objects; import java.util.Set; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; import org.jivesoftware.smack.AbstractXMPPConnection; +import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; import org.jivesoftware.smack.ConnectionListener; import org.jivesoftware.smack.ReconnectionManager; import org.jivesoftware.smack.SmackException; @@ -42,7 +41,6 @@ import org.jxmpp.jid.impl.JidCreate; import org.jxmpp.stringprep.XmppStringprepException; import org.openhab.binding.xmppclient.internal.handler.XMPPClientMessageSubscriber; -import org.openhab.core.common.ThreadPoolManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -54,14 +52,16 @@ */ @NonNullByDefault public class XMPPClient implements IncomingChatMessageListener, ConnectionListener { - private static final int CONNECTION_CHECK_INTERVAL = 180; private final Logger logger = LoggerFactory.getLogger(XMPPClient.class); private @Nullable AbstractXMPPConnection connection; private @Nullable ChatManager chatManager; private @Nullable HttpFileUploadManager httpFileUploadManager; private Set subscribers = new HashSet<>(); - private @Nullable ScheduledFuture connectionCheckJob; - protected final ScheduledExecutorService scheduler = ThreadPoolManager.getScheduledPool("ConnectionCheck"); + private final XMPPClientEventlistener eventListener; + + public XMPPClient(XMPPClientEventlistener eventListener) { + this.eventListener = eventListener; + } public void subscribe(XMPPClientMessageSubscriber channel) { logger.debug("Channel {} subscribed", channel.getName()); @@ -73,20 +73,26 @@ public void unsubscribe(XMPPClientMessageSubscriber channel) { subscribers.remove(channel); } - public void connect(String host, Integer port, String login, String domain, String password) - throws XMPPException, SmackException, IOException { + public void connect(String host, Integer port, String login, String domain, String password, + SecurityMode securityMode) throws XMPPClientConfigException, XMPPClientException { disconnect(); String serverHost = domain; if (!host.isBlank()) { serverHost = host; } - XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder() // - .setHost(serverHost) // - .setPort(port) // - .setUsernameAndPassword(login, password) // - .setXmppDomain(domain) // - .build(); + XMPPTCPConnectionConfiguration config; + try { + config = XMPPTCPConnectionConfiguration.builder() // + .setHost(serverHost) // + .setPort(port) // + .setUsernameAndPassword(login, password) // + .setXmppDomain(domain) // + .setSecurityMode(SecurityMode.disabled)// + .build(); + } catch (XmppStringprepException e) { + throw new XMPPClientConfigException(Objects.requireNonNullElse(e.getMessage(), "Unknown error message")); + } AbstractXMPPConnection connectionLocal = new XMPPTCPConnection(config); connection = connectionLocal; @@ -101,75 +107,41 @@ public void connect(String host, Integer port, String login, String domain, Stri try { connectionLocal.connect().login(); - } catch (InterruptedException ex) { + } catch (InterruptedException | XMPPException | SmackException | IOException e) { + throw new XMPPClientException(Objects.requireNonNullElse(e.getMessage(), "Unknown error message"), + e.getCause()); } - ChatManager chatManagerLocal = ChatManager.getInstanceFor(connection); - chatManagerLocal.addIncomingListener(this); - chatManager = chatManagerLocal; + ChatManager chatManager = ChatManager.getInstanceFor(connection); + chatManager.addIncomingListener(this); + this.chatManager = chatManager; httpFileUploadManager = HttpFileUploadManager.getInstanceFor(connection); - - scheduleConnectionCheck(); - } - - private void checkAndReconnect() { - AbstractXMPPConnection connectionLocal = connection; - if (connectionLocal == null) { - logger.warn("XMPP connection is null, cannot automatic recover from this permanent failure"); - return; - } - - if (!connectionLocal.isConnected()) { - connectionLocal.disconnect(); - try { - connectionLocal.connect().login(); - } catch (SmackException | IOException | XMPPException | InterruptedException ex) { - logger.info("XMPP connection error", ex); - } - } - } - - private synchronized void scheduleConnectionCheck() { - if (this.connectionCheckJob == null) { - logger.debug("Scheduling connection check job every {}s", CONNECTION_CHECK_INTERVAL); - this.connectionCheckJob = scheduler.scheduleWithFixedDelay(this::checkAndReconnect, 0, - CONNECTION_CHECK_INTERVAL, TimeUnit.SECONDS); - } - } - - private synchronized void cancelConnectionCheck() { - ScheduledFuture connectionCheckJobLocal = connectionCheckJob; - if (connectionCheckJobLocal != null) { - logger.debug("Cancelling connection check job"); - connectionCheckJobLocal.cancel(true); - this.connectionCheckJob = null; - } } public void disconnect() { - cancelConnectionCheck(); - AbstractXMPPConnection connectionLocal = connection; - if (connectionLocal != null) { - connectionLocal.disconnect(); + AbstractXMPPConnection connection = this.connection; + if (connection != null) { + connection.disconnect(); } } public void sendMessage(String to, String message) { if (connection == null) { - logger.warn("XMPP connection is null"); + eventListener.onErrorEvent("XMPP connection is null"); return; } - ChatManager chatManagerLocal = chatManager; - if (chatManagerLocal == null) { - logger.warn("XMPP chatManager is null"); + + ChatManager chatManager = this.chatManager; + if (chatManager == null) { + eventListener.onErrorEvent("XMPP chatManager is null"); return; } try { EntityBareJid jid = JidCreate.entityBareFrom(to); - Chat chat = chatManagerLocal.chatWith(jid); + Chat chat = chatManager.chatWith(jid); chat.send(message); } catch (XmppStringprepException | SmackException.NotConnectedException | InterruptedException e) { - logger.info("XMPP message sending error", e); + logger.warn("XMPP message sending error", e); } } @@ -209,21 +181,24 @@ public void newIncomingMessage(@Nullable EntityBareJid from, @Nullable Message m @Override public void connected(@Nullable XMPPConnection connection) { logger.debug("Connected to XMPP server."); + eventListener.onAllOk(); } @Override public void authenticated(@Nullable XMPPConnection connection, boolean resumed) { logger.debug("Authenticated to XMPP server."); + eventListener.onAllOk(); } @Override public void connectionClosed() { logger.debug("XMPP connection was closed."); + eventListener.onErrorEvent("XMPP connection was closed."); } @Override public void connectionClosedOnError(@Nullable Exception e) { logger.debug("Connection to XMPP server was lost."); - checkAndReconnect(); + eventListener.onErrorEvent("XMPP connection was closed."); } } diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientConfigException.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientConfigException.java new file mode 100644 index 0000000000000..c474c8c4ea4cf --- /dev/null +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientConfigException.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.xmppclient.internal.client; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * The {@link XMPPClientConfigException} represents a binding specific {@link Exception}. + * + * @author Leo Siepel - Initial contribution + */ + +@NonNullByDefault +public class XMPPClientConfigException extends Exception { + + private static final long serialVersionUID = 1L; + + public XMPPClientConfigException(String message) { + super(message); + } + + public XMPPClientConfigException(String message, @Nullable Throwable cause) { + super(message, cause); + } + + public XMPPClientConfigException(@Nullable Throwable cause) { + super(cause); + } +} diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java new file mode 100644 index 0000000000000..35638e4420154 --- /dev/null +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java @@ -0,0 +1,29 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.xmppclient.internal.client; + +import org.eclipse.jdt.annotation.NonNullByDefault; + +/** + * The {@link XMPPClientEventlistener} is lib for handling XMPP connection events + * + * @author Leo Siepel - Add reconnection logic + */ + +@NonNullByDefault +public interface XMPPClientEventlistener { + + void onErrorEvent(String errorMessage); + + void onAllOk(); +} diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientException.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientException.java new file mode 100644 index 0000000000000..5967a397ca228 --- /dev/null +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientException.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.binding.xmppclient.internal.client; + +import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; + +/** + * The {@link XMPPClientException} represents a binding specific {@link Exception}. + * + * @author Leo Siepel - Initial contribution + */ + +@NonNullByDefault +public class XMPPClientException extends Exception { + + private static final long serialVersionUID = 1L; + + public XMPPClientException(String message) { + super(message); + } + + public XMPPClientException(String message, @Nullable Throwable cause) { + super(message, cause); + } + + public XMPPClientException(@Nullable Throwable cause) { + super(cause); + } +} diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java index a99795bf1b679..21c19627293c5 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/PublishTriggerChannel.java @@ -13,7 +13,7 @@ package org.openhab.binding.xmppclient.internal.handler; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.openhab.binding.xmppclient.internal.XMPPClient; +import org.openhab.binding.xmppclient.internal.client.XMPPClient; import org.openhab.core.thing.ChannelUID; /** diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java index 2fcf77278b635..b2f0bfdef5583 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientConfiguration.java @@ -14,6 +14,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; import org.eclipse.jdt.annotation.Nullable; +import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; /** * The {@link XMPPClientConfiguration} class contains fields mapping thing configuration parameters. @@ -27,12 +28,10 @@ public class XMPPClientConfiguration { public String username = ""; public String password = ""; public String domain = ""; + public String securityMode = SecurityMode.required.toString(); public boolean isValid() { - String hostLocal = host; - if (hostLocal == null) { - return false; - } - return !hostLocal.isBlank(); + String host = this.host; + return !(host == null || host.isBlank()); } } diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java index 64bf44978704c..3c7cfc2dbfd3d 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/handler/XMPPClientHandler.java @@ -12,18 +12,20 @@ */ package org.openhab.binding.xmppclient.internal.handler; -import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; import org.eclipse.jdt.annotation.NonNullByDefault; -import org.jivesoftware.smack.SmackException; -import org.jivesoftware.smack.XMPPException; -import org.openhab.binding.xmppclient.internal.XMPPClient; +import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; import org.openhab.binding.xmppclient.internal.action.XMPPActions; +import org.openhab.binding.xmppclient.internal.client.XMPPClient; +import org.openhab.binding.xmppclient.internal.client.XMPPClientConfigException; +import org.openhab.binding.xmppclient.internal.client.XMPPClientEventlistener; +import org.openhab.binding.xmppclient.internal.client.XMPPClientException; import org.openhab.core.thing.Bridge; import org.openhab.core.thing.Channel; import org.openhab.core.thing.ChannelUID; @@ -42,14 +44,14 @@ * @author Pavel Gololobov - Initial contribution */ @NonNullByDefault -public class XMPPClientHandler extends BaseBridgeHandler { +public class XMPPClientHandler extends BaseBridgeHandler implements XMPPClientEventlistener { private final Logger logger = LoggerFactory.getLogger(XMPPClientHandler.class); private XMPPClient xmppClient; private final Map channelStateByChannelUID = new HashMap<>(); public XMPPClientHandler(Bridge thing) { super(thing); - xmppClient = new XMPPClient(); + xmppClient = new XMPPClient(this); } public XMPPClient getXMPPClient() { @@ -88,14 +90,20 @@ public void dispose() { private void doConnect() { XMPPClientConfiguration config = getConfigAs(XMPPClientConfiguration.class); if (!config.isValid()) { - updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Please check host configuration"); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, "Please check configuration"); return; } - String host = config.host; + try { - xmppClient.connect(host != null ? host : "", config.port, config.username, config.domain, config.password); - } catch (SmackException | IOException | XMPPException e) { - logger.info("XMPP connection error", e); + xmppClient.connect(Objects.requireNonNullElse(config.host, ""), config.port, config.username, config.domain, + config.password, SecurityMode.valueOf(config.securityMode)); + updateStatus(ThingStatus.ONLINE); + } catch (XMPPClientConfigException e) { + logger.debug("XMPP connection error", e); + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, e.getMessage()); + return; + } catch (XMPPClientException e) { + logger.debug("XMPP connection error", e); updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage()); return; } @@ -108,7 +116,15 @@ private void doConnect() { logger.info("XMPP added channel {} payload {}", channel.getUID().toString(), channelConfig.payload); } channelStateByChannelUID.values().forEach(c -> c.start()); + } + @Override + public void onErrorEvent(String errorMessage) { + updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, errorMessage); + } + + @Override + public void onAllOk() { updateStatus(ThingStatus.ONLINE); } } diff --git a/bundles/org.openhab.binding.xmppclient/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.xmppclient/src/main/resources/OH-INF/thing/thing-types.xml index b9841ddce73f1..ea506032b3c2e 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.xmppclient/src/main/resources/OH-INF/thing/thing-types.xml @@ -30,6 +30,19 @@ The default port is 5222. + true + + + + An enumeration for TLS security modes that are available when making a connection to the XMPP server. + true + + + + + + required + true From e84cd09b6e3fba0e8a7ebd8a82f62b40645a9f1e Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Sat, 29 Jun 2024 23:37:36 +0200 Subject: [PATCH 4/8] Update documentation Signed-off-by: Leo Siepel --- .../org.openhab.binding.xmppclient/README.md | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/bundles/org.openhab.binding.xmppclient/README.md b/bundles/org.openhab.binding.xmppclient/README.md index 8a8d944feec24..228aea4bd8723 100644 --- a/bundles/org.openhab.binding.xmppclient/README.md +++ b/bundles/org.openhab.binding.xmppclient/README.md @@ -26,22 +26,23 @@ Bridge xmppclient:xmppBridge:xmpp "XMPP Client" [ host="xmpp.example.com", port= **xmppBridge** parameters: -| Name | Label | Description | Required | Default value | -|----------|--------------------|-------------------------------------------|-----------|-----------------------| -| username | Username | The XMPP username (left part of JID) | true | - | -| domain | Domain | The XMPP domain name (right part of JID) | true | - | -| password | Password | The XMPP user password | true | - | -| host | Server Hostname/IP | The IP/Hostname of the XMPP server | false | as "domain" parameter | -| port | XMPP server Port | The typical port is 5222 | false | 5222 | +| Name | Label | Description | Required | Default value | +|----------|--------------------|--------------------------------------------------------------------|----------|-----------------------| +| username | Username | The XMPP username (left part of JID) | true | - | +| domain | Domain | The XMPP domain name (right part of JID) | true | - | +| password | Password | The XMPP user password | true | - | +| host | Server Hostname/IP | The IP/Hostname of the XMPP server | false | as "domain" parameter | +| port | XMPP server Port | The typical port is 5222 | false | 5222 | +| port | Security Mode | Sets the TLS security mode: `required`, `ifpossible` or `disabled` | false | `required` | ## Channels **publishTrigger** parameters: -| Name | Label | Description | Required | -|-----------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------| -| payload | Payload condition | An optional condition on the value | false | -| separator | Separator character | The trigger channel payload usually only contains the received text. If you define a separator character, for example '#', the sender UID and received text will be in the trigger channel payload. For example: pavel@example.com#My Message Text | false | +| Name | Label | Description | Required | +|-----------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------| +| payload | Payload condition | An optional condition on the value | false | +| separator | Separator character | The trigger channel payload usually only contains the received text. If you define a separator character, for example '#', the sender UID and received text will be in the trigger channel payload. For example: pavel@example.com#My Message Text | false | ## Example Rules From 22ab80552acbadbf0eb28f84cfc69bddd4d8a974 Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Tue, 16 Jul 2024 20:29:10 +0200 Subject: [PATCH 5/8] Minor improvement Signed-off-by: Leo Siepel --- .../binding/xmppclient/internal/action/XMPPActions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java index cc6eb8e2c3adc..4bcc6b509e504 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/action/XMPPActions.java @@ -58,8 +58,8 @@ public void publishXMPP(@ActionInput(name = "to", label = "To", description = "S } XMPPClient connection = clientHandler.getXMPPClient(); - if ((to == null) || (text == null)) { - logger.info("Skipping XMPP messaging to {} value {}", to, text); + if (to == null || text == null) { + logger.warn("Skipping XMPP messaging to {} value {}", to, text); return; } connection.sendMessage(to, text); @@ -76,7 +76,7 @@ public void publishXMPPImageByHTTP( } XMPPClient connection = clientHandler.getXMPPClient(); - if ((to == null) || (filename == null)) { + if (to == null || filename == null) { logger.warn("Skipping XMPP messaging to {} value {}", to, filename); return; } From b4cd43db71fff9280875a3f3ccf7290906310967 Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Tue, 16 Jul 2024 20:33:41 +0200 Subject: [PATCH 6/8] Fix securityMode Signed-off-by: Leo Siepel --- .../openhab/binding/xmppclient/internal/client/XMPPClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClient.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClient.java index 00fe9567840c6..4ca39840436ef 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClient.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClient.java @@ -88,7 +88,7 @@ public void connect(String host, Integer port, String login, String domain, Stri .setPort(port) // .setUsernameAndPassword(login, password) // .setXmppDomain(domain) // - .setSecurityMode(SecurityMode.disabled)// + .setSecurityMode(securityMode)// .build(); } catch (XmppStringprepException e) { throw new XMPPClientConfigException(Objects.requireNonNullElse(e.getMessage(), "Unknown error message")); From 353dcd12b56a79eec90e85392108ccef85e82124 Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Tue, 16 Jul 2024 20:35:09 +0200 Subject: [PATCH 7/8] Fix SAT Signed-off-by: Leo Siepel --- .../xmppclient/internal/client/XMPPClientEventlistener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java index 35638e4420154..c03534cb8587f 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java @@ -17,7 +17,7 @@ /** * The {@link XMPPClientEventlistener} is lib for handling XMPP connection events * - * @author Leo Siepel - Add reconnection logic + * @author Leo Siepel - Initial Contribution */ @NonNullByDefault From 4d14bd53ef55d1375c33c7439c8538abef1fb3e2 Mon Sep 17 00:00:00 2001 From: Leo Siepel Date: Sun, 18 Aug 2024 21:32:44 +0200 Subject: [PATCH 8/8] Fix comments. Signed-off-by: Leo Siepel --- bundles/org.openhab.binding.xmppclient/README.md | 16 ++++++++-------- .../internal/client/XMPPClientEventlistener.java | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.binding.xmppclient/README.md b/bundles/org.openhab.binding.xmppclient/README.md index 228aea4bd8723..e7133375d4ccd 100644 --- a/bundles/org.openhab.binding.xmppclient/README.md +++ b/bundles/org.openhab.binding.xmppclient/README.md @@ -26,14 +26,14 @@ Bridge xmppclient:xmppBridge:xmpp "XMPP Client" [ host="xmpp.example.com", port= **xmppBridge** parameters: -| Name | Label | Description | Required | Default value | -|----------|--------------------|--------------------------------------------------------------------|----------|-----------------------| -| username | Username | The XMPP username (left part of JID) | true | - | -| domain | Domain | The XMPP domain name (right part of JID) | true | - | -| password | Password | The XMPP user password | true | - | -| host | Server Hostname/IP | The IP/Hostname of the XMPP server | false | as "domain" parameter | -| port | XMPP server Port | The typical port is 5222 | false | 5222 | -| port | Security Mode | Sets the TLS security mode: `required`, `ifpossible` or `disabled` | false | `required` | +| Name | Label | Description | Required | Default value | +|--------------|--------------------|--------------------------------------------------------------------|----------|-----------------------| +| username | Username | The XMPP username (left part of JID) | true | - | +| domain | Domain | The XMPP domain name (right part of JID) | true | - | +| password | Password | The XMPP user password | true | - | +| host | Server Hostname/IP | The IP/Hostname of the XMPP server | false | as "domain" parameter | +| port | XMPP server Port | The typical port is 5222 | false | 5222 | +| securityMode | Security Mode | Sets the TLS security mode: `required`, `ifpossible` or `disabled` | false | `required` | ## Channels diff --git a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java index c03534cb8587f..e1fb7a2257da9 100644 --- a/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java +++ b/bundles/org.openhab.binding.xmppclient/src/main/java/org/openhab/binding/xmppclient/internal/client/XMPPClientEventlistener.java @@ -15,7 +15,7 @@ import org.eclipse.jdt.annotation.NonNullByDefault; /** - * The {@link XMPPClientEventlistener} is lib for handling XMPP connection events + * The {@link XMPPClientEventlistener} is an interface for handling XMPP connection events. * * @author Leo Siepel - Initial Contribution */