VMware Cloud Community
crnkyadmin
Contributor
Contributor

Accessing Java Classes from JavaScript documentation... less-than helpful

So, here's what the VCO 4.1 developer's guide says about accessing java classes from Orchestrator's javascript...

h5. Accessing Java Classes from JavaScript
By default, Orchestrator restricts JavaScript access to a limited set of Java classes. If you require JavaScript
access to a wider range of Java classes, you must set an Orchestrator system property to allow this access.
By default, the Orchestrator JavaScript engine can access only the classes in the java.util.* package.
The Orchestrator administrator can allow access to other Java classes from JavaScript functions by setting a
system property. See the VMware vCenter Orchestrator Administration Guide for information about setting system
properties.
(http://vmware.ie/pdf/vco_410_developers_guide.pdf, pp. 115).

This is less-than helpful as it doesn't actually say how to use java classes from javascript.

After following the instructions for access java classes from javascript in the VCO administrator's guide (http://vmware.ie/pdf/vco_410_admin_guide.pdf, pp. 67) I am still unable to use standard java classes. Does anyone have any examples of how to do this? I've tried "inetAddress = java.net.InetAddress.getByName(serverAddress);" and I get the error "TypeError: getByName is not a function, it is org.mozilla.javascript.NativeJavaPackage." I've also tried using Rhino's importPackage function and it doesn't seem to be recognized.

Reply
0 Kudos
5 Replies
cdecanini_
VMware Employee
VMware Employee

For the java example try:

var baseAddress = java.net.InetAddress.getByName(serverAddress);

var name = baseAddress.getHostName();

If you want to do just this it is not necessary to use java. You can do like this:

var name = System.resolveIpAddress(serverAddress);

Christophe.

If my answer resolved or helped you, please mark it as Correct or Helpful to award points. Thank you! Visit http://www.vcoteam.info & http://blogs.vmware.com/orchestrator for vCenter Orchestrator tips and tutorials - @vCOTeam on Twitter
Reply
0 Kudos
benlicmu
Contributor
Contributor

hi Christophe,

I got exactly same problem here. when I call

var url = java.net.url("http://www.google.com");

var con = url.openConnection();

I got the TypeError: Cannot find function openConnection.

also any idea about how can I convert java class type in orchestrator? like url.openConnection will return URLConnection, but I want to convert it to HTTPURLConnection.

Thanks,

Reply
0 Kudos
tschoergez
Leadership
Leadership

Hi!

Have you tried to use a shutter-file to allow vCO to access the Java-Classes?

See some examples here:

http://mighty-virtualization.blogspot.com/2011/01/vco-access-to-java-classes.html

Regards,

Joerg

Reply
0 Kudos
benlicmu
Contributor
Contributor

I did. but just java.net.URL class is not working, because Orchestartor also offer another URL class, blocking me to use the orignal Java class.

Reply
0 Kudos
maaca
Enthusiast
Enthusiast

I'm facing exactly the same issue. java.net.URL object is somehow automatically "switched" to Orchestrator's URL.

Have you found some workaround?

Reply
0 Kudos