Question

When I'm trying to use found solutions to convert from Node to String in javascript, starting from this line

var transformer = javax.xml.transform.TransformerFactory.newInstance().newTransformer();

it says

Message: (Desired evaluation could not be performed: JavaScript Error: Internal Error: ReferenceError: "javax" is not defined. (JavaScript Error: Internal Error: ReferenceError: "javax" is not defined.)

but classes from java* package work OK

this works:

var writer = new java.io.StringWriter();

Is it possible to convert Node to String without using classes from javax* package?

using org.w3c.* is ok though

Was it helpful?

Solution

Sonic ESB internally uses Rhino as its JavaScript engine.

When calling Java from JavaScript, you should reference the Java classes using Packages: Packages.javax.xml.transform.TransformerFactory The reason you can use the java packages without trouble is that Packages.java has been aliased in the global variable java.

When you do this, you can use the classes in the javax package just fine. In fact, you can add any jars you like to the classpath and use those classes too.

https://developer.mozilla.org/en-US/docs/Rhino/Scripting_Java

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top