AnsweredAssumed Answered

Empty Message(Reply) Received From FCM Google Server(Smack 4.1.0)

Question asked by Rohan Kalra on Sep 26, 2016
Latest reply on Sep 27, 2016 by Luis

Hello,

I am new to FCM XMPP Domain. I tried to migrate from Smack 3.2.1 to Smack 4.1.0 and faced following issue:

When I sent a push notification using Smack 3.2.1, the XML message sent from application is as follows:

<message id="rNdOr-2"><gcm xmlns="google:mobile:data">{"data":{"message":"This is the simple sample message"},"message_id":"m-ebb3a51f-7269-48e5-a7e6-52c7363cb4e9","to":"ctsQTqWHUhk:APA91bHfxyii0J-Z9nn9oA4MCpeL8lJgyf5H5-IKD7tpSW-3MRq-oifDv3MBAbVGPpP2BgHebgfLaMH-vfEKxBA7XnKfIIfy7hJWOy_J5TzaVWNC7ej2jxv6bm82wLfsxzyjVNdRfFsW"}</gcm></message>

 

 

And the reply(acknowledgement) received while using Smack 3.2.1 was as follows:-

<message><gcm xmlns="google:mobile:data">{"message_type":"ack","from":"ctsQTqWHUhk:APA91bHfxyii0J-Z9nn9oA4MCpeL8lJgyf5H5-IKD7tpSW-3MRq-oifDv3MBAbVGPpP2BgHebgfLaMH-vfEKxBA7XnKfIIfy7hJWOy_J5TzaVWNC7ej2jxv6bm82wLfsxzyjVNdRfFsW","message_id":"m-ebb3a51f-7269-48e5-a7e6-52c7363cb4e9"}</gcm></message>

 

 

But for the same message sent from Smack 4.1.0, the reply was as follows:-

<message><gcm xmlns='google:mobile:data'></gcm></message>

 

 

I was wondering how to get the acknowledgement message similar to the one received in Smack 3.2.1.

The Java code for Smack 4.1.0 is as follows:-

 

public class CcsClient implements StanzaListener{

   private XMPPTCPConnection connection;
   private XMPPTCPConnectionConfiguration config;

   public void connect() throws XMPPException, SmackException, IOException {
   config = XMPPTCPConnectionConfiguration.builder()
  .setHost("fcm-xmpp.googleapis.com")
  .setPort(5236)
  .setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible)
  .setSendPresence(false)
  .setSocketFactory(SSLSocketFactory.getDefault())
  .setDebuggerEnabled(false)
  .setUsernameAndPassword(FCMUtil.SENDER_ID + "@gcm.googleapis.com", FCMUtil.APIKey)
  .setServiceName("gcm.googleapis.com")
  .build();
   connection = new XMPPTCPConnection(config);
  ReconnectionManager.getInstanceFor(connection).enableAutomaticReconnection();
   connection.setPacketReplyTimeout(10000);//
   Roster roster = Roster.getInstanceFor(connection);
  roster.setRosterLoadedAtLogin(false);
   connection.addAsyncStanzaListener(this, new StanzaTypeFilter(Message.class));
   connection.setUseStreamManagement(true);
   connection.setUseStreamManagementResumption(true);
   connection.addSyncStanzaListener(this, new StanzaTypeFilter(Message.class));
   connection.addStanzaAcknowledgedListener(this);
   connection.addPacketInterceptor(packet -> System.out.println("CCS_Client sent the following message: " + packet.toXML()), new StanzaTypeFilter(Message.class));
   connection.addConnectionListener(new ConnectionListener() {
   public void reconnectionSuccessful() {
   logger.log(Level.INFO, "Reconnection successful ...");
  }
   public void reconnectionFailed(Exception e) {
   logger.log(Level.INFO, "Reconnection failed: ", e.getMessage());
  }
   public void reconnectingIn(int seconds) {
   logger.log(Level.INFO, "Reconnecting in %d secs", seconds);
  }
   public void connectionClosedOnError(Exception e) {
   logger.log(Level.INFO, "Connection closed on error");
  }
   public void connected(XMPPConnection xmppConnection) {
   logger.info("connecteddddddddddddddd");
  }
   public void authenticated(XMPPConnection xmppConnection, boolean b) {
  }
   public void connectionClosed() {
   logger.log(Level.INFO, "Connection closed");
  }
  });
   connection.connect();
   connection.login(FCMUtil.SENDER_ID + "@gcm.googleapis.com", FCMUtil.APIKey);
  }
public void send(String jsonRequest) {

   Stanza request = new GcmPacketExtension(jsonRequest).toPacket();
   try {
   connection.sendStanza(request);
  } catch (SmackException.NotConnectedException e) {
  e.printStackTrace();
  }
}



 

 

 

public class GcmPacketExtension extends DefaultExtensionElement {
   private String json;
   public GcmPacketExtension(String json) {
   super(Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE);
   this.json = json;
  }
   public String getJson() {
   return json;
  }
   @Override
   public String toXML() {
   return String.format("<%s xmlns=\"%s\">%s</%s>", Util.FCM_ELEMENT_NAME, Util.FCM_NAMESPACE, json,
  Util.FCM_ELEMENT_NAME);
  }
   public Stanza toPacket() {
  Message message = new Message();
  message.addExtension(this);
   return message;
  }
}

 

Basically, the purpose of reading the acknowledgement is to make sure that that nothing went wrong while delivering message to CCS.

 

Any help would be appreciated!

Outcomes