saravanan-vdg / oauth-signpost

Automatically exported from code.google.com/p/oauth-signpost
0 stars 0 forks source link

After Java upgrade: "Server returned HTTP response code: 411 for URL #60

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Recently i upgraded my java runtime from 1.6.0_14 to 1.6.0_22-b04 and my 
previously functional code stopped working. I'm using the latest signpost 
version 1.2.11.

Exception message is:

Exception in thread "main" 
oauth.signpost.exception.OAuthCommunicationException: Communication with the 
service provider failed: Server returned HTTP response code: 411 for URL: 
https://www.google.com
/accounts/OAuthGetRequestToken?scope=http%3A%2F%2Fpicasaweb.google.com%2Fdata%2F
&xoauth_displayname=Test
        at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:218)
        at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
        at oooo.Main.main(Main.java:31)
Caused by: java.io.IOException: Server returned HTTP response code: 411 for 
URL: 
https://www.google.com/accounts/OAuthGetRequestToken?scope=http%3A%2F%2Fpicasawe
b.google.com%2Fdata%2F&xoauth_displayna
me=Test

Code to reproduce:

        DefaultOAuthConsumer consumer = new DefaultOAuthConsumer("anonymous", "anonymous");

        String[] endPointURLs =
                new String[]{"https://www.google.com/accounts/OAuthGetRequestToken?" + "scope="
            + "http%3A%2F%2Fpicasaweb.google.com%2Fdata%2F" + "&xoauth_displayname="
            + "Test",
            "https://www.google.com/accounts/OAuthGetAccessToken",
            "https://www.google.com/accounts/OAuthAuthorizeToken"
        };
        DefaultOAuthProvider provider = new DefaultOAuthProvider(endPointURLs[0], endPointURLs[1], endPointURLs[2]);
        String authUrl = provider.retrieveRequestToken(consumer,  "oob" );
        System.out.println( authUrl );

Maybe something has changed in the java.net.HttpURLConnection because if I 
change the request method from POST to GET in DefaultOAuthProvider linenumber 
43 then it will work fine. By the way does the createRequest explicitly set the 
method to POST?

Original issue reported on code.google.com by m.magy...@gmail.com on 30 Oct 2010 at 9:52

GoogleCodeExporter commented 8 years ago
I am also getting same problem, here is my code.

package gdatatest;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

import oauth.signpost.OAuth;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthConsumer;
import oauth.signpost.basic.DefaultOAuthProvider;
//import oauth.signpost.signature.SignatureMethod;

public class TestClass {
    public static void main(String[] args) throws Exception {

        OAuthConsumer consumer = new DefaultOAuthConsumer("PRIVATETOME","PRIVATETOME");

        String scope = "http://www.google.com/calendar/feeds/";
        OAuthProvider provider = new DefaultOAuthProvider("https://www.google.com/accounts/OAuthGetRequestToken?scope="
                                + URLEncoder.encode(scope, "utf-8"),
                                "https://www.google.com/accounts/OAuthGetAccessToken",
                                "https://www.google.com/accounts/OAuthAuthorizeToken?hd=default");

        System.out.println("Fetching request token...");
        String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
        System.out.println("Request token: " + consumer.getToken());
        System.out.println("Token secret: " + consumer.getTokenSecret());
        System.out.println("Now visit:\n" + authUrl + "\n... and grant this app authorization");
        System.out.println("Enter the verification code and hit ENTER when you're done:");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String verificationCode = br.readLine();
        System.out.println("Fetching access token...");
        provider.retrieveAccessToken(consumer, verificationCode.trim());
        System.out.println("Access token: " + consumer.getToken());
        System.out.println("Token secret: " + consumer.getTokenSecret());
        URL url = new URL("http://www.blogger.com/feeds/default/blogs");
        HttpURLConnection request = (HttpURLConnection) url.openConnection();
        consumer.sign(request);
        System.out.println("Sending request...");
        request.connect();
        System.out.println("Response: " + request.getResponseCode() + " "
        + request.getResponseMessage());
    }
}

Following error is displaying for me for JRE 6
Fetching request token...
Exception in thread "main" 
oauth.signpost.exception.OAuthCommunicationException: Communication with the 
service provider failed: Server returned HTTP response code: 411 for URL: 
https://www.google.com/accounts/OAuthGetRequestToken?scope=http%3A%2F%2Fwww.goog
le.com%2Fcalendar%2Ffeeds%2F
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    at gdatatest.TestClass.main(TestClass.java:27)
Caused by: java.io.IOException: Server returned HTTP response code: 411 for 
URL: 
https://www.google.com/accounts/OAuthGetRequestToken?scope=http%3A%2F%2Fwww.goog
le.com%2Fcalendar%2Ffeeds%2F
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection$6.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.net.www.protocol.http.HttpURLConnection.getChainedException(Unknown Source)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
    at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getContent(HttpURLConnectionResponseAdapter.java:18)
    at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:228)
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:189)
    ... 2 more
Caused by: java.io.IOException: Server returned HTTP response code: 411 for 
URL: 
https://www.google.com/accounts/OAuthGetRequestToken?scope=http%3A%2F%2Fwww.goog
le.com%2Fcalendar%2Ffeeds%2F
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at java.net.HttpURLConnection.getResponseCode(Unknown Source)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
    at oauth.signpost.basic.HttpURLConnectionResponseAdapter.getStatusCode(HttpURLConnectionResponseAdapter.java:22)
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:178)
    ... 2 more

Original comment by Avadhesh...@gmail.com on 14 Nov 2010 at 5:37

GoogleCodeExporter commented 8 years ago
Error confirmed when going from
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)

..to
Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03, mixed mode)

Code to reproduce:

final String tokenRequestPath = 
"https://chpp.hattrick.org/oauth/request_token.ashx";
final String authorizePath = "https://chpp.hattrick.org/oauth/authorize.aspx";
final String accessRequestPath = 
"https://chpp.hattrick.org/oauth/access_token.ashx";

OAuthConsumer consumer = new CommonsHttpOAuthConsumer("SECRET", "SECRET");
OAuthProvider provider = new DefaultOAuthProvider(tokenRequestPath, 
accessRequestPath, authorizePath);
String url = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);

Original comment by lug00...@gmail.com on 21 Nov 2010 at 8:14

GoogleCodeExporter commented 8 years ago
This could possibly be related:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6996110

Original comment by lug00...@gmail.com on 21 Nov 2010 at 9:26

GoogleCodeExporter commented 8 years ago
Hi, im developing a tool for hattrick but im stuck @ the part after retrieve 
the token:

provider.retrieveAccessToken(consumer, oauth_verifier);
System.out.println("Access token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());

How can i get the hattrick xml data now ?
can you give me some pointers??

Thanks for the help.

Original comment by rpgome...@gmail.com on 16 Dec 2010 at 11:44

GoogleCodeExporter commented 8 years ago
Facing the same problem on ubuntu with Mendeley:
if (provider != null && consumer != null) {
                requestToken = provider.retrieveRequestToken(consumer,
                        OAuth.OUT_OF_BAND);
                System.out.println("Request token: " + consumer.getToken());
                System.out
                        .println("Token secret: " + consumer.getTokenSecret());
            }

This results in:
oauth.signpost.exception.OAuthCommunicationException: Communication with the 
service provider failed: Server returned HTTP response code: 411 for URL: 
http://www.mendeley.com/oauth/request_token/
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:214)
    at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:69)
    at de.test.MendeleyAuth.init(MendeleyAuth.java:31)
    at de.test.MendeleyAuth.main(MendeleyAuth.java:19)

Original comment by TimMesse...@gmail.com on 6 Mar 2011 at 2:12

GoogleCodeExporter commented 8 years ago
Is there anyone solved this problem?

Original comment by muratbir...@gmail.com on 6 Apr 2011 at 12:58

GoogleCodeExporter commented 8 years ago
Instead of using 
OAuthProvider provider = new DefaultOAuthProvider
use
OAuthProvider provider = new CommonsHttpOAuthProvider

Original comment by mfrie...@gmail.com on 21 Apr 2011 at 1:57

GoogleCodeExporter commented 8 years ago
use
OAuthProvider provider = new CommonsHttpOAuthProvider

this solution worked for me. thank!

Original comment by othmanelmoulat on 11 Jul 2011 at 2:10

GoogleCodeExporter commented 8 years ago
I think that the problem is on DefaultOAuthProvider#createRequest (line 42):

// Should calculate payload length instead of "0"
connection.setRequestProperty("Content-Length", "0"); 

Original comment by cadu.gon...@gmail.com on 21 Jun 2012 at 7:02

GoogleCodeExporter commented 8 years ago
OAuthProvider provider = new CommonsHttpOAuthProvider 
I am using this but still having same problem on Samsung Ace.

Original comment by sphinx.a...@gmail.com on 31 May 2013 at 11:17