Viewing raw XML traffic when using Google Data Java Client APIs

The Google Data Java Client APIs provide a convenient way for Java prorgams to interface with Google’s public Data APIs, for Google calendars, contacts, and many other services.

It’s such a good abstraction, however, there is no clear way of seeing the underlying XML of the feed. When debugging, and for their interest, programmers may wish to see this data – it’s supposed to be human-readable after all.

After at least an hour of playing around I found the commands to enable the logging in the client’s initialization. Traffic will then be output to the console at run time.

The gotcha is that enabling verbose output on Java’s logging requires not just the logs to be set to Level.ALL, but also the underlying handlers.

Here’s the code.

  1. import java.util.logging.Logger;
  2. import com.google.gdata.client.http.GoogleGDataRequest;
  3. import com.google.gdata.client.http.HttpGDataRequest;
  1. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).getParent().getHandlers()[0].setLevel(Level.ALL);
  2. Logger.getLogger(GoogleGDataRequest.class.getName()).setLevel(Level.ALL);
  3. Logger.getLogger(HttpGDataRequest.class.getName()).setLevel(Level.ALL);

Reply

Your email address will not be published. Required fields are marked *