VMware Cloud Community
bdamian
Expert
Expert

API Authentication using ResteasyClient

I'm having problems trying to authenticate using org.jboss.resteasy.client.jaxrs ResteasyClient.

If I create a request pointing to https://vcdServer/api/versions it works correctly. But against https://vcdServer/api/sessions it gives me an errorCode 500 (Internal server error)

If I use "curl" in command line it works correctly:

curl -i -k -H "Accept:application/*+xml;version=1.5" -u "administrator@System:pass" -X POST  https://vcdServer/api/sessions

Here is my testing program:

String authHeader = BasicAuthHelper.createHeader("administrator@System","pass");

ResteasyClient client = new ResteasyClientBuilder().disableTrustManager().build();

ResteasyWebTarget target = client.target("https://vcdServer/api/sessions");
target.request().header("Authorization", authHeader);
target.request().header("Accept", "application/*+xml;version=1.5");

Response response = target.request().post(Entity.text(""));
System.out.println(response.getStatus());


Any ideas?

Thanks a lot,

D.

---
Damián Bacalov
vExpert 2017-2023 (7 years)
https://www.linkedin.com/in/damianbacalov/
https://tecnologiaimasd.blogspot.com/
twitter @bdamian
Tags (1)
0 Kudos
1 Reply
IamTHEvilONE
Immortal
Immortal

https://vcdServer/api/versions -> this URL does not require authentication ... you can even run wget against this address in command line.

https://vcdServer/api/sessions -> this requires basic auth encoded in the correct format ... That looks right in curl.

The same general process works in Chrome's Postman app.  I haven't used the RestEasy Client before to know how it works.

0 Kudos