}
@Override
public void run() {
log.debug("Running handler...");
final XMLSerializer serializer = new XMLSerializer();
JSONObject json = null;
try {
json = (JSONObject)JSONSerializer.toJSON(new String(packetData));
} catch(ClassCastException e) {
log.error("Error converting packet to JSON: " + e.getMessage());
return;
} catch(Exception e) {
log.error("Got exception: " + e.getMessage());
return;
}
// check for a timestamp, and add if not already there
if(!json.has("timestamp")) {
json.put("timestamp", new Date().getTime());
}
// set the root to the event output name
serializer.setRootName(config.getEventOutputName());
final String xml = serializer.write(json);
final DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
try {
final DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
final Document document = dBuilder.parse(new ByteArrayInputStream(xml.getBytes()));