From: <pn...@hy...> - 2010-02-03 05:56:05
|
Author: pnguyen Date: 2010-02-02 21:55:57 -0800 (Tue, 02 Feb 2010) New Revision: 14253 URL: http://svn.hyperic.org/?view=rev&root=Hyperic+HQ&revision=14253 Modified: trunk/src/org/hyperic/hq/bizapp/shared/action/SnmpActionConfig.java Log: [HPD-140] Improve data validation and debugging Modified: trunk/src/org/hyperic/hq/bizapp/shared/action/SnmpActionConfig.java =================================================================== --- trunk/src/org/hyperic/hq/bizapp/shared/action/SnmpActionConfig.java 2010-02-02 09:19:37 UTC (rev 14252) +++ trunk/src/org/hyperic/hq/bizapp/shared/action/SnmpActionConfig.java 2010-02-03 05:55:57 UTC (rev 14253) @@ -7,6 +7,8 @@ import org.hyperic.util.config.InvalidOptionException; import org.hyperic.util.config.InvalidOptionValueException; import org.hyperic.util.config.StringConfigOption; +import org.json.JSONArray; +import org.json.JSONException; public class SnmpActionConfig implements ActionConfigInterface { @@ -18,7 +20,7 @@ protected String oid; protected String address; protected String snmpNotificationMechanism; - protected String variableBindings; // in JSON format + protected String variableBindings; // in JSONArray format private static String implementor = "com.hyperic.hq.bizapp.server.action.alert.SnmpAction"; @@ -67,10 +69,24 @@ } /** - * Sets the variable bindings configuration in JSON format + * Sets the variable bindings configuration in JSONArray format */ public void setVariableBindings(String variableBindings) { - this.variableBindings = variableBindings; + try { + if (variableBindings != null + && variableBindings.length() > 0) { + + // validate that the variable bindings is in JSONArray format + JSONArray j = new JSONArray(variableBindings); + this.variableBindings = j.toString(); + } else { + this.variableBindings = variableBindings; + } + } catch (JSONException je) { + throw new IllegalArgumentException( + "Variable bindings must be in a valid JSONArray format:" + + je.getMessage()); + } } /* (non-Javadoc) |