The JavaClass component executes the specified external JAVA class.
Input | Format | All |
---|---|---|
Number of Inputs | 1 | |
Description | Any stream type can be input. | |
Output | Format | All |
Description |
If the |
Name | Data Type/Selection | Mapping | Description | |
---|---|---|---|---|
ClassName | string | Yes |
Specifies the class name of the external Java class to be executed. |
|
StreamPassThrough | boolean | None |
Specifies whether this component's input stream is to be copied to the output stream. |
|
UserProperties | category | Yes |
Specifies the properties to be set by the external Java class. |
This component cannot be the starting point for a loop.
Commit |
Do Nothing |
---|---|
Rollback |
Do Nothing |
Type | Parameters | Flow Input Stream | Error Code | Cause |
---|---|---|---|---|
Exception | none |
This component's input stream. | none | The ClassName class can not be found. |
none | The external Java class throws an exception. |
An external Java class is executed much like a component is executed.
However, external java classes:
UserProperties
External Java classes must be placed in the ASTERIA_HOME/lib/userlib directory.
FlowService must be restarted after the external Java classes are placed there.
Refer to the Developer's SDK Guide for details on the UserJavaClass, retrieving input stream data, getting variables and setting output streams.
In the code sample below, the sum of the UserProperties
variables a and b is calculated and the result is set to the UserProperties
variable c.
The StreamPassThrough
property is set to True. The UserProperties
variables a, b and c must be defined.
import com.infoteria.asteria.flowengine2.execute.ExecuteContext; import com.infoteria.asteria.flowlibrary2.FlowException; import com.infoteria.asteria.flowlibrary2.component.system.UserJavaClass; import com.infoteria.asteria.value.Value; /** * This class must extend the base class * com.infoteria.asteria.flowlibrary2.component.system.UserJavaClass. */ public class UserClassTest1 extends UserJavaClass { /** This class must implement the execute method. */ public void execute(ExecuteContext context) throws FlowException { context.info("UserClassTest1 execute");//log entries can be written //using the ExecuteContext#info method // UserProperties variables can be retrieved using the // getProperty method. This method returns Value objects. // A Value object has various methods used to retrieve different // formats of the data. For example: // String strValue() // int intValue() Value v1 = getProperty("a"); Value v2 = getProperty("b"); if (v1 == null || v2 == null) throw new FlowException("Required property not found"); // Use the setProperty method to set the value of a // UserProperties variable. setProperty("c", new Value(v1.intValue() + v2.intValue())); } }
In the code sample below, the UserProperties
variables pre and post defined strings are appended to the left and right of the input stream, and this new string is set to the output stream.
The StreamPassThrough
property is set to False. The UserProperties
variables pre and post must be defined.
import com.infoteria.asteria.flowengine2.execute.ExecuteContext; import com.infoteria.asteria.flowlibrary2.FlowException; import com.infoteria.asteria.flowlibrary2.component.system.UserJavaClass; import com.infoteria.asteria.flowlibrary2.stream.StreamFactoryText; import com.infoteria.asteria.value.Value; public class UserClassTest2 extends UserJavaClass { public void execute(ExecuteContext context) throws FlowException { context.info("UserClassTest2 execute"); Value v1 = getProperty("pre"); Value v2 = getProperty("post"); if (v1 == null || v2 == null) throw new FlowException("Required property not found"); // Use the getInputStream method to retrieve the input stream. // This method returns a StreamDataObject object. // The StreamDataObject has various methods that can be // used to get the input stream's data. For example, // String strValue() - returns the input string as a string // byte[] byteValue() - returns the input string binary data StreamDataObject is = getInputStream(); // Use the StreamFactory to create a stream. // Refer to the SDK developer's guide for further details. // Use the setOutputStream method to set the output stream. // The StreamPassThrough property must be set to False. StreamFactoryText factory = (StreamFactoryText)getStreamFactory(); setOutputStream(factory.create(v1.strValue() + is.strValue() + v2.strValue())); } }