Closed GoogleCodeExporter closed 9 years ago
setting HttpRequestInitializer to attach an UnsuccessfulResponseHandler which
reattaches the oauth token to the redirect url seems to get around the issue
this.storage = new Storage.Builder(getHttpTransport(), JSON_FACTORY, new
HttpRequestInitializer() {
public void initialize(HttpRequest request) {
request.setUnsuccessfulResponseHandler(new RedirectHandler());
}
})
.setApplicationName(Constants.APP_NAME).build();
public class RedirectHandler implements HttpUnsuccessfulResponseHandler {
private static final String OAUTH_TOKEN_PARAM = "?oauth_token=";
/*
* (non-Javadoc)
* @see com.google.api.client.http.HttpUnsuccessfulResponseHandler#handleResponse(
* com.google.api.client.http.HttpRequest, com.google.api.client.http.HttpResponse, boolean)
*/
public boolean handleResponse(
HttpRequest request, HttpResponse response, boolean retrySupported) throws IOException {
if (response.getStatusCode() == HttpStatusCodes.STATUS_CODE_TEMPORARY_REDIRECT) {
String redirectLocation = response.getHeaders().getLocation();
if (request.getFollowRedirects() && redirectLocation != null) {
String url = request.getUrl().toString();
String oauthToken = StringUtils.substringAfterLast(url, OAUTH_TOKEN_PARAM);
// resolve the redirect location relative to the current location
// re-append the oauth token request parameter
request.setUrl(new GenericUrl(request.getUrl().toURL(redirectLocation + OAUTH_TOKEN_PARAM + oauthToken)));
return true;
}
}
return false;
}
}
Original comment by omer.daw...@gmail.com
on 6 Apr 2014 at 12:27
This seems to be working fine in the API v1 cloud storage library. Can be closed
Original comment by omer.daw...@gmail.com
on 23 Dec 2014 at 9:12
Original comment by wonder...@google.com
on 30 Dec 2014 at 4:45
Original issue reported on code.google.com by
omer.daw...@gmail.com
on 6 Apr 2014 at 10:15Attachments: