📜 ⬆️ ⬇️

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

About release 1.4.2 of the SDK version has already been written on Habré , but I’m interested in the changes in the second version of XMPP API



Also, I remind you about the topic of the first version of the XMPP API .

')
Javadok on API has noticeably grown fat.

The service can now respond to authorization requests and change the status of interlocutors.

These functions are included in the same way as the inbox service using the appengine-web.xml file:

 <inbound-services> <service>xmpp_message</service> <service>xmpp_presence</service> <service>xmpp_subscribe</service> </inbound-services> 


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

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

"Authorization Events"
" / _ah / xmpp / subscription / subscribe / " - the interlocutor wants to log in
" / _ah / xmpp / subscription / subscribed / " - the interlocutor has authorized the application
" / _ah / xmpp / subscription / unsubscribe / " - the interlocutor revoked the application authorization
" / _ah / xmpp / subscription / unsubscribed / " - interlocutor rejected invitation to authorize

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

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

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

For all three types of events, there are parsers that will help you parse the query:

 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, and lastly, we set our application status:
 xmppService.sendPresence(toJid, PresenceType.AVAILABLE, PresenceShow.NONE, "My app's status") 

Source: https://habr.com/ru/post/113806/


All Articles