gunglefunk
gunglefunk

Reputation: 423

Google Cloud Connection Server and smack

I'm trying to get a java server set up for communicating to Google's Cloud Connection Server using the smack library. I have set up an app ID and API key through Google APIs and am trying to use the following code:

import javax.net.ssl.SSLSocketFactory;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.SASLAuthentication;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.packet.Packet;

public class CloudMessager {

public CloudMessager(){
    ConnectionConfiguration config = new ConnectionConfiguration("gcm.googleapis.com", 5235);
    SASLAuthentication.supportSASLMechanism("PLAIN", 0);
    config.setSASLAuthenticationEnabled(true);
    config.setSocketFactory(SSLSocketFactory.getDefault());

    Connection connection = new XMPPConnection(config);
    // Connect to the server
    try {
        connection.connect();

        connection.login("SENDERID@gcm.googleapis.com", "APIKEY");

        PacketListener myListener = new PacketListener() {
            public void processPacket(Packet packet) {

            }
        };

        // Register the listener.
        connection.addPacketListener(myListener,null);

    } catch (XMPPException e) {
        e.printStackTrace();
    }       
}
}

Which gives me the following error:

SASL authentication PLAIN failed: text: 
at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:342)
at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:221)
at org.jivesoftware.smack.Connection.login(Connection.java:366)
at org.umptyfratz.strongbox.CloudMessager.<init>(CloudMessager.java:25)

I'm at a bit of a loss to figure out where to go from here. Has anyone else successfully connected to CCS using the Java smack library?

Upvotes: 4

Views: 2427

Answers (1)

Gerifield
Gerifield

Reputation: 403

Try to debug the connection with this option:

config.setDebuggerEnabled(true);

This'll open a new window with the data sent and received.

If you find something like "Project SENDERID not whitelisted." you have to register your project here.

(This is in the documentation's note too! http://developer.android.com/google/gcm/ccs.html )

Upvotes: 3

Related Questions