INT-1687 added connection validation and reconnect logic for outbound XMPP adapters, added ConnectionListener to the XMPPConnection to log (DEBUG level) connection events
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
import org.jivesoftware.smack.ConnectionListener;
|
||||
import org.jivesoftware.smack.Roster;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
@@ -96,6 +97,28 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
public void start() {
|
||||
try {
|
||||
connection.connect();
|
||||
connection.addConnectionListener(new ConnectionListener() {
|
||||
|
||||
public void reconnectionSuccessful() {
|
||||
logger.debug("Reconnection is successfull");
|
||||
}
|
||||
|
||||
public void reconnectionFailed(Exception e) {
|
||||
logger.debug("Reconnection failed", e);
|
||||
}
|
||||
|
||||
public void reconnectingIn(int seconds) {
|
||||
logger.debug("Reconnecting in " + seconds + " seconds");
|
||||
}
|
||||
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
logger.debug("Connection closed", e);
|
||||
}
|
||||
|
||||
public void connectionClosed() {
|
||||
logger.debug("Connection closed");
|
||||
}
|
||||
});
|
||||
if (StringUtils.hasText(user)){
|
||||
connection.login(user, password, resource);
|
||||
Assert.isTrue(connection.isAuthenticated(), "Failed to authenticate user: " + user);
|
||||
|
||||
@@ -68,6 +68,9 @@ public class ChatMessageSendingMessageHandler extends AbstractXmppConnectionAwar
|
||||
"are suported. Was '" + messageBody.getClass().getName() +
|
||||
"' Consider adding a transformer prior to sending message to this handler");
|
||||
}
|
||||
if (!this.xmppConnection.isConnected()){
|
||||
this.xmppConnection.connect();
|
||||
}
|
||||
this.xmppConnection.sendPacket(xmppMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ public class PresenceSendingMessageHandler extends AbstractXmppConnectionAwareMe
|
||||
Object payload = message.getPayload();
|
||||
Assert.isInstanceOf(Presence.class, payload, "'payload' must be of type 'org.jivesoftware.smack.packet.Presence', was: "
|
||||
+ payload.getClass().getName());
|
||||
if (!this.xmppConnection.isConnected()){
|
||||
this.xmppConnection.connect();
|
||||
}
|
||||
this.xmppConnection.sendPacket((Presence)payload);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user