GAE XMPP v.2 (Java SDK). Jabber in GAE from the second approach

    About release 1.4.2 SDK versions have already been written on Habré , but I am interested in the changes in the second version of the XMPP API . Also, I remind you about the topic about the first version of the XMPP API . Javadok on API noticeably grew fat. The service can now respond to authorization requests and changing the status of interlocutors. These functions are enabled in the same way as the incoming message service using a file:










    appengine-web.xml

    xmpp_messagexmpp_presencexmpp_subscribe


    xmpp_message - already familiar, incoming message service.
    xmpp_presence - message status service.
    xmpp_subscribe - service of authorization messages.

    All three services, when an event for which they are responsible appears, form a POST request to certain URLs:

    "Authorization events"
    " / _ah / xmpp / subscription / subscribe / " - the interlocutor wishes to log in
    " / _ah / xmpp / subscription / subscribed / "- the interlocutor of authorized applications
    " / _ah / xmpp / subscription / an unsubscribe / "- the interlocutor annulled authorization application
    " / _ah / xmpp / subscription / unsubscribed / "- the interlocutor rejected the invitation to sign in

    "Status changes"
    " / _ah / xmpp / presence / available / " - the interlocutor is online and supports status messages
    " / _ah / xmpp / presence / unavailable / " - the interlocutor is unavailable
    " / _ah / xmpp / presence / probe / " - a response to a request for the current status of the user

    "Incoming message"
    " / _ah / xmpp / message / chat / " - an incoming message has arrived

    If you plan to use any service, you need to map the servlet to the corresponding URL that will process POST requests. The request will contain all the necessary information.

    For all three types of events, there are parsers to help parse the request:

    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    Message message = xmpp.parseMessage(req); //входящее сообщение
    JID fromJid = message.getFromJid();
    String body = message.getBody();
    //...
    Presence presence = xmpp.parsePresence(req); //статус
    String from = presence.getFromJid().getId().split("/")[0]; //удаляем из JID source (то, что после "/")
    String status = presence.getStatus();
    //...
    Subscription sub = xmpp.parseSubscription(req); //подписка-авторизация
    String from = sub.getFromJid().getId().split("/")[0];
    //...


    Well, lastly, set your application status:
    xmppService.sendPresence(toJid, PresenceType.AVAILABLE, PresenceShow.NONE, "My app's status")

    Also popular now: