Contact Us 1-800-596-4880

Java Module Reference - Mule 4

Java Module v1.2

Java Module is used to invoke Java code.

Release Notes: Java Module Release Notes

Configurations


Default Configuration

Default configuration

Parameters

Name Type Description Default Value Required

Name

String

The name for this configuration. Connectors reference the configuration with this name.

x

Operations

Invoke

<java:invoke>

Invoke methods with the provided arguments in an instance. The identifier of the method to invoke includes the class and method names, being the method a full description of its signature including the types of each parameter.

For example, to invoke the echo method with the signature public String echo(String msg) that belongs to Class org.bar.Me, then the identifier of the method is echo(String).

Parameters

Name Type Description Default Value Required

Instance

Any

The instance on which the method is invoked.

x

Args

Object

The arguments used to invoke a method.

Class

String

Represents the fully qualified name of the class containing the referenced method.

x

Method

String

Represents the method signature containing the method name and its argument types. For example, for the method with signature, public String log(String msg, boolean verbose), then the identifier of the method is log(String, boolean)

x

Target Variable

String

The name of a variable in which to place the operation’s output.

Target Value

String

An expression to evaluate against the operation’s output, and to store the outcome of that expression in the target variable.

#[payload]

Output

Type

Any

Throws

  • JAVA:ARGUMENTS_MISMATCH

  • JAVA:CLASS_NOT_FOUND

  • JAVA:INVOCATION

  • JAVA:NO_SUCH_METHOD

  • JAVA:WRONG_INSTANCE_CLASS

Invoke Static

<java:invoke-static>

Operation that allows the user to invoke static methods with the provided arguments. The identifier of the method to be invoked includes the class and method names, being the method a full description of its signature including the types of each parameter.

For example, to invoke the static method echo with signature public static String echo(String msg) that belongs to Class org.bar.Me, then the identifier of the method is echo(String).

Parameters

Name Type Description Default Value Required

Args

Object

The arguments used to invoke the given Method.

Class

String

Represents the fully qualified name of the Class containing the referenced Method.

x

Method

String

Represents the Method signature containing the method name and its argument types. For example, for the method with signature public static String log(String msg, boolean verbose), then the identifier of the method is log(String, boolean).

x

Target Variable

String

The name of a variable in which to place the operation’s output.

Target Value

String

An expression to evaluate against the operation’s output, and to store the outcome of that expression in the target variable.

#[payload]

Output

Type

Any

Throws

  • JAVA:CLASS_NOT_FOUND

  • JAVA:ARGUMENTS_MISMATCH

  • JAVA:INVOCATION

  • JAVA:WRONG_INSTANCE_CLASS

  • JAVA:NO_SUCH_METHOD

New

<java:new>

Create a new instance of a class.

The identifier of a Constructor includes the class and constructor names, and the constructor has a full description of its signature including the types of each parameter.

For example, to invoke the constructor Me(String name, int age) which belongs to the org.bar.Me class, then the identifier of the method is Me(String,int).

Parameters

Name Type Description Default Value Required

Args

Object

The arguments used to invoke the given Constructor

Class

String

Represents the fully qualified name of the Class containing the referenced Method.

x

Constructor

String

Represents the Constructor signature that contains the name and its argument types. For example, for the Constructor with the public Me(String name, Integer age) signature, then the identifier of the method is Me(String, Integer).

x

Target Variable

String

The name of a variable in which to place the operation’s output.

Target Value

String

An expression to evaluate against the operation’s output, and to store the outcome of that expression in the target variable.

#[payload]

Output

Type

Any

Throws

  • JAVA:ARGUMENTS_MISMATCH

  • JAVA:CLASS_NOT_FOUND

  • JAVA:NO_SUCH_CONSTRUCTOR

  • JAVA:NOT_INSTANTIABLE_TYPE

Validate Type

<java:validate-type>

Validate that an instance is an instanceof a class.

Parameters

Name Type Description Default Value Required

Class

String

Instance

Any

The object whose type is expected to be an instanceof of a class.

x

Accept Subtypes

Boolean

Whether or not to accept subtypes of a class, or if the instance has to be of the exact same class.

true

Throws

  • JAVA:CLASS_NOT_FOUND

  • JAVA:WRONG_INSTANCE_CLASS

View on GitHub