SyntaxHighlighter

Showing posts with label Spring Integration XMPP. Show all posts
Showing posts with label Spring Integration XMPP. Show all posts

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;

package de.incompleteco.spring.social.service.support;

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;

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

  ConnectionConfiguration config = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
  XMPPConnection connection = new XMPPConnection(config);
  connection.connect();
  connection.login("someuser@gmail.com", "password");
  return connection;
   }
}



and here's the XML that supports the test