package com.enow.storm.ActionTopology;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.storm.task.OutputCollector;
import org.apache.storm.task.ShellBolt;
import org.apache.storm.task.TopologyContext;
import org.apache.storm.topology.IRichBolt;
import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.topology.base.BaseRichBolt;
import org.apache.storm.tuple.Fields;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import java.util.Map;

/*
public class ExecutingBolt extends ShellBolt implements IRichBolt {
    // Call the countbolt.py using Python
    public ExecutingBolt() {
        super("python", "executingBolt.py");
    }

    // Declare that we emit a 'jsonObject'
    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("jsonObject", "message"));
    }

    // Nothing to do for configuration
    @Override
    public Map<String, Object> getComponentConfiguration() {
        return null;
    }
}*/

public class ExecutingBolt extends BaseRichBolt {
    protected static final Logger _LOG = LogManager.getLogger(ProvisioningBolt.class);
    private OutputCollector _collector;

    @Override
    public void prepare(Map MongoConf, TopologyContext context, OutputCollector collector) {
        _collector = collector;
    }

    @Override
    public void execute(Tuple input) {
        JSONObject _jsonObject;
        JSONObject _message = new JSONObject();
        _jsonObject = (JSONObject) input.getValueByField("jsonObject");
        _message.put("succeed", "great!");
        _jsonObject.put("message",_message);


        _collector.emit(new Values(_jsonObject));

        try {
            _LOG.debug("input = [" + input + "]");
            _collector.ack(input);
        } catch (Exception e) {
            _collector.fail(input);
        }
    }

    @Override
    public void declareOutputFields(OutputFieldsDeclarer declarer) {
        declarer.declare(new Fields("jsonObject"));
    }
}
@@ -1571,23 +1571,23 @@
 Object _
-message
+payload
  = new J
@@ -1680,23 +1680,23 @@
        _
-message
+payload
 .put(%22su
@@ -1743,25 +1743,25 @@
 ut(%22
-message%22,_message
+payload%22,_payload
 );%0A%0A

Update ExecutingBolt for testing code