@@ -0,0 +1,1731 @@
+package org.ctrip.ops.sysdev.filters;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.concurrent.ArrayBlockingQueue;%0A%0Aimport org.apache.log4j.Logger;%0Aimport org.json.simple.JSONValue;%0A%0Apublic class Json extends BaseFilter %7B%0A%09private static final Logger logger = Logger.getLogger(Json.class.getName());%0A%0A%09public Json(Map config, ArrayBlockingQueue inputQueue) %7B%0A%09%09super(config, inputQueue);%0A%09%7D%0A%0A%09private String tagOnFailure;%0A%09private String field;%0A%09private ArrayList%3CString%3E removeFields;%0A%0A%09protected void prepare() %7B%0A%09%09if (!config.containsKey(%22field%22)) %7B%0A%09%09%09logger.error(%22no field configured in Json%22);%0A%09%09%09System.exit(1);%0A%09%09%7D%0A%09%09this.field = (String) config.get(%22field%22);%0A%0A%09%09this.removeFields = (ArrayList%3CString%3E) this.config%0A%09%09%09%09.get(%22remove_fields%22);%0A%0A%09%09if (config.containsKey(%22tag_on_failure%22)) %7B%0A%09%09%09this.tagOnFailure = (String) config.get(%22tag_on_failure%22);%0A%09%09%7D else %7B%0A%09%09%09this.tagOnFailure = %22jsonfail%22;%0A%09%09%7D%0A%09%7D;%0A%0A%09@Override%0A%09protected Map filter(final Map event) %7B%0A%09%09Map%3CString, Object%3E obj = null;%0A%09%09if (event.containsKey(this.field)) %7B%0A%09%09%09obj = (HashMap%3CString, Object%3E) JSONValue.parse((String) event%0A%09%09%09%09%09.get(field));%0A%0A%09%09%7D%0A%0A%09%09if (obj == null) %7B%0A%09%09%09if (!event.containsKey(%22tags%22)) %7B%0A%09%09%09%09event.put(%22tags%22,%0A%09%09%09%09%09%09new ArrayList%3CString%3E(Arrays.asList(this.tagOnFailure)));%0A%09%09%09%7D else %7B%0A%09%09%09%09Object tags = event.get(%22tags%22);%0A%09%09%09%09if (tags.getClass() == ArrayList.class%0A%09%09%09%09%09%09&& ((ArrayList) tags).indexOf(this.tagOnFailure) == -1) %7B%0A%09%09%09%09%09((ArrayList) tags).add(this.tagOnFailure);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09%09%09event.putAll(obj);%0A%09%09%09if (this.removeFields != null) %7B%0A%09%09%09%09for (String f : this.removeFields) %7B%0A%09%09%09%09%09event.remove(f);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return event;%0A%09%7D%0A%7D%0A

add Json filter