Real-time error monitoring in Google app engine

Yesterday, I showed you how your Google app engine application can send a mail whenever an error occurs (an uncaught Exception for example).

Today we are going to see how to monitor your application in real-time using Google talk.

Of course, the Google talk client has a little icon that tells you how many unread emails you have:

But that’s not enough: we want the GAE application to send a “google talk message” each time an error occurs. This can easily be done using the XMPP service.

First, we define a servlet to handle all exceptions:


And here is the code for the servlet:

public class ShowError extends HttpServlet {

  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // note that 't' cannot be null since this servlet is defined as the error handler in web.xml:
    Throwable t = (Throwable) req.getAttribute("javax.servlet.error.exception");
    JID jid = new JID("");
    String msgBody = "an error occured: " + t.getMessage();
    Message msg = new MessageBuilder()
    boolean isSent = false;
    XMPPService xmpp = XMPPServiceFactory.getXMPPService();
    if (xmpp.getPresence(jid).isAvailable()) {
      SendResponse status = xmpp.sendMessage(msg);
      isSent = (status.getStatusMap().get(jid) == SendResponse.Status.SUCCESS);
    if (!isSent) {
      // error handling
    getServletContext().getRequestDispatcher("/WEB-INF/jsp/error.jsp").forward(req, resp);

In the code sample above, “” is the email of an administrator of the GAE application: replace it with yours !

Now you need to invite your GAE application from the Google talk client (exactly like you would invite a friend using his email). To do this, just invite [APPLICATION_IDENTIFIER] In my case, my application is so I need to invite

Now generate an exception in your application so that the error servlet is invoked and you will receive an instant notification:



About lkubaski

2 Responses to Real-time error monitoring in Google app engine

  1. learncomputeradmin says:

    Thanks, this is really useful. Makes Google Talk a little more useful.

  2. Pingback: Best Of The Week – 2012 – W07 | Java Code Geeks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: