I have a JSON File with key value pairs and I want to put the key value pairs into headers. So when I have a file with content like this:
[{"msgId": "8600C5A3-C666-4E63-BFDB-52BCF557F938", "jiraId": "ERR002"}]
I want to create headers with the name msgId and with value "8600C5A3-C666-4E63-BFDB-52BCF557F938", etc.
Or as an alternative: Is there a way to store the headers of an exchange to a file to which later on the headers can be restored in another exchange?
Thank you.
EDIT: My fork of the example.
public void jsonToHeaders(String body, @Headers Map<String, String> headers) throws ParseException {
LOG.info("Starting JSON conversion...");
LOG.debug("Body input, content: {} ", body);
JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(body);
if (jsonObject != null)
{
String stringValue = null;
String stringKey = null ;
final String NA_STRING = "*** N/A ***";
for (Object key : jsonObject.keySet()) {
stringKey = ((key == null) ? NA_STRING : (String)key);
stringValue = ((jsonObject.get(stringKey) == null) ? NA_STRING : jsonObject.get(stringKey).toString());
headers.put(stringKey, stringValue);
LOG.debug("Processing key {} with value {}", stringKey, stringValue);
}
LOG.info("Done processed JSON: {}", headers.toString());
}
}