Skip to main content
Compatible with Fusion version: 4.2.0 through 5.2.2
Deprecation and removal noticeThis connector is deprecated as of August 24, 2020 and is removed or expected to be removed as of May 18, 2022. Use the index pipeline for fetching content.For more information about deprecations and removals, including possible alternatives, see Deprecations and Removals.
The Javascript connector executes a JavaScript program that is compiled by the JDK. This program returns a content item which is handed off to the fetcher. The JavaScript program must be standard ECMAScript. You can use any Java class available to the connectors JDK ClassLoader to manipulate that object within a function. As in Java, to access Java classes by their simple names instead of their fully specified class names, e.g. to be able to write String instead of java.lang.String, these classes must be imported. The java.lang package is not imported by default, because its classes would conflict with Object, Boolean, Math, and other built-in JavaScript objects. To import a Java class, use the JavaImporter object and the with statement, which limits the scope of the imported Java packages and classes.
For global variables, you can reference these objects using the Java.type API extension. See this tutorial for details: http://winterbe.com/posts/2014/04/05/java8-nashorn-tutorial/ There is a known issue with JavaImporter that causes intermittent errors with patterns like with (imports) { } *. The preferred approach is Java.type(). A pattern that works well is:
An example of Java.type() usage:

The JavaScript Program

The Javascript context provides the following variables: The program must return one of the following kinds of objects: If the JavaScript script is implemented as a function, the return statement must return one of the above types. If the script is not function-based, the last line in the script must evaluate to one of these object types.

Examples

Return content as a java.lang.String

Return content as a byte array

Return content as a JavaScript array

Return content as a JavaScript map

Leverage the Fetcher

Configuration

When entering configuration values in the UI, use unescaped characters, such as \t for the tab character. When entering configuration values in the API, use escaped characters, such as \\t for the tab character.