Thursday, May 2, 2013

Spring Integration XMPP and Google Talk

Spring Integration XMPP and Google Talk

in developing a little test application the other day, i came across a fiddly little problem with Google Talk and Spring Integration's XMPP.  essentially, there's an authentication rub that means you can't really use the out-of-the-box namespace configuration to connect to Google Talk.

so, the trick appears to be setting a static value before calling connect on the XMPPConnection.  to do this, it's best to use @Configuration;


import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

public class GoogleTalkConfiguration {
   public XMPPConnection xmppConnection() throws Exception {
  SASLAuthentication.supportSASLMechanism("PLAIN", 0); // static initializer

  ConnectionConfiguration config = new ConnectionConfiguration("", 5222, "");
  XMPPConnection connection = new XMPPConnection(config);
  connection.login("", "password");
  return connection;

and here's the XML that supports the test


No comments:

Post a Comment