Java Reference
In-Depth Information
String msgBody = "App Engine is pretty cool. I can't believe it's
this easy to send XMPP!";
Message msg = new MessageBuilder()
.withRecipientJids(jid)
.withBody(msgBody)
.build();
boolean messageSent = false;
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
if (xmpp.getPresence(jid).isAvailable()) {
SendResponse status = xmpp.sendMessage(msg);
messageSent = (status.getStatusMap().get(jid) ==
SendResponse.Status.SUCCESS);
}
if (!messageSent) {
// do something
}
}
}
There's not much to it. You're creating an instance of the XMPPService and using the
com.google.appengine.api.xmpp.JID class to define the Jabber ID that will be
receiving your message. Save this servlet after putting your own Gmail ID in place of
put your gmail account here. Deploy the project to App Engine. Don't forget to map
your servlet in your web.xml file. Once you land on the page, if you've already added
the application to your friend list, you should get an instant message right away. An
example message is displayed in Figure 8-10.
Figure 8-10. XMPP Message received from App Engine
 
Search WWH ::




Custom Search