SilverHoodCorp / gdata-java-client

Automatically exported from code.google.com/p/gdata-java-client
Apache License 2.0
0 stars 0 forks source link

RedirectRequiredException running CalendarTest sample #123

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Install gdata (and prereqs) for Java
2. Run sample calendar test found at
http://code.google.com/apis/gdata/articles/java_client_lib.html#helloworld
3.

What is the expected output? What do you see instead?
Expect a list of Calendar names.  Get an exception of the form:

Exception in thread "main" com.google.gdata.util.RedirectRequiredException:
Moved Temporarily
<HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A
HREF="http://www.google.com/calendar/feeds/default/allcalendars/full?gsessionid=
xxxxsessionidxxxx">here</A>.
</BODY>
</HTML>

    at
com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataR
equest.java:560)
    at
com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.jav
a:481)
    at
com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:460)
    at
com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:
534)
    at com.google.gdata.client.Service.getFeed(Service.java:962)
    at com.google.gdata.client.Service.getFeed(Service.java:819)
    at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:600)
    at com.google.gdata.client.Service.getFeed(Service.java:838)
    at CalTest.main(CalTest.java:23)

What version of the product are you using? On what operating system?
GData v1.30.0
Mac OS X 10.5.6

Please provide any additional information below.
While it is true that the example mentions it has no exception handling it
is a bit of an obstacle for first-timers to have to hunt down how to deal
with a redirect.  Other than this wart, the getting started section got me
up and running very smoothly.  Something like the following worked for me:

    public static void main(String[] args) throws IOException, ServiceException
    {
        CalendarService cs = new CalendarService("sample");
        cs.setUserCredentials("username@gmail.com", "password");

        URL feedUrl = new
URL("http://google.com/calendar/feeds/default/allcalendars/full");

        CalendarFeed feed = null;
        try
        {
            feed = cs.getFeed(feedUrl, CalendarFeed.class);
        }
        catch (RedirectRequiredException re)
        {
            feedUrl = new URL(re.getRedirectLocation());
            feed = cs.getFeed(feedUrl, CalendarFeed.class);
        }

        for (CalendarEntry entry : feed.getEntries())
        {
            System.out.println(entry.getTitle().getPlainText());
        }
    }

Original issue reported on code.google.com by michael....@gmail.com on 13 Apr 2009 at 2:49

GoogleCodeExporter commented 9 years ago
Micheal,
    The client library automatically handles 1 redirect
(http://code.google.com/p/gdata-java-client/source/browse/trunk/java/src/com/goo
gle/gdata/client/GoogleService.java#600).
 If there are more than 1 redirects, then the exception is thrown.  Somehow you hit
more than 1 redirect (either connecting through a proxy or something similar).
Handling redirects in sample code may lead to potentially looping behavior 
(because
of bad proxy).  So this is intended.  

    But I agree that it needs to be documented better.  started a FAQ wiki page to
help future users
(http://code.google.com/p/gdata-java-client/wiki/FAQ?ts=1239632032&updated=FAQ#H
ow_to_handle_com.google.gdata.util._RedirectRequiredException).

Cheers.

Original comment by vbarat...@gmail.com on 13 Apr 2009 at 2:14

GoogleCodeExporter commented 9 years ago
Understood. That makes sense.  Thanks much.

Original comment by michael....@gmail.com on 13 Apr 2009 at 2:22