abdera-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James M Snell <jasn...@gmail.com>
Subject Re: Google Data APIs and chunked encoding
Date Thu, 05 Oct 2006 16:31:45 GMT

Ugo Cei wrote:
> Folks,
> after having banged my head against the wall for a few hours, I finally
> managed to post an entry to Google Calendar using the Google Data API
> and Abdera (svn trunk). Here's what I discovered and some suggestions:
> 1. Google Data has this pesky authentication mechanism that requires you
> to post a request to a given URL including your credentials as
> parameters and you get back a token in a text reply that you have to
> parse. Of course, this is not Atom, so Abdera is not of much help here.

If you look in the Extensions module there is an implementation of the
GoogleLogin scheme that can be used with Abdera's client.

First, register the scheme:


Then, set your credentials. There are two possible ways of doing this:

Using the commons httpclient's UsernamePasswordCredentials:

 Client client = new CommonsClient();
   null, "GoogleLogin",
   new UsernamePasswordCredentials(

Which ends up doing the GoogleLogin authentication on every request,
which is horribly inefficient if you're doing multiple requests.

The other way is to use the GoogleLoginAuthCredentials:

 Client client = new CommonsClient();

 GoogleLoginAuthCredentials credentials =
   new GoogleLoginAuthCredentials(
     "email", "password", "blogger");

   null, null,

This will perform the GoogleLogin once and reuse the auth token for each

> 2. Google expects a Content-Length header when posting an entry. I found
> no better way (admittedly I didn't spend much time on this) than to
> write my entry to a byte array and count its size. Hardly optimal, and I
> wonder whether there's a better way.

Try this:

  client.post(new BaseRequestEntity(entry,false));

The BaseRequestEntity is what is used under the covers to post the entry
via the commons http client.  This variation of the post will tell the
BaseRequestEntity to set the Content-Length header.

> 3. Google doesn't seem to like postings in chuked encoding format. Took
> a while to figure this one out, since the only reply I got was "400 Bad
> Request". Abdera, on the other hand, insists on chunking the output
> (BaseRequestEntity has a constructor that allows you to specifiy whether
> you want it chunked or not, but Client always invokes the constructor
> that leaves the parameter to its default, "true" value.

(heh.. note to self: read the entire note before commenting)

> Regarding point #3 above, I think it would be nice to let the user
> decide whether he wants chunked or not, even though this should maybe be
> negotiated at the HTTP level, so it might be a problem in HttpClient or
> Google, I don't know.

This could be made an option on the RequestOptions interface.  Patches
welcome ;-)


- James

View raw message