problems using signpost with freelancer API

21 views
Skip to first unread message

gonzobrains

unread,
Nov 6, 2010, 3:41:51 PM11/6/10
to Signpost users, sup...@internetovations.com
Hi,

Is anyone out there using signpost with Freelancer's API? I think
there are a few issues that is preventing me from getting around this
401 issue I'm having.

At first I was getting "malformed packet" errors. I have since
overridden the DefaultOAuthProvider to specify "GET" instead of
"POST", as the Freelancer API's sample app seems to be using GET, from
what I can see via Wireshark:




import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;

import oauth.signpost.AbstractOAuthProvider;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.basic.HttpURLConnectionRequestAdapter;
import oauth.signpost.http.HttpRequest;
import oauth.signpost.http.HttpResponse;

public class FreelancerOAuthProvider extends DefaultOAuthProvider
{
private static final long serialVersionUID = 1L;

public FreelancerOAuthProvider(String requestTokenEndpointUrl,
String accessTokenEndpointUrl, String authorizationWebsiteUrl) {
super(requestTokenEndpointUrl, accessTokenEndpointUrl,
authorizationWebsiteUrl);
// TODO Auto-generated constructor stub
}

@Override
protected HttpRequest createRequest(String endpointUrl) throws
MalformedURLException,
IOException

{
HttpURLConnection connection = (HttpURLConnection) new
URL(endpointUrl).openConnection();
connection.setRequestMethod("GET");
connection.setAllowUserInteraction(false);

return new HttpURLConnectionRequestAdapter(connection);

}

}


The problem is, I still get an error. When I compare the packets in
Wireshark it looks as thought Freelancer's API sample places all the
OAuth parameters in the query string:

/RequestRequestToken/requestRequestToken.xml?
oauth_callback=oob&oauth_consumer_key=0a4861e74131de5b679aebaf99e5821c6a4a5baa&oauth_nonce=72&oauth_signature=7Rn80qXj9%2FxQMX6RZN59G
%2FjzcXk%3D&oauth_signature_method=HMAC-
SHA1&oauth_timestamp=1289071858&oauth_version=1.0

I don't see this in the URI signpost creates:

/RequestRequestToken/requestRequestToken.xml

I'm guessing this is because signpost places this stuff in the
Authentication Header, right?

gb

Fetching request token from freelancer...
Exception in thread "main"
oauth.signpost.exception.OAuthCommunicationException: Communication
with the service provider failed: Server returned HTTP response code:
401 for URL: http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml
at
oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:
214)
at
oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:
69)
at TwitterMain.main(TwitterMain.java:34)
Caused by: java.io.IOException: Server returned HTTP response code:
401 for URL: http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
39)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at sun.net.www.protocol.http.HttpURLConnection
$6.run(HttpURLConnection.java:1496)
at java.security.AccessController.doPrivileged(Native Method)
at
sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:
1490)
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:
1144)
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:
401 for URL: http://api.sandbox.freelancer.com/RequestRequestToken/requestRequestToken.xml
at
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:
1441)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:
379)
at
oauth.signpost.basic.HttpURLConnectionResponseAdapter.getStatusCode(HttpURLConnectionResponseAdapter.java:
22)
at
oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:
178)
... 2 more
Reply all
Reply to author
Forward
0 new messages