Handle the HttpURLConnection calling sequences in the DefaultOAuthProvider.java #7
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I just add connection.setDoOutput(true); in the createRequest(String url) method and add connection.getOutputStream();in the sendRequest() method.
I am doing this because I got a problem when i am using signpost doing the OAuth stuff thing. i got a 502 response code when i tried to get the request token. Here is my code:
I am using sign-post-1.2.1.1, and i also checked the source code, i think there may have problems with using the HttpURLConnection class. After some googling, i found those two bug reports http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4192018 and http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4146690. I just copy some evaluations of them here in case that you do not want to check it out by yourself. It's all about the HttpURLConnection.
"The calling sequence that you are supposed to follow is:
For request method other than POST or PUT, 1. set request properties; 2. call getInputStream.
For POST and PUT request methods, 1. set request properties; 2. call getOutputStream and write to the outputstream; 3. call getInputStream to send out the request and get the response from server.
You can not call getOutputStream alone and expect the flush method would cause the request to be sent to the server. The only way to send out the request is by calling getInputStream."
It means that Java really cares about the calling sequence when you do the http request. But oauth.signpost.basic.DefaultOAuthProvider.java do not stick to that very well. It create a POST request,
then some other class set the parameters or properties of the request, then it call sendRequest().OK, there is no calling of getOutputStream(). So i implement my own OAuthProvider, just copy the DefaultOAuthProvider source code into it and add connection.setDoOutput(true) in the createRequest() method and call the connecion.getOutputStream() then do nothing, the problems just gone.
So is it a problem?
BTW, i am using jdk-1.6.0-24, Windows XP professinal sp3.
There is also a wired problem, when i switched jdk from jdk-1.6.0-24 to jdk-1.6.0-14, everything works just fine, can anyone help me out there?