What are the correct parameters for the xmpp connection (spring integration) to make it work with google gcm?

I want to set up spring-integration-xmpp in my spring application so that it can receive upstream messages from android devices. I can already send messages to my android device using http, but I cannot configure the xmpp-connection bean, so it gives me:

failed to connect to gcm-preprod.googleapis.com; nested exception is Connection failed. No response from server.:

      

This is my spring integration integration:

  <int:channel id="gcmOutboundNotificationChannel"/>

  <int-xmpp:xmpp-connection
    id="xmppConnection"
    user="${tracker.server.app.id}@gcm.googleapis.com"
    password="${tracker.auth.key}"
    host="gcm-preprod.googleapis.com"
    port="5236"
    subscription-mode="accept_all"/>

  <int-xmpp:outbound-channel-adapter
    id="gcmOutboundAdapter"
    xmpp-connection="xmppConnection"
    channel="gcmOutboundNotificationChannel"/>

      

tracker.server.app.id

is a 12 digit number and is tracker.auth.key

like AIzaSyBdfZ4oBaVuu07sjW5e9DnogeUF6NV****

(I put asterisks).

What am I missing?

+1


source to share


2 answers


I have set up xmpp connection as bean like this:

@Configuration
public class GcmXmppConnection {

@Value("${gcm.senderID}")
private String username;

@Value("${gcm.apiKey}")
private String password;

@Value("${gcm.host}")
private String host;

@Value("${gcm.port}")
private int port;

@Bean(name="gcmConnection")
public XmppConnectionFactoryBean xmppConnectionFactoryBean(){

    ConnectionConfiguration configuration = new    ConnectionConfiguration(host, port);
    configuration.setSecurityMode(SecurityMode.enabled);
    configuration.setReconnectionAllowed(true);
    configuration.setRosterLoadedAtLogin(false);
    configuration.setSendPresence(false);
    configuration.setSocketFactory(SSLSocketFactory.getDefault());

//      configuration.setDebuggerEnabled(true);
    XmppConnectionFactoryBean connectionFactoryBean = new XmppConnectionFactoryBean(configuration);

    connectionFactoryBean.setUser(username);
    connectionFactoryBean.setPassword(password);

    return connectionFactoryBean;
}
}

      

The config is automatically set in the xml config as follows:

<!-- Outbound messages to gcm -->
    <int:chain input-channel="androidNotificationOutputChannel">
    <int:transformer ref="androidMessageTransformer"></int:transformer>
    <int-xmpp:outbound-channel-adapter xmpp-connection="gcmConnection"/>
</int:chain>

<!-- Inbound messages from gcm -->
<int:channel id="gcmInboundNotificationChannel"/>
<int-xmpp:inbound-channel-adapter id="gcmInboundAdapter"
    channel="gcmInboundNotificationChannel" xmpp-connection="gcmConnection"
    extract-payload="true" auto-startup="true" />

      



The last part is androidMessageTransformer, it is quite simple, like gcmXmppConnection bean, it was coded in the example in google docs.

@MessageEndpoint
public class AndroidMessageTransformer extends AbstractTransformer {

public final static String DESTINATION_HEADER_KEY="push.destinationID";

private final static String MESSAGE_ID_FORMAT = "%s-%s";

@Value("${gcm.senderID}")
private String senderId;

@Autowired
ObjectMapper om;

@SuppressWarnings("unchecked")
@Override
protected Object doTransform(Message<?> msgIn) throws Exception {
    Map<String,String> data = (Map<String, String>) msgIn.getPayload();
    String registrationID = msgIn.getHeaders().get(DESTINATION_HEADER_KEY,String.class);
    Map<String, Object> gcmPayload = new HashMap<>();

    gcmPayload.put("to", registrationID);
    gcmPayload.put("message_id", String.format(Locale.ENGLISH, MESSAGE_ID_FORMAT, senderId, UUID.randomUUID().toString()));
    gcmPayload.put("data", data);

    String gcmJsonPayload = om.writeValueAsString(gcmPayload);

    org.jivesoftware.smack.packet.Message xmppMessage = new org.jivesoftware.smack.packet.Message();
    xmppMessage.addExtension(new GcmPacketExtension(gcmJsonPayload));

    return xmppMessage;
}
}

      

This works reliably for me, although I have mostly worked with outbound direction and never checked much about the inbound side.

+1


source


I think what you are missing auto-startup="true"

in the tag <int-xmpp:outbound-channel-adapter

. Refer to the next answer for you.



0


source







All Articles