users@jersey.java.net

[Jersey] Fw: Regarding Apache Jersey and doing a POST request on REST Service (by passing JSON)

From: Girish Khadke <girish.khadke_at_ni.com>
Date: Fri, 4 Feb 2011 13:15:58 -0600

Hello,

Thanks for replying back.

Yes they are using 2 legged OAuth.

Well in order to use stashboard, I am deploying stashboard application
source code as a google app on Google App Engine. (So the link for my
sample app is : https://stashboardni.appspot.com )

Now in order to get OAuth Token / Secret, you can go to
https://stashboardni.appspot.com and log in as admin of application (In
this case my google account id and password). Once you log in and go to
API credentials section, you will be able to see your OAuth token /
secret.

I am using this OAuth key secret and consumer key / secret (anonymous) in
my code.

Let me know if any more questions. Actually I am trying out jersey client
API.

I have following questions:

1. I am using 1.1.5 API and I want to know does it support OAuth 2.0 ??
(because all the examples they have given for PHP and Python use some
Oauth2 libraries on Github)

2. Also the basic Server side web service is all written in Python and it
supports JSON and plain text. ( I went through source code of Stashboard
located at folder /handler in installation directory written as script
restful.py)
 
    Now since the Server side web service is in Python and still I should
be able to consume and post JSON objects from it right?


Hoping for your replies and posting also on users list.

Thanks and regards,
Girish



From: Martin Matula <martin.matula_at_oracle.com>
To: Girish Khadke <girish.khadke_at_ni.com>
Cc: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: 02/04/2011 03:29 AM
Subject: Re: Regarding Apache Jersey and doing a POST request on
REST Service (by passing JSON)



HI Girish,
How have you obtained consumer key, consumer secret, access token and
token secret?
I browsed through the website you pointed to, but the API Credentials
Section link seems to be broken (
http://stashboard.appspot.com/documentation/credentials). Typically you
need to register your app with the web site - they would give a you
consumer key/secret pair, which your app then uses to obtain request
token/secret pair. That needs to get authorized by a user and exchanged
for access token/secret which can then be used to make subsequent
requests. From the example it seems they are implementing 2-legged OAuth,
where you are always passing "anonymous" as the consumer key/secret and
they give you access token/secret during the registration (i.e. no need to
obtain request token first and get user authorization). But I am not sure
since I can't get to the API Credentials Section.
Would you mind posting follow-up questions to our users list (
users_at_jersey.java.net)? That way others could also benefit from our
conversation (and maybe also help).
Thanks,
Martin

On 4.2.2011 8:55, Paul Sandoz wrote:
Hi Girish,

CC'ing Martin, who knows more about this than I.

Paul.

On Feb 3, 2011, at 10:36 PM, Girish Khadke wrote:

Hello,

I am developing client for StashBoard API (stashboard.org) which provides
RESTful service to monitor status of cloud services.

I am also using Oauth to authenticate POST requests.

I am using following to create Authenticated client and webresource using
OAuth:

private void CreateOAuthClient() {
    this.sbClient = Client.create();

   this.sbOAuthParams = new OAuthParameters();
   this.sbOAuthSecrets = new OAuthSecrets();

 
this.sbOAuthParams.consumerKey(this.SB_CONSUMER_KEY).signatureMethod("HMAC-SHA1");
   this.sbOAuthSecrets.consumerSecret(this.SB_CONSUMER_SECRET);

 
this.sbOAuthParams.token(this.SB_OAUTH_TOKEN_KEY).signatureMethod("HMAC-SHA1");
   this.sbOAuthSecrets.tokenSecret(this.SB_OAUTH_TOKEN_SECRET);

   this.sbOAuthClientFilter = new
OAuthClientFilter(sbClient.getProviders() , sbOAuthParams,
sbOAuthSecrets);

   this.sbWebResource = this.sbClient.resource(strBaseUrl);
   this.sbWebResource.addFilter(sbOAuthClientFilter);
}

Using this webResource I am doing a POST request which in turn takes input
as a JSON representation.

JSONObject newEvent = new JSONObject();
        newEvent.put("status", "up");
       newEvent.put("message", "working again!!!");
 
sbWebResource.path("services").path(prmServiceId).path("events").type(MediaType.APPLICATION_JSON_TYPE).post(newEvent)


But when I run this I get HTTP 400 error.
I am following http://stashboard.appspot.com/documentation/examples (which
has examples for PHP / ruby based client) and trying to make a Jersey
based client using Jersey client libraries and Jersey Oauth libraries.
Please let me know if I am doing anything wrong here.