-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix checkstyle errors in XMPP sample. (#184)
Add XMPP sample to Travis build.
- Loading branch information
Showing
6 changed files
with
106 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
/* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -16,43 +16,47 @@ | |
|
||
package com.example.appengine.xmpp; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
import javax.servlet.http.*; | ||
import com.google.appengine.api.xmpp.JID; | ||
import com.google.appengine.api.xmpp.Message; | ||
import com.google.appengine.api.xmpp.MessageBuilder; | ||
import com.google.appengine.api.xmpp.SendResponse; | ||
import com.google.appengine.api.xmpp.XMPPService; | ||
import com.google.appengine.api.xmpp.XMPPServiceFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
// [START example] | ||
@SuppressWarnings("serial") | ||
public class MessageSenderServlet extends HttpServlet { | ||
private static final Logger log = Logger.getLogger(MessageSenderServlet.class.getName()); | ||
|
||
private static final Logger log = Logger.getLogger(MessageSenderServlet.class.getName()); | ||
|
||
@Override | ||
public void doGet(HttpServletRequest req, HttpServletResponse res) | ||
throws IOException { | ||
@Override | ||
public void doGet(HttpServletRequest req, HttpServletResponse res) | ||
throws IOException { | ||
|
||
JID jid = new JID("[email protected]"); | ||
String msgBody = "Someone has sent you a gift on Example.com. To view: http://example.com/gifts/"; | ||
Message msg = new MessageBuilder() | ||
JID jid = new JID("[email protected]"); | ||
String msgBody = "Someone has sent you a gift on Example.com. To view: http://example.com/gifts/"; | ||
Message msg = | ||
new MessageBuilder() | ||
.withRecipientJids(jid) | ||
.withBody(msgBody) | ||
.build(); | ||
|
||
boolean messageSent = false; | ||
XMPPService xmpp = XMPPServiceFactory.getXMPPService(); | ||
SendResponse status = xmpp.sendMessage(msg); | ||
messageSent = (status.getStatusMap().get(jid) == SendResponse.Status.SUCCESS); | ||
boolean messageSent = false; | ||
XMPPService xmpp = XMPPServiceFactory.getXMPPService(); | ||
SendResponse status = xmpp.sendMessage(msg); | ||
messageSent = (status.getStatusMap().get(jid) == SendResponse.Status.SUCCESS); | ||
|
||
log.info("Message sent? " + messageSent); | ||
log.info("Message sent? " + messageSent); | ||
|
||
if (!messageSent) { | ||
// Send an email message instead... | ||
} | ||
if (!messageSent) { | ||
// Send an email message instead... | ||
} | ||
} | ||
} | ||
// [END example] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
/* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -16,35 +16,42 @@ | |
|
||
package com.example.appengine.xmpp; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
import javax.servlet.http.*; | ||
import com.google.appengine.api.xmpp.Presence; | ||
import com.google.appengine.api.xmpp.PresenceType; | ||
import com.google.appengine.api.xmpp.XMPPService; | ||
import com.google.appengine.api.xmpp.XMPPServiceFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
// [START example] | ||
@SuppressWarnings("serial") | ||
public class PresenceServlet extends HttpServlet { | ||
private static final Logger log = Logger.getLogger(PresenceServlet.class.getName()); | ||
|
||
private static final Logger log = Logger.getLogger(PresenceServlet.class.getName()); | ||
|
||
@Override | ||
public void doPost(HttpServletRequest req, HttpServletResponse res) | ||
throws IOException { | ||
@Override | ||
public void doPost(HttpServletRequest req, HttpServletResponse res) | ||
throws IOException { | ||
|
||
XMPPService xmpp = XMPPServiceFactory.getXMPPService(); | ||
Presence presence = xmpp.parsePresence(req); | ||
XMPPService xmpp = XMPPServiceFactory.getXMPPService(); | ||
Presence presence = xmpp.parsePresence(req); | ||
|
||
// Split the XMPP address (e.g., [email protected]) | ||
// from the resource (e.g., gmail.CD6EBC4A) | ||
String from = presence.getFromJid().getId().split("/")[0]; | ||
// Split the XMPP address (e.g., [email protected]) | ||
// from the resource (e.g., gmail.CD6EBC4A) | ||
String from = presence.getFromJid().getId().split("/")[0]; | ||
|
||
log.info("Received presence from: " + from); | ||
log.info("Received presence from: " + from); | ||
|
||
// Mirror the contact's presence back to them | ||
xmpp.sendPresence(presence.getFromJid(), PresenceType.AVAILABLE, presence.getPresenceShow(), presence.getStatus()); | ||
} | ||
// Mirror the contact's presence back to them | ||
xmpp.sendPresence( | ||
presence.getFromJid(), | ||
PresenceType.AVAILABLE, | ||
presence.getPresenceShow(), | ||
presence.getStatus()); | ||
} | ||
} | ||
// [END example] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/** | ||
/* | ||
* Copyright 2016 Google Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
|
@@ -16,31 +16,33 @@ | |
|
||
package com.example.appengine.xmpp; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
import javax.servlet.http.*; | ||
import com.google.appengine.api.xmpp.Subscription; | ||
import com.google.appengine.api.xmpp.XMPPService; | ||
import com.google.appengine.api.xmpp.XMPPServiceFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.logging.Logger; | ||
|
||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
// [START example] | ||
@SuppressWarnings("serial") | ||
public class SubscriptionServlet extends HttpServlet { | ||
private static final Logger log = Logger.getLogger(SubscriptionServlet.class.getName()); | ||
|
||
private static final Logger log = Logger.getLogger(SubscriptionServlet.class.getName()); | ||
|
||
@Override | ||
public void doPost(HttpServletRequest req, HttpServletResponse res) | ||
throws IOException { | ||
|
||
XMPPService xmppService = XMPPServiceFactory.getXMPPService(); | ||
Subscription sub = xmppService.parseSubscription(req); | ||
@Override | ||
public void doPost(HttpServletRequest req, HttpServletResponse res) | ||
throws IOException { | ||
XMPPService xmppService = XMPPServiceFactory.getXMPPService(); | ||
Subscription sub = xmppService.parseSubscription(req); | ||
|
||
// Split the bare XMPP address (e.g., [email protected]) | ||
// from the resource (e.g., gmail.CD6EBC4A) | ||
String from = sub.getFromJid().getId().split("/")[0]; | ||
// Split the bare XMPP address (e.g., [email protected]) | ||
// from the resource (e.g., gmail.CD6EBC4A) | ||
String from = sub.getFromJid().getId().split("/")[0]; | ||
|
||
log.info("Received subscription event from: " + from); | ||
} | ||
log.info("Received subscription event from: " + from); | ||
} | ||
} | ||
// [END example] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters