Java Class

This component executes a java class which has execute() method. The java class should be located under custom directory.

If the execution throws Throwable(Exception), that error is escalated to the caller and that execution is treated as failed. The return value of the method is added to the output data of this component.

Input

Attribute
Description

Class name

Class name with full path - ex) com.xnarum.custom.SampleJava

Timeout

Execution timeout in seconds.

Output

Attribute
Description

ResultValue

Return value from the method execution

Example

This example generates a new parameter and return to the caller.

package com.xnarum.custom;
                        
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
                        
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
                        
public class SampleJavaClassTask {
                        
    private static Logger logger = LoggerFactory.getLogger(SampleJavaClassTask.class);
    public Map execute(Map map, Properties props) {
                                
        logger.info("Received parameters map = {}, props = {}", map, props);
        HashMap newMap = new HashMap();
        newMap.put("Hello", "world");
        try {
            String timeout = props.getProperty("Timeout");
            Thread.sleep(Integer.parseInt(timeout)*1000);
        }catch( Exception ex ) {
            logger.error("Failed to sleep", ex);
        }
        return newMap; 
    }
}
                    

Last updated