artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

NullPointerException with schema-less redirect #198

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Version of google-http-java-client (e.g. 1.5.0-beta)?

1.12.0-beta

Java environment (e.g. Java 6, Android 2.3, App Engine)?

Android 4.1.2

Describe the problem.

When loading a URL from google plus, I receive a redirect with a location 
header which doesnt contain a full URL such as 

/redirect/index.html

HttpRequest.handleRedirect
(line 1085) creates a new GenericUrl object with this relative location (see 
below)

  public boolean handleRedirect(int statusCode, HttpHeaders headers) {
    String redirectLocation = headers.getLocation();
    if (getFollowRedirects() && HttpStatusCodes.isRedirect(statusCode)
        && redirectLocation != null) {
=>      setUrl(new GenericUrl(redirectLocation));

      if (statusCode == HttpStatusCodes.STATUS_CODE_SEE_OTHER) {
        setRequestMethod(HttpMethods.GET);
      }
      return true;
    }
    return false;
  }

GenericUrl on its own tries to parse the URL Scheme

  public GenericUrl(String encodedUrl) {
    URI uri;
    try {
      uri = new URI(encodedUrl);
    } catch (URISyntaxException e) {
      throw new IllegalArgumentException(e);
    }
==>    scheme = uri.getScheme().toLowerCase();

since the scheme in this case returns null, this line blows up.

How would you expect it to be fixed?

I would expect that local redirects would expand the whole host name and build 
a fully qualified URL to process further.

See log with callstack below

E/Crittercism( 1493):   at 
com.google.api.client.http.GenericUrl.<init>(GenericUrl.java:104)
E/Crittercism( 1493):   at 
com.google.api.client.http.HttpRequest.handleRedirect(HttpRequest.java:1085)
E/Crittercism( 1493):   at 
com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1016)

Original issue reported on code.google.com by rbur...@gmail.com on 7 Feb 2013 at 9:58

GoogleCodeExporter commented 9 years ago

Original comment by ngmic...@google.com on 20 Feb 2013 at 3:41

GoogleCodeExporter commented 9 years ago

Original comment by yan...@google.com on 11 Mar 2013 at 11:58