Skip to content
This repository has been archived by the owner on Apr 5, 2019. It is now read-only.

Problem in Using Jersey to develop StashBoard API client (POST requests) #12

Closed
girishni opened this issue Feb 3, 2011 · 2 comments
Closed
Labels

Comments

@girishni
Copy link

girishni commented Feb 3, 2011

Hello,

I am using apache jersey client libraries to develop StashBoard API client which will allow me to update status of a particular service using client program.

I am using following code in java to create Oauth consumer:
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);
}

But when I try to do a POST I get HTTP 400 error. The code to call POST on /api/v1/services/{service}/events is as follows:

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);

Please let me know if I am doing something wrong.

BTW the service defination expects a JSON object right ?? (At least that is what I could find out by looking client examples for PHP/ruby on your website)

@kyleconroy
Copy link
Contributor

The Services list resource expects is data to be in the form of url-encoded parameters. In your email you mentioned you set the data type to APPLICATION_FORM_URLENCODED. Did you make sure to actually urlencode the data?

@kyleconroy
Copy link
Contributor

Closing, as we haven't heard an update in a while

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants