class ScriptRunnerTest { public static void main (String[] args) throws Exception { // Get instance of ScriptRunnerConnectionManager ScriptRunnerConnectionManager manager = ScriptRunnerConnectionManager.getInstance(); // Generate ScriptRunnerConnectionFactory ScriptRunnerConnectionFactory factory = manager.createConnectionFactory(); // Set hostname factory.setHost("127.0.0.1"); // Set port number factory.setPort(7700); // Set execution user factory.setUser("test"); // Set execution user's password factory.setPassword("test"); // Set whether to use HTTPS factory.setSSLEnabled(false); ScriptRunnerConnection conn = null; try { // Generate ScriptRunnerConnection conn = factory.newConnection(); // Generate ScriptRunnerParam ScriptRunnerParam param = new ScriptRunnerParam(); // Generate ScriptPK // First argument is "service name", second argument is "script name" // The default form of service name is "user-name@project name" ScriptPK pk = new ScriptPK("test@project", "script"); param.setScriptPK(pk); // Create arguments // When the argument is not passed, it is not required. Map<String, Object> input = new HashMap<String, Object>(); // The input variable of string type is set // Take String type input.put("in.string", "test"); // The input variable of integer type is set // Take Integer type input.put("in.integer", Integer.valueOf(111)); // The input variable of decimal type is set // Take BigDecimal type input.put("in.decimal", new BigDecimal(222)); // The input variable of date type is set // Take Date type input.put("in.date", new Date()); // The input variable of boolean type is set // Take Boolean type input.put("in.boolean", Boolean.valueOf("true")); // The input variable of binary type is set // Take byte[] type input.put("in.binary", new byte[]{0x42, 0x43}); // The input variable of XML type is set // Take the string representation of the XML document input.put("in.xml", "<?xml version=\"1.0\"?><root />"); param.setInput(input); // Create options // When you don't set any option, it is not required. ScriptRunnerOption option = new ScriptRunnerOption(); option.setType(ExecutionTypes.TYPE_PRODUCTION); // Execute by the type for real part. When omitting it, Execute script with ExecutionTypes.TYPE_DEFAULT. // Option.setType ("<user specified type>"); // Execute script by the user specified type.Specify type directly. option.setEnableTypeSwitch(false); option.setEnableXMLLog(true); option.setLogLevel("DEBUG"); param.setOption(option); // Execute and get result ScriptRunnerResult result = conn.execute(param); // Get exit status System.out.println("Exit Status: " + result.getExitStatus()); if (result.isSucceeded()) { // When processing is succeeded Map output = result.getResultData(); for (Object key : output.keySet()) { Object value = output.get(key); if (value == null) { System.out.println(key + "(null): " + value); } else { System.out.println(key + "(" + value.getClass().getName() + "): " + value); } } } else { // When processing is failed for (Failure f = result.getFailure(); f != null; f = f.next()) { System.out.println(f.toString()); } } } finally { if (conn != null) conn.close(); } } }
Type of input variable | Type of Java that can be set | Remarks |
---|---|---|
String | java.lang.String | |
Integer | java.lang.Integer | |
Decimal | java.math.BigDecimal | |
Date/Time | java.util.Date | |
Boolean | java.lang.Boolean | |
Binary | byte[] | |
XML | byte[] or java.lang.String |
Key | Value | Description | Remarks |
---|---|---|---|
TYPE | - | Specify the type when ScriptRunnerProxy executes script. | |
default | Execute script by "Default" type. Also when TYPE is not explicitly specified, "Default" is used at runtime. |
||
test | Execute script by "Test" type. | ||
production | Execute script by "Production" type. | ||
<User-specified type> | Execute script when you register service by the type that the user arbitrarily specified when a global resource is made. | ||
ENABLE_TYPE_SWITCH | - | Set whether to switch and retrieve the type again when a global resource of the specified type doesn't exist. | |
true | Retrieve it again by "Default" type when a global resource of the specified type doesn't exist. | ||
false | When a global resource of the specified type doesn't exist, raise error. When ENABLE_TYPE_SWITCH is omitted It operates as false. |
||
ENABLE_XML_LOG | - | Set ON/OFF of the XML log. | |
true | Output the XML log. | ||
false | Do not output the XML log. (default) | ||
LOG_LEVEL | - | Specify Log Level | |
NOTICE | Logs severe errors that cause premature termination or unexpected conditions that are critical.(default) | ||
INFO | Logs informative runtime events occurred but the messages are kept at its minimum. | ||
FINFO | Logs informative runtime events occurred. | ||
FINEST | Shows more detailed messages than FINFO Log Level. | ||
DEBUG | Provides messages useful for debugging. |
Type of output variable | Type of Java that can be set | Remarks |
---|---|---|
String | java.lang.String | |
Integer | java.lang.Integer | |
Decimal | java.math.BigDecimal | |
Date/Time | java.util.Date | |
Boolean | java.lang.Boolean | |
Binary | byte[] | |
XML | Byte[] or org.w3c.dom.Document |
|
Key | Description | Remarks |
---|---|---|
sun.net.client.defaultReadTimeout | A timeout value in milliseconds until the script execution expires |
|
REM Set the time-out in ten minutes. java -Dsun.net.client.defaultReadTimeout=60000 -cp %CP%;. ScriptRunnerTest |
<target name="execute"> <java classname="ScriptRunnerTest" fork="yes" classpathref="class.path"> <classpath> <pathelement path="." /> </classpath> <!-- Set the time-out in ten minutes. --> <jvmarg value="-Dsun.net.client.defaultReadTimeout=60000"/> </java> </target> |