Skip to content

Instantly share code, notes, and snippets.

@dzimine
Last active August 29, 2015 14:27
Show Gist options
  • Save dzimine/8338dc5b406fa6f90b75 to your computer and use it in GitHub Desktop.
Save dzimine/8338dc5b406fa6f90b75 to your computer and use it in GitHub Desktop.
Java action in StackStorm. Used https://code.google.com/p/json-simple/ DO NOT DELETE - used in blog.stackstorm.com
# /opt/stackstorm/packs/default/actions/jaction.yaml
---
name: jaction
description: Sample of running Java.
runner_type: "local-shell-cmd"
parameters:
cmd:
immutable: true
default: "java MyApp {{p1}} {{p2}}"
cwd:
default: "/opt/stackstorm/packs/default/actions/"
immutable: true
env:
default:
CLASSPATH: lib/*:.
p1:
type: "string"
default: "do"
p2:
type: "string"
default: "something"
//opt/stackstorm/packs/default/actions/MyApp.java
// Used https://code.google.com/p/json-simple/, download and save as lib/json-simple-1.1.1.jar
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
class MyApp
{
public static void main(String[] args)
{
JSONObject obj = new JSONObject();
JSONArray list = new JSONArray();
for (String s: args) {
list.add(s);
}
obj.put("description", "array of arguments");
obj.put("args", list);
System.out.print(obj);
System.out.println();
}
}
foo@bar:/opt/stackstorm/packs/default/actions$ st2 run default.jaction p1=do p2=something
.
id: 55d3c11b5b64c44adab13f5c
status: succeeded
result:
{
"succeeded": true,
"failed": false,
"return_code": 0,
"stderr": "",
"stdout": {
"args": [
"do",
"something"
],
"description": "array of arguments"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment