Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Oauth using Java instead of curl with apache oltu.  RSS feed

Ben Pittens
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I want to replace this curl command with a request in a Java client:

curl -k --user userName:SecretID –d "scope=/LeverdatumbepalingRest/api/v1.0/"

It is returning an JSON message and it look like this:

{ "token_type":"bearer", "access_token":"AAEecmVzdC10b2tlbi1zcnYtcGFzc3dvcmQtY2xpZW50zBVd4EcoSnA5zVHOHSMkSN-ReEgOnAuyQxv3jv613vQvonMGU_HxjWbzNJPfadc1L0ZSA4dar0YCR8Jx7PSvkue_2Lh7lOQ9Nv8KGRz092OgLR_A2TGD6e6zafsgpaMB", "expires_in":2678400, "scope":"/LeverdatumbepalingRest/api/v1.0/" }

The request goes to a IBM Datapower server with an webtoken implementation.

I tried it in Java with Apache oltu lib: org.apache.oltu.oauth2.client-1.0.1.jar

I tried to build a Java client with this code but it is not working, the server even does not receive any message so my client is not working:

This error I am getting:

Exception in thread "main" OAuthProblemException{error='unsupported_response_type', description='Invalid response! Response body is not application/json encoded', uri='null', state='null', scope='null', redirectUri='null', responseStatus=0, parameters={}}
at org.apache.oltu.oauth2.common.exception.OAuthProblemException.error(
at org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse.setBody(
at org.apache.oltu.oauth2.client.response.OAuthClientResponse.init(
at org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse.init(
at org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory.createCustomResponse(
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(
at nl.sligro.leverdatumbepaling.test.LDBGetCertificaat.callGetToken(
at nl.sligro.leverdatumbepaling.test.LDBGetCertificaat.main(

Any body have an idea whats wrong with my code?

Thanks in advance,

Kind Regards,

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!