VMware Cloud Community
abo56
Contributor
Contributor

How to use vcTokenAuth in vROps adapter?

I’m using vROps Java Client Bindings to create Java client capable of consuming vROps REST API.

My source code to create the client:

 

            Client client = ClientConfig.builder()

                        .serverUrl("https://10.172.181.231/suite-api/")

                        //.vcTokenAuth(token)  

                        .basicAuth("admin", "password")

                        .build()

                        .newClient();

           

     

            ApplicationVersion version = client.apiVersionsClient().getCurrentVersion();

 

It works with basicAuth, which uses vROps user credentials.

 

I would like to switch to vcTokenAuth method, which is very briefly described under /suite-api/docs/java/com/vmware/ops/api/client/Client.ClientConfig.Builder.html#vcTokenAuth(java.lang.String)

Token is acquired with vimPortType.acquireCloneTicket() method from Web Services SDK.

Simply switching to .vcTokenAuth instead of .basicAuth doesn’t work. For token I’m using cloneTicket acquired from vCenter Server.

It generates following warning message and stack trace:

 

478  [main] WARN  org.springframework.web.client.RestTemplate  - GET request for "https://10.172.181.231/suite-api/api/versions/current?_no_links=true" resulted in 500 (Internal Server Error); invoking error handler

Exception in thread "main" com.vmware.ops.api.client.exceptions.ServerException: Internal Server error, cause unknown.

      at com.vmware.ops.api.client.internal.DefaultClient.handleError(DefaultClient.java:262)

      at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:607)

      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:565)

      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:536)

      at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:269)

      at com.vmware.ops.api.client.internal.RestClientProxy.invoke(RestClientProxy.java:149)

      at com.vmware.ops.api.client.internal.DefaultClient$InvocationHandlerWrapper.invoke(DefaultClient.java:228)

      at com.sun.proxy.$Proxy40.getCurrentVersion(Unknown Source)

      at vcTokenAuth.Main.main(Main.java:34)

 

My question is what are the steps to successfully use vcTokenAuth mechanism? Are there any prerequisites that need to be fulfilled before using it? Where do I get the token from, because I’m not entirely sure I’m getting the correct one? The documentation isn’t very precise about that.

0 Kudos
1 Reply
Phil_K
Enthusiast
Enthusiast

Were you able to instantiate the client with the code sample they provided in the documentation?

If so, what am I missing here? I have added the jar file for the client api to my library, then I create the client class right? Or do I instantiate the client inside the body of the code for whatever program I am trying to run? Netbeans seemed to have a fit when I tried to paste that client = client code into the body of my program.

If you have any insight into this process please let me know. I'm new to coding with Java but think I have a pretty decent understanding of object oriented programming.

0 Kudos