VMware Cloud Community
kc987654321
Contributor
Contributor

vCO Java Rest SDK

I played around vCO Java Rest SDK (o11n-rest-client-services-5.5.1.jar , o11n-rest-client-stubs-5.5.1.jar) and have the following questions:

Q1) Where can I get the source codes of  the Java Rest SDK ? I am mainly interested for the source codes of o11n-rest-client-services-5.5.1.jar and o11n-rest-client-stubs-5.5.1.jar


Q2) I used the provided sample to execute to a vCO workflow but it returned  "401 Full authentication is required to access this resource". I then debugged and found out that vCO Java Rest SDK d not set any "Authorization" header for the basic authentication  in the HTTP request . I then  decompiled vCO Java Rest SDK and did not find there are codes that  will set the "Authorization" header . I traced the source codes  and finally solved this issue by implementing the basic authentication algorithm by overriding UsernamePasswordAuthentication#postProcessRequest() . So  , I want to ask if the vCO Java Rest SDK can be used out of the box ? Or it is just a semi-finished product and expect developer to implement the rest of code ?

Tags (4)
0 Kudos
10 Replies
iiliev
VMware Employee
VMware Employee

A1) vCO Java REST SDK is not open-sourced (yet) so its source code is not publicly available.

A2) It should work out of the box. I think "Authorization" header is populated by Spring from the authentication object so you don't need to write code to set it.

Could you send me your code that fails with 401? Preferably a full compilable project so I can debug it. I did a quick test in my environment and UsernamePasswordAuthentication seems to work as expected (my environment is not 5.5.1 but 6.0 so in theory it's possible that there is a bug in 5.5.1).

0 Kudos
kc987654321
Contributor
Contributor

Hi

0 Kudos
iiliev
VMware Employee
VMware Employee

Hi,

I tried something like this in my 5.5.1 environment, and it worked properly. Also I compiled your sample project (with changed values for username/password/URL/etc) and it also worked.

Are you able to access the REST API with other clients? For example, could you try to access https://192.168.1.1:8281/vco/api/workflows/72342d322-3d34-4e92-831f-1865c34514c6 with a browser?

String user = "username";

String pwd = "password";

URI vcoUri = new URI("https://192.168.1.1:8281/vco/api");

String workflowId = "72342d322-3d34-4e92-831f-1865c34514c6";

VcoSessionFactory sessionFactory = new DefaultVcoSessionFactory(vcoUri) {

    @Override

    protected HostnameVerifier newHostnameVerifier() {

        return newUnsecureHostnameVerifier();

    }

    @Override

    protected SSLContext newSSLContext() throws KeyManagementException, NoSuchAlgorithmException {

        return newUnsecureSSLContext();

        }

    };

VcoSession session = sessionFactory.newSession(new UsernamePasswordAuthentication(user, pwd));

WorkflowService workflowService = new WorkflowService(session);

ExecutionService executionService = new ExecutionService(session);

Workflow workflow = workflowService.getWorkflow(workflowId);

// execute the workflow by passing the input parameters

ExecutionContext context = new ExecutionContextBuilder().build();

WorkflowExecution execution = executionService.execute(workflow, context);

0 Kudos
smithgp
Enthusiast
Enthusiast

Hi -

I'm also using the 5.5.1 vco client jars and ran into the same issue, and did the same workaround of creating a subclass of com.vmware.o11n.sdk.rest.client.authentication.Authentication that implements postProcessRequest to manually set the Authentication header. For me, it seemed to occur when the username I was trying had an '@' in it (e.g. administrator@vsphere.local using the vCO in the vCAC VA).

Greg

iiliev
VMware Employee
VMware Employee

I just tried with 'administrator@vsphere.local' in my environment; seems to work fine.

Perhaps the issue is somehow related to the version of vCO bundled in the vCAC VA. I recall it was not exactly the same as the standalone vCO although both are version 5.5.1.

Could you try to deploy a standalone vCO VA 5.5.1 (or windows installation of standalone vCO 5.5.1) and check if the issue is still there?

0 Kudos
smithgp
Enthusiast
Enthusiast

I believe I copied the 5.5.1 client jars from a vCO VA's /var/lib/vco/downloads/vco-repo folder, since they don't appear to be on the vCAC VA (its /var/lib/vco/downloads is a symlink to itself, which is weird). And, I just retried some things again so here's some more information.

When hitting a vCO VA 5.5.1 appliance as vcoadmin@vpshere.local, using either the regular UsernamePasswordAuthentication class or my Authentication subclass that sets the Authentication header, it works fine. When hitting a vCAC 6.0.1 or 6.0.1.1 VA's vCO with administrator@vsphere.local with the regular UsernamePasswordAuthentication class, I get the 401. If I use my Authentication subclass hitting a vCAC VA's vCO, it works fine.

So, it's something about the vCAC VA's vCO setup and the 5.5.1 client jars.

Greg

0 Kudos
iiliev
VMware Employee
VMware Employee

It appears that vCAC 6.0.1/6.0.1.1 bundle vCO build# 1413271 and the standalone vCO 5.5.1 is build# 1617131 (Windows) or build# 1617225 (appliance).

That's quite a big time difference - 3 months or so between the builds, so it is possible that something was fixed in standalone vCO release. Unfortunately, at the moment I don't have a working vCAC environment so I can't debug the issue. Perhaps next week.

Meantime, if this is an important/blocker issue for you, consider opening a support request.

0 Kudos
smithgp
Enthusiast
Enthusiast

That makes sense.

In any case, for what I'm doing, I'm good. We're just using the vco client jar to run unit tests against our workflows and plugin, and the Authentication subclass is working fine for that.

Thanks,

Greg

0 Kudos
SergeyGomanyuk
Contributor
Contributor

Hi, I have a couple of questions regarding vCO Java REST SDK:


> A1) vCO Java REST SDK is not open-sourced (yet) so its source code is not publicly available.

- Is it possible to get at least Javadoc of vCO Java REST SDK?


- Is it possible to get more samples? I can find the only one at vSphere 5.5 Documentation Center


- Can I reuse VcoSession, WorkflowService, ExecutionService among different REST Calls?


- Can I share VcoSession, WorkflowService, ExecutionService among different java threads, are they thread safe?


- Can I execute multiple Workflows in parallel using the same ExecutionService and await each workflow termination in different threads using executionService.awaitState?


- Is it possible to find workflow by its name (not id)?


- Is it possible to build ExecutionContext  using string representation of parameters, i.e. workflow has input string, secureString and boolean params, but I have string representation of each parameter, can I use ExecutionContextBuilder.addParam(String, String) for all of them?


- Is it possible to retrieve workflow parameter names and their types?


- Is it possible to get all WorkflowExecutions of Workflow?


- Is it possible to get WorkflowExecution later using, i.e. its ID?




0 Kudos
thomas_root1
Enthusiast
Enthusiast

Hi,

I am also interested in source code files of the Java REST SDK.

Does anyone know if the source code of the Java REST SDK will be publicly available???

Or is this not intended by VMware.

Thomas

0 Kudos