Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checkstyle errors in XMPP sample. #184

Merged
merged 1 commit into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Expand All @@ -16,30 +16,32 @@

package com.example.appengine.xmpp;

import com.google.common.io.ByteStreams;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.logging.Logger;

import javax.servlet.ServletInputStream;
import javax.servlet.http.*;
import com.google.common.io.ByteStreams;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

// [START example]
@SuppressWarnings("serial")
public class ErrorServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(ErrorServlet.class.getName());

private static final Logger log = Logger.getLogger(ErrorServlet.class.getName());

@Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {

// Parse the POST data, which is sent as a MIME stream containing the stanza.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ServletInputStream inputStream = req.getInputStream();
ByteStreams.copy(inputStream, baos);
@Override
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException {
// Parse the POST data, which is sent as a MIME stream containing the stanza.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ServletInputStream inputStream = req.getInputStream();
ByteStreams.copy(inputStream, baos);

// Log the error
log.warning("Error stanza received: " + baos.toString());
}
// Log the error
log.warning("Error stanza received: " + baos.toString());
}
}
// [END example]
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");
Expand All @@ -16,32 +16,35 @@

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.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 MessageReceiverServlet extends HttpServlet {
private static final Logger log = Logger.getLogger(MessageReceiverServlet.class.getName());

private static final Logger log = Logger.getLogger(MessageReceiverServlet.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();
Message message = xmpp.parseMessage(req);
XMPPService xmpp = XMPPServiceFactory.getXMPPService();
Message message = xmpp.parseMessage(req);

JID fromJid = message.getFromJid();
String body = message.getBody();
JID fromJid = message.getFromJid();
String body = message.getBody();

log.info("Received a message with id: " + fromJid + " and body: " + body);
// ...
}
log.info("Received a message with id: " + fromJid + " and body: " + body);
// ...
}
}
// [END example]
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");
Expand All @@ -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]
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");
Expand All @@ -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]
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");
Expand All @@ -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]
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
<module>appengine/twilio</module>
<module>appengine/urlfetch</module>
<module>appengine/users</module>
<module>appengine/xmpp</module>
<module>bigquery</module>
<module>compute/cmdline</module>
<module>datastore</module>
Expand Down