StefanSchnell
Enthusiast
Enthusiast

Set JavaScript Access to Java Classes

Jump to solution

To find a way to detect the used Java version I would like to use the following script:

// Begin----------------------------------------------------------------

var javaVersion = java.lang.System.getProperty("java.version");
System.log(javaVersion);

// End------------------------------------------------------------------

However, the use of Java classes, other than java.util.*, is limited, they must be explicitly enabled. You can find a description how to set JavaScript access to Java classes here. I try that exactly as described, but it does not work.

1. Create file with name rhino-class-shutter-file in the directory /data/vco/usr/lib/vco.
2. Set system property com.vmware.scripting.rhino-class-shutter-file to vco/usr/lib/vco/rhino-class-shutter-file. This configuration is stored in the file vmo-managed.properties in the location /data/vco/usr/lib/vco/app-server/conf.

StefanSchnell_0-1669698094443.png

Different file names were tried, e.g. java_shutter_file or rhinofile. Furthermore different notations of the paths were tried out, like vco/usr/lib/vco/app-server/conf/rhinofile/vco/usr/lib/vco/app-server/conf/rhinofiledata/vco/usr/lib/vco/app-server/conf/rhinofile/data/vco/usr/lib/vco/app-server/conf/rhinofile etc. This was tested with version 8.5.1 and 8.9.0.

3. After the restart of the Orchestration service and an new login into the vRA the error message 'TypeError: Cannot call property getProperty in object [JavaPackage java.lang.System], it is not a function, it is "object"' occures.

StefanSchnell_1-1669698284185.png

This is exactly the same error message as in a simulation where the ClassShutter is set on the same way.

context.setClassShutter(new ClassShutter() {
  public boolean visibleToScripts(String className) {
    if (
      className.startsWith("java.util")
    ) {
      return true;
    } else {
      return false;
    }
  }
});

StefanSchnell_2-1669699037047.png

It looks like accessing classes, outside of java.util.*, does not work, despite the configuration.

As far as I can see uses the Orchestrator 8.5.1 the Azul JDK Zulu 11.0.12.

What is my mistake? What else do I need to do to access Java classes via JavaScript?

Thanks for hints and tips.

 

 

0 Kudos
1 Solution

Accepted Solutions
StefanSchnell
Enthusiast
Enthusiast

This morning I analyzed this problem again and found that the path of the class pattern shutter list, which is stored in the system property com.vmware.scripting.rhino-class-shutter-file, must be specified relative to the running container. The path described in the documentation is incorrect and your_configuration_file_subdirectory is already a bit misleading..

StefanSchnell_0-1671267401465.png

The correct path is /usr/lib/vco/yourFileName. In my example I use today the file name PatternClassShutter.list. The location and the content is as described above.

StefanSchnell_0-1671261867502.png

Now all works as expected.

StefanSchnell_1-1671261963149.png

Great that Java can be used seamlessly on this way.

View solution in original post

2 Replies
StefanSchnell
Enthusiast
Enthusiast

To get the Java version I tried another way. i set the system property com.vmware.js.allow-local-process to true.

StefanSchnell_0-1671100094060.png

To get the Java version I used the following command sequence:

 

var com = new Command("jdk/bin/java --version");
com.execute(true);
System.log(com.output);

 

And this delivers these result:

StefanSchnell_1-1671100507006.png

Now we definitely see with Orchestrator 8.5.1 that Java version 11.0.12 is used and that it is an Zulu Azul distribution.

StefanSchnell_0-1671432817501.png

The Orchestrator 8.10.2 uses the Java version 11.0.16.1 and that is an BellSoft distribution. This information is available in the java.vendor system property.

0 Kudos
StefanSchnell
Enthusiast
Enthusiast

This morning I analyzed this problem again and found that the path of the class pattern shutter list, which is stored in the system property com.vmware.scripting.rhino-class-shutter-file, must be specified relative to the running container. The path described in the documentation is incorrect and your_configuration_file_subdirectory is already a bit misleading..

StefanSchnell_0-1671267401465.png

The correct path is /usr/lib/vco/yourFileName. In my example I use today the file name PatternClassShutter.list. The location and the content is as described above.

StefanSchnell_0-1671261867502.png

Now all works as expected.

StefanSchnell_1-1671261963149.png

Great that Java can be used seamlessly on this way.