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
Greenhorn
Posts: 29
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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

curl -k https://api.bp-services.com/ --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(OAuthProblemException.java:63)
at org.apache.oltu.oauth2.client.response.OAuthJSONAccessTokenResponse.setBody(OAuthJSONAccessTokenResponse.java:70)
at org.apache.oltu.oauth2.client.response.OAuthClientResponse.init(OAuthClientResponse.java:56)
at org.apache.oltu.oauth2.client.response.OAuthAccessTokenResponse.init(OAuthAccessTokenResponse.java:52)
at org.apache.oltu.oauth2.client.response.OAuthClientResponseFactory.createCustomResponse(OAuthClientResponseFactory.java:60)
at org.apache.oltu.oauth2.client.URLConnectionClient.execute(URLConnectionClient.java:111)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:65)
at org.apache.oltu.oauth2.client.OAuthClient.accessToken(OAuthClient.java:55)
at nl.sligro.leverdatumbepaling.test.LDBGetCertificaat.callGetToken(LDBGetCertificaat.java:55)
at nl.sligro.leverdatumbepaling.test.LDBGetCertificaat.main(LDBGetCertificaat.java:28)



Any body have an idea whats wrong with my code?

Thanks in advance,

Kind Regards,

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