Viewing raw XML traffic when using Google Data Java Client APIs
Posted by jimblackler on Oct 23, 2008
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.
- import java.util.logging.Logger;
- import com.google.gdata.client.http.GoogleGDataRequest;
- import com.google.gdata.client.http.HttpGDataRequest;
- Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).getParent().getHandlers()[0].setLevel(Level.ALL);
- Logger.getLogger(GoogleGDataRequest.class.getName()).setLevel(Level.ALL);
- Logger.getLogger(HttpGDataRequest.class.getName()).setLevel(Level.ALL);