java - Not able receiving all messages, only every second, from Google Cloud Messaging with CCS using Smack -


i'm trying set connection google cloud messaging via cloud connection server (xmpp-connection) using smack 4.1.2. able establish connection , receive incoming messages. problem stanzalistener isn't triggered each message (but every second one). smack debugging console shows "raw received packets", sending device-to-cloud works each message.

thank help!

here's code server app:

my class gcmserver main:

public class gcmserver {  public static final logger logger = logger.getlogger(gcmserver.class.getname()); public static sslcontext sslctx; public static xmpptcpconnection connection;  private static final string gcm_server = "gcm.googleapis.com"; private static final int gcm_port = 5235;  private static final string gcm_element_name = "gcm"; private static final string gcm_namespace = "google:mobile:data";  private static final string your_project_id = "xxxxxxxxxxxx"; private static final string your_api_key = "xxxx";    public static void main(string[] args) {      connectionlistener cl;      try {                  keystore windowsroottruststore = keystore.getinstance("windows-root", "sunmscapi");         windowsroottruststore.load(null, null);         trustmanagerfactory tmf = trustmanagerfactory.getinstance(trustmanagerfactory.getdefaultalgorithm());         tmf.init(windowsroottruststore);         sslctx = sslcontext.getinstance("tls");         sslctx.init(null, tmf.gettrustmanagers(), null);         } catch (keystoreexception | nosuchproviderexception | ioexception | nosuchalgorithmexception | certificateexception | keymanagementexception ex) {             logger.getlogger(gcmserver.class.getname()).log(level.severe, null, ex);         }             xmpptcpconnectionconfiguration conf = xmpptcpconnectionconfiguration.builder()                 .setsecuritymode(securitymode.ifpossible)                 .setusernameandpassword(your_project_id, your_api_key)                 .sethost(gcm_server)                 .setservicename(gcm_server)                 .setport(5235)                 .setdebuggerenabled(true)                 .setcompressionenabled(false)                 .setsocketfactory(sslctx.getsocketfactory())                 .build();       cl = new connectionlistener() {          @override         public void connected(xmppconnection xmppc) {              logger.getlogger(gcmserver.class.getname()).log(level.info, "connected");              system.out.println("conncetion secure: "+connection.issecureconnection());         }          @override         public void authenticated(xmppconnection xmppc, boolean bln) {             logger.getlogger(gcmserver.class.getname()).log(level.info, "authenticated");         }          @override         public void connectionclosed() {             logger.getlogger(gcmserver.class.getname()).log(level.info, "connection closed");         }          @override         public void connectionclosedonerror(exception excptn) {             logger.getlogger(gcmserver.class.getname()).log(level.info, "conncetion closed on error");         }          @override         public void reconnectionsuccessful() {             logger.getlogger(gcmserver.class.getname()).log(level.info, "reconnection successful");         }          @override         public void reconnectingin(int i) {             logger.getlogger(gcmserver.class.getname()).log(level.info, "reconnecting..");         }          @override         public void reconnectionfailed(exception excptn) {             logger.getlogger(gcmserver.class.getname()).log(level.info, "reconnection failed");         }     };          connection = new xmpptcpconnection(conf);          //disable roster; seems it's not supported gcm         roster roster = roster.getinstancefor(connection);           roster.setrosterloadedatlogin(false);             try {             connection.connect();             connection.addasyncstanzalistener(new mystanzalistener(),new stanzatypefilter(message.class));             connection.addconnectionlistener(cl);             connection.login(your_project_id + "@gcm.googleapis.com", your_api_key);         } catch (smackexception ex) {             logger.getlogger(gcmserver.class.getname()).log(level.severe, null, ex);          } catch (ioexception ex) {             logger.getlogger(gcmserver.class.getname()).log(level.severe, null, ex);         } catch (xmppexception ex) {             logger.getlogger(gcmserver.class.getname()).log(level.severe, null, ex);         }  } 

class mystanzalistener:

private static class mystanzalistener implements stanzalistener{      @override     public void processpacket(stanza stanza) {                 system.out.println("hei ho, new message: " + stanza.toxml());                  message incomingmessage = (message) stanza;                 gcmpacketextension gcmpacket = (gcmpacketextension) incomingmessage.getextension(gcm_namespace);                 string json = gcmpacket.getjson();                  try {                     map<string, object> jsonobject = (map<string, object>) jsonvalue.parsewithexception(json);                      object messagetype = jsonobject.get("message_type");                     string = (string)jsonobject.get("from");                     string messageid = (string)jsonobject.get("message_id");                     string category = (string)jsonobject.get("category");                       if(messagetype == null) {                         string ack = createjsonack(from, messageid);                         system.out.println(ack);                         send(ack);                          handlemessage(jsonobject);                     }                     else{                         logger.getlogger(gcmserver.class.getname()).log(level.severe, "error in handling message");                     }                  } catch (parseexception ex) {                     logger.getlogger(gcmserver.class.getname()).log(level.severe, null, ex);                 }     }  } 

methods handlemessage, createjsonack, send:

public static void handlemessage(map<string, object> jsonobject) {       dbconnect db = new dbconnect();        map<string, object> messagedata = (map<string, object>) jsonobject.get("data");       string phonenumber = (string)messagedata.get("phonenumber");       string text = (string)messagedata.get("message");         db.inboundmessage(phonenumber, text);    }     public static string createjsonack(string to, string messageid) {         map<string, object> message = new linkedhashmap<string, object>();         message.put("to", to);         message.put("message_id", messageid);         message.put("message_type", "ack");          return jsonvalue.tojsonstring(message);     }     /**      * sends downstream gcm message.      */     public static void send(string jsonrequest) {         stanza request = (stanza)new gcmpacketextension(jsonrequest).topacket();         try {             connection.sendstanza(request);         } catch (notconnectedexception ex) {             logger.getlogger(gcmserver.class.getname()).log(level.severe, "error while sending: ", ex);         }     } 

this bug (smack-695) in smack 4.1.3, fixed/will fixed in 4.1.4. more information see https://community.igniterealtime.org/thread/56610.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -