google app engine - java.lang.ExceptionInInitializerError while connecting to GCM CCS -



google app engine - java.lang.ExceptionInInitializerError while connecting to GCM CCS -

i new gcm world. have created xmpp gcm server explained @ link [https://developer.android.com/google/gcm/ccs.html#smack][1] .

i have modified code bit create endpoint method prepareclient connectxmpserver. methods establishes connection ccs. phone call endpoint client on mobile device.

here server code -

public class smackccsclientendpoint { private static final logger logger = logger.getlogger("smackccsclientendpoint"); private static final string gcm_server = "gcm.googleapis.com"; private static final int gcm_port = 5236; private static final string gcm_element_name = "gcm"; private static final string gcm_namespace = "google:mobile:data"; private static smackccsclientendpoint sinstance = null; private string mapikey = null; private string mprojectid = null; private boolean mdebuggable = false; public static smackccsclientendpoint getinstance() { if (sinstance == null) { throw new illegalstateexception("you have prepare client first"); } homecoming sinstance; } @apimethod(name = "connectxmpserver") public void prepareclient(@named("senderid") string projectid, @named("apikey") string apikey, @named("debuggable") boolean debuggable) throws xmppexception, ioexception, smackexception { synchronized(smackccsclientendpoint.class) { if (sinstance == null) { sinstance = new smackccsclientendpoint(projectid, apikey, debuggable); } } sinstance.connect(); } private smackccsclientendpoint(string projectid, string apikey, boolean debuggable) { this(); mapikey = apikey; mprojectid = projectid; mdebuggable = debuggable; } public smackccsclientendpoint() { providermanager.addextensionprovider(gcm_element_name, gcm_namespace, new packetextensionprovider() { @override public packetextension parseextension(xmlpullparser parser) throws exception { // todo check nexttext method logger.severe("before parse"); string json = parser.gettext(); logger.severe("after parse"); homecoming new gcmpacketextension(json); } }); } private xmppconnection connection; /** * indicates whether connection in draining state, means * not take new downstream messages. */ protected volatile boolean connectiondraining = false; /** * sends downstream message gcm. * * @return true if message has been sent. */ private boolean senddownstreammessage(string jsonrequest) throws notconnectedexception { if (!connectiondraining) { send(jsonrequest); homecoming true; } logger.info("dropping downstream message since connection draining"); homecoming false; } /** * returns random message id uniquely identify message. * * <p>note: generated pseudo random number generator * illustration purpose, , not guaranteed unique. */ private string nextmessageid() { //todo unique id homecoming "m-" + uuid.randomuuid().tostring(); } /** * sends packet contents provided. */ protected void send(string jsonrequest) throws notconnectedexception { packet request = new gcmpacketextension(jsonrequest).topacket(); connection.sendpacket(request); } /** * handles upstream info message device application. * * <p>this sample echo server sends echo message device. * subclasses should override method process upstream messages. */ protected void handleupstreammessage(map<string, object> jsonobject) { // packagename of application sent message. string category = (string) jsonobject.get("category"); string = (string) jsonobject.get("from"); @suppresswarnings("unchecked") map<string, string> payload = (map<string, string>) jsonobject.get("data"); payload.put("echo", "application: " + category); // send echo response string echo = createjsonmessage(from, nextmessageid(), payload, "echo:collapsekey", null, false); seek { senddownstreammessage(echo); } grab (notconnectedexception e) { logger.log(level.warning, "not connected anymore, echo message not sent", e); } } /** * handles ack. * * <p>logs info message, subclasses override * handle acks. */ protected void handleackreceipt(map<string, object> jsonobject) { string messageid = (string) jsonobject.get("message_id"); string = (string) jsonobject.get("from"); logger.log(level.info, "handleackreceipt() from: " + + ", messageid: " + messageid); } /** * handles nack. * * <p>logs info message, subclasses override * handle nacks. */ protected void handlenackreceipt(map<string, object> jsonobject) { string messageid = (string) jsonobject.get("message_id"); string = (string) jsonobject.get("from"); logger.log(level.info, "handlenackreceipt() from: " + + ", messageid: " + messageid); } protected void handlecontrolmessage(map<string, object> jsonobject) { logger.log(level.info, "handlecontrolmessage(): " + jsonobject); string controltype = (string) jsonobject.get("control_type"); if ("connection_draining".equals(controltype)) { connectiondraining = true; } else { logger.log(level.info, "unrecognized command type: %s. ", controltype); } } /** * creates json encoded gcm message. * * @param registrationid of target device (required). * @param messageid unique messageid ccs send * "ack/nack" (required). * @param payload message content intended application. (optional). * @param collapsekey gcm collapse_key parameter (optional). * @param timetolive gcm time_to_live parameter (optional). * @param delaywhileidle gcm delay_while_idle parameter (optional). * @return json encoded gcm message. */ public static string createjsonmessage(string to, string messageid, map<string, string> payload, string collapsekey, long timetolive, boolean delaywhileidle) { map<string, object> message = new hashmap<string, object>(); message.put("to", to); if (collapsekey != null) { message.put("collapse_key", collapsekey); } if (timetolive != null) { message.put("time_to_live", timetolive); } if (delaywhileidle != null && delaywhileidle) { message.put("delay_while_idle", true); } message.put("message_id", messageid); message.put("data", payload); homecoming jsonvalue.tojsonstring(message); } /** * creates json encoded ack message upstream message received * application. * * @param registrationid of device sent upstream message. * @param messageid messageid of upstream message acknowledged ccs. * @return json encoded ack. */ protected static string createjsonack(string to, string messageid) { map<string, object> message = new hashmap<string, object>(); message.put("message_type", "ack"); message.put("to", to); message.put("message_id", messageid); homecoming jsonvalue.tojsonstring(message); } /** * connects gcm cloud connection server using supplied credentials. * */ public void connect()throws xmppexception, ioexception, smackexception { connectionconfiguration config = new connectionconfiguration(gcm_server, gcm_port); config.setsecuritymode(securitymode.enabled); config.setreconnectionallowed(true); config.setrosterloadedatlogin(false); config.setsendpresence(false); config.setsocketfactory(sslsocketfactory.getdefault()); connection = new xmpptcpconnection(config); connection.connect(); connection.addconnectionlistener(new loggingconnectionlistener()); // handle incoming packets connection.addpacketlistener(new packetlistener() { @override public void processpacket(packet packet) { logger.log(level.info, "received: " + packet.toxml()); message incomingmessage = (message) packet; gcmpacketextension gcmpacket = (gcmpacketextension) incomingmessage. getextension(gcm_namespace); string json = gcmpacket.getjson(); seek { @suppresswarnings("unchecked") map<string, object> jsonobject = (map<string, object>) jsonvalue. parsewithexception(json); // nowadays "ack"/"nack", null otherwise object messagetype = jsonobject.get("message_type"); if (messagetype == null) { // normal upstream info message handleupstreammessage(jsonobject); // send ack ccs string messageid = (string) jsonobject.get("message_id"); string = (string) jsonobject.get("from"); string ack = createjsonack(from, messageid); send(ack); } else if ("ack".equals(messagetype.tostring())) { // process ack handleackreceipt(jsonobject); } else if ("nack".equals(messagetype.tostring())) { // process nack handlenackreceipt(jsonobject); } else if ("control".equals(messagetype.tostring())) { // process command message handlecontrolmessage(jsonobject); } else { logger.log(level.warning, "unrecognized message type (%s)", messagetype.tostring()); } } grab (parseexception e) { logger.log(level.severe, "error parsing json " + json, e); } grab (exception e) { logger.log(level.severe, "failed process packet", e); } } }, new packettypefilter(message.class)); // log outgoing packets connection.addpacketinterceptor(new packetinterceptor() { @override public void interceptpacket(packet packet) { logger.log(level.info, "sent: {0}", packet.toxml()); } }, new packettypefilter(message.class)); connection.login(mprojectid + "@gcm.googleapis.com", mapikey); } /** * xmpp packet extension gcm cloud connection server. */ private static final class gcmpacketextension extends defaultpacketextension { private final string json; public gcmpacketextension(string json) { super(gcm_element_name, gcm_namespace); this.json = json; } public string getjson() { homecoming json; } @override public string toxml() { homecoming string.format("<%s xmlns=\"%s\">%s</%s>", gcm_element_name, gcm_namespace, stringutils.escapeforxml(json), gcm_element_name); } public packet topacket() { message message = new message(); message.addextension(this); homecoming message; } } private static final class loggingconnectionlistener implements connectionlistener { @override public void connected(xmppconnection xmppconnection) { logger.info("connected."); } @override public void authenticated(xmppconnection xmppconnection) { logger.info("authenticated."); } @override public void reconnectionsuccessful() { logger.info("reconnecting.."); } @override public void reconnectionfailed(exception e) { logger.log(level.info, "reconnection failed.. ", e); } @override public void reconnectingin(int seconds) { logger.log(level.info, "reconnecting in %d secs", seconds); } @override public void connectionclosedonerror(exception e) { logger.info("connection closed on error."); } @override public void connectionclosed() { logger.info("connection closed."); } } }

at client side calling endpoint in asynctask -

protected string doinbackground(object... params) { if(messageservice == null){ smackappserver.builder builder = new smackappserver.builder(androidhttp.newcompatibletransport(), new androidjsonfactory(), null); messageservice = builder.build(); seek { messageservice.connectxmpserver(gcmsenderid, password, true).execute(); } grab (ioexception e) { e.printstacktrace(); string logmsg; logmsg = "error while connecting : " + e.getmessage(); homecoming logmsg; } } context = (context)params[0]; message = (string)params[1]; if (gcm == null) { gcm = googlecloudmessaging.getinstance(context); } string logmsg; /* if(!connected) { seek { messageservice.connect(senderid, password).execute(); connected = true; logmsg = "connection established!"; } grab (ioexception e) { e.printstacktrace(); logmsg = "error while connecting! " + e.getmessage(); homecoming logmsg; } }*/ string id = integer.tostring(msgid.incrementandget()); bundle info = new bundle(); // bundle info consists of key-value pair data.putstring("message", message); // "time live" parameter // optional. specifies value in seconds 24 hours. seek { gcm.send(gcmsenderid + "@gcm.googleapis.com", id, data); logmsg = "message sent!"; } grab (ioexception e) { e.printstacktrace(); logmsg = "error while sending message! " + e.getmessage(); } homecoming logmsg; }

however calls leads exception. clueless whats going wrong here.

com.google.api.server.spi.systemservice invokeservicemethod: null java.lang.exceptionininitializererror @ org.jivesoftware.smack.connectionconfiguration.<init>(connectionconfiguration.java:67) @ com.example.mymodule.xmppserver.smackccsclientendpoint.connect(smackccsclientendpoint.java:255) @ com.example.mymodule.xmppserver.smackccsclientendpoint.prepareclient(smackccsclientendpoint.java:75) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:45) @ com.google.api.server.spi.systemservice.invokeservicemethod(systemservice.java:359) @ com.google.api.server.spi.systemserviceservlet.execute(systemserviceservlet.java:160) @ com.google.api.server.spi.systemserviceservlet.dopost(systemserviceservlet.java:118) @ javax.servlet.http.httpservlet.service(httpservlet.java:637) @ javax.servlet.http.httpservlet.service(httpservlet.java:717) @ org.mortbay.jetty.servlet.servletholder.handle(servletholder.java:511) @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1166) @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157) @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157) @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157) @ org.mortbay.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler.java:1157) @ org.mortbay.jetty.servlet.servlethandler.handle(servlethandler.java:388) @ org.mortbay.jetty.security.securityhandler.handle(securityhandler.java:216) @ org.mortbay.jetty.servlet.sessionhandler.handle(sessionhandler.java:182) @ org.mortbay.jetty.handler.contexthandler.handle(contexthandler.java:765) @ org.mortbay.jetty.webapp.webappcontext.handle(webappcontext.java:418) @ org.mortbay.jetty.handler.handlerwrapper.handle(handlerwrapper.java:152) @ org.mortbay.jetty.server.handle(server.java:326) @ org.mortbay.jetty.httpconnection.handlerequest(httpconnection.java:542) @ org.mortbay.jetty.httpconnection$requesthandler.headercomplete(httpconnection.java:923) @ org.mortbay.jetty.httpconnection.handle(httpconnection.java:404) @ com.google.tracing.tracecontext$tracecontextrunnable.runincontext(tracecontext.java:438) @ com.google.tracing.tracecontext$tracecontextrunnable$1.run(tracecontext.java:445) @ com.google.tracing.currentcontext.runincontext(currentcontext.java:220) @ com.google.tracing.tracecontext$abstracttracecontextcallback.runininheritedcontextnounref(tracecontext.java:309) @ com.google.tracing.tracecontext$abstracttracecontextcallback.runininheritedcontext(tracecontext.java:301) @ com.google.tracing.tracecontext$tracecontextrunnable.run(tracecontext.java:442) @ java.lang.thread.run(thread.java:724) caused by: java.lang.illegalstateexception: org.xmlpull.v1.xmlpullparserexception: not load mill class (even little or total default implementation); nested exception is: org.kxml2.io.xmlreader @ org.jivesoftware.smack.smackconfiguration.<clinit>(smackconfiguration.java:158) ... 35 more caused by: org.xmlpull.v1.xmlpullparserexception: not load mill class (even little or total default implementation); nested exception is: org.kxml2.io.xmlreader @ org.xmlpull.v1.xmlpullparserfactory.newinstance(xmlpullparserfactory.java:225) @ org.xmlpull.v1.xmlpullparserfactory.newinstance(xmlpullparserfactory.java:76) @ org.jivesoftware.smack.smackconfiguration.processconfigfile(smackconfiguration.java:352) @ org.jivesoftware.smack.smackconfiguration.processconfigfile(smackconfiguration.java:347) @ org.jivesoftware.smack.smackconfiguration.<clinit>(smackconfiguration.java:155) ... 35 more

at server side, original piece of code within static block. parser.nexttext giving compile error. downloded latest xmlpullparser jar , replace phone call parser.gettext. possible cause?

original server code -

static { providermanager.addextensionprovider(gcm_element_name, gcm_namespace, new packetextensionprovider() { @override public packetextension parseextension(xmlpullparser parser) throws exception { string json = parser.nexttext(); homecoming new gcmpacketextension(json); } }); }

please help me. not able proceed stuck @ basic level.

regards, shailesh

i downloaded jar xpp3 , added dependencies in android studio backend module. not come bundled smack api longer.

google-app-engine xmpp google-cloud-messaging google-cloud-endpoints smack

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -