|
1 |
| -/** |
| 1 | +/* |
2 | 2 | * Copyright 2016 Google Inc. All Rights Reserved.
|
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
|
16 | 16 |
|
17 | 17 | package com.example.appengine.xmpp;
|
18 | 18 |
|
19 |
| -import java.io.IOException; |
20 |
| -import java.util.logging.Logger; |
21 |
| -import javax.servlet.http.*; |
22 | 19 | import com.google.appengine.api.xmpp.Presence;
|
23 | 20 | import com.google.appengine.api.xmpp.PresenceType;
|
24 | 21 | import com.google.appengine.api.xmpp.XMPPService;
|
25 | 22 | import com.google.appengine.api.xmpp.XMPPServiceFactory;
|
26 | 23 |
|
| 24 | +import java.io.IOException; |
| 25 | +import java.util.logging.Logger; |
| 26 | + |
| 27 | +import javax.servlet.http.HttpServlet; |
| 28 | +import javax.servlet.http.HttpServletRequest; |
| 29 | +import javax.servlet.http.HttpServletResponse; |
| 30 | + |
27 | 31 | // [START example]
|
28 | 32 | @SuppressWarnings("serial")
|
29 | 33 | public class PresenceServlet extends HttpServlet {
|
| 34 | + private static final Logger log = Logger.getLogger(PresenceServlet.class.getName()); |
30 | 35 |
|
31 |
| - private static final Logger log = Logger.getLogger(PresenceServlet.class.getName()); |
32 |
| - |
33 |
| - @Override |
34 |
| - public void doPost(HttpServletRequest req, HttpServletResponse res) |
35 |
| - throws IOException { |
| 36 | + @Override |
| 37 | + public void doPost(HttpServletRequest req, HttpServletResponse res) |
| 38 | + throws IOException { |
36 | 39 |
|
37 |
| - XMPPService xmpp = XMPPServiceFactory.getXMPPService(); |
38 |
| - Presence presence = xmpp.parsePresence(req); |
| 40 | + XMPPService xmpp = XMPPServiceFactory.getXMPPService(); |
| 41 | + Presence presence = xmpp.parsePresence(req); |
39 | 42 |
|
40 |
| - // Split the XMPP address (e.g., [email protected]) |
41 |
| - // from the resource (e.g., gmail.CD6EBC4A) |
42 |
| - String from = presence.getFromJid().getId().split("/")[0]; |
| 43 | + // Split the XMPP address (e.g., [email protected]) |
| 44 | + // from the resource (e.g., gmail.CD6EBC4A) |
| 45 | + String from = presence.getFromJid().getId().split("/")[0]; |
43 | 46 |
|
44 |
| - log.info("Received presence from: " + from); |
| 47 | + log.info("Received presence from: " + from); |
45 | 48 |
|
46 |
| - // Mirror the contact's presence back to them |
47 |
| - xmpp.sendPresence(presence.getFromJid(), PresenceType.AVAILABLE, presence.getPresenceShow(), presence.getStatus()); |
48 |
| - } |
| 49 | + // Mirror the contact's presence back to them |
| 50 | + xmpp.sendPresence( |
| 51 | + presence.getFromJid(), |
| 52 | + PresenceType.AVAILABLE, |
| 53 | + presence.getPresenceShow(), |
| 54 | + presence.getStatus()); |
| 55 | + } |
49 | 56 | }
|
50 | 57 | // [END example]
|
0 commit comments