Google sites API, IllegalArgumentException("Trying to set foreign cookie") after RedirectRequiredException

Viewed 361

I am using the gdata-media-1.0-1.47.1.jar functionality to fetch media data using the com.google.gdata.client.media.MediaService.getMedia(IMediaContent mediaContent) method. For some requests I get a RedirectRequiredException. When I redo the getMedia request, using the url i get from RedirectRequiredException.getRedirectLocation(), I get an IllegalArgumentException("Trying to set foreign cookie") exception.

From what I can see, the reason for this is that the domain in the response header for the cookie doesn't match the domain of the redirect location. In com.google.gdata.client.http.GoogleGDataRequest.matchDomain() the first argument is ".docs.google.com" and the second is "docs.google.com" which makes the domain matching fail.

Is this a correct behaviour? Why is this happening? Is there something I can do about this? Am I doing anything wrong here? Is is possible to avoid this problem?

SitesService sitesService = new SitesService("SomeAppName");
try {
    MediaContent mc = new MediaContent();
    mc.setUri(aURI);
    return sitesService.getMedia(mc);
} catch (RedirectRequiredException e) {
    MediaContent mc = new MediaContent();
    mc.setUri(e.getRedirectLocation());
    return sitesService.getMedia(mc);
}
0 Answers
Related