Hi,
I had Smack 4.0.3 working with Google Hanouts but it stopped sending messages. I am trying Smack version: 4.2.0 (4.2.0-rc2-49-gb9b8b1a-4.2 2017-03-10). I am able to authenticate but my chat messages are not received. I have tried every combination I could think of. Below is what I have currently. Looking for suggestions on what to try next.
Thanks, PLA
package com.mygsuitedomain.xmpp;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.jivesoftware.smack.ConnectionListener;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.chat2.Chat;
import org.jivesoftware.smack.chat2.ChatManager;
import org.jivesoftware.smack.chat2.IncomingChatMessageListener;
import org.jivesoftware.smack.chat2.OutgoingChatMessageListener;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.roster.Roster;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jxmpp.jid.EntityBareJid;
import org.jxmpp.jid.impl.JidCreate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLSession;
import java.io.FileInputStream;
import java.net.InetAddress;
import java.util.Date;
import java.util.Properties;
public class XmppDAO {
private AbstractXMPPConnection connection;
public XmppDAO() {
}
public static void main(String[] args) {
XmppDAO dao = new XmppDAO();
try {
dao.init();
} catch (Exception e) {
e.printStackTrace();
}
}
private void init() throws Exception {
System.out.format(String.format("Smack version: %s.\n", SmackConfiguration.getVersion()));
SmackConfiguration.DEBUG = true;
Properties properties = new Properties();
properties.load(new FileInputStream("/etc/XmppDAO.properties"));
Roster.setRosterLoadedAtLoginDefault(false);
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword(properties.getProperty("username"), properties.getProperty("password"));
configBuilder.setHostAddress(InetAddress.getByName("talk.google.com"));
configBuilder.setXmppDomain(JidCreate.domainBareFrom("mygsuitedomain.com"));
configBuilder.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String s, SSLSession sslSession) {
System.out.format("Host name verifier. %s - %s\n", s, sslSession);
return true;
}
});
configBuilder.setPort(5222);
configBuilder.setSendPresence(false);
configBuilder.setDebuggerEnabled(true);
connection = new XMPPTCPConnection(configBuilder.build());
org.jivesoftware.smack.ConnectionListener connectionListener = new ConnectionListener() {
@Override
public void reconnectionSuccessful() {
System.out.format("reconnectionSuccessful\n");
}
@Override
public void reconnectionFailed(Exception e) {
System.out.format("reconnectionFailed\n");
}
@Override
public void reconnectingIn(int arg0) {
System.out.format("reconnectingIn %d\n", arg0);
}
@Override
public void connectionClosedOnError(Exception e) {
System.out.format("connectionClosedOnError %s\n", e.getLocalizedMessage());
e.printStackTrace();
}
@Override
public void connectionClosed() {
System.out.format("connectionClosed\n");
}
@Override
public void connected(XMPPConnection connection) {
System.out.format("connected %s\n", connection);
}
@Override
public void authenticated(XMPPConnection connection, boolean resumed) {
System.out.format("authenticated %s Resumed: %s Secure connection: %s\n",
connection.isAuthenticated(), resumed, connection.isSecureConnection());
}
};
connection.addConnectionListener(connectionListener);
System.out.println("Attempt to connect.");
connection.connect();
System.out.println("Attempt to login");
connection.login();
ChatManager chatManager = ChatManager.getInstanceFor(connection);
EntityBareJid jid = JidCreate.entityBareFrom("patrick.archibald@mygsuitedomain.com");
Chat chat = chatManager.chatWith(jid);
chatManager.addOutgoingListener(new OutgoingChatMessageListener() {
@Override
public void newOutgoingMessage(EntityBareJid to, Message message, Chat chat) {
System.out.format("OUTGOING: %s.\n", message);
}
});
chatManager.addIncomingListener(new IncomingChatMessageListener() {
@Override
public void newIncomingMessage(EntityBareJid from, Message message, Chat chat) {
System.out.format("INCOMING: %s.\n", message);
}
});
for (int i = 0; i < 1; i++) {
String messageString = String.format("Test message number: %d from %s at %s\n", i, this.getClass().getCanonicalName(), new Date());
chat.send(messageString);
System.out.format("Attempt to send message number: %d partner: %s Message text: %s.\n",
i, chat.getXmppAddressOfChatPartner(), messageString);
}
System.out.println("Sleeping.");
Thread.sleep(1000 * 60);
System.out.println("Done");
System.exit(0);
}
}