@Override public boolean execute() throws Exception { if (_controllerHost == null) { _controllerHost = NetUtil.getHostAddress(); } String stateValue = _state.toLowerCase(); if (!stateValue.equals("enable") && !stateValue.equals("disable") && !stateValue.equals("drop")) { throw new IllegalArgumentException( "Invalid value for state: " + _state + "\n Value must be one of enable|disable|drop"); } HttpClient httpClient = new HttpClient(); HttpURL url = new HttpURL(_controllerHost, Integer.parseInt(_controllerPort), URI_TABLES_PATH + _tableName); url.setQuery("state", stateValue); GetMethod httpGet = new GetMethod(url.getEscapedURI()); int status = httpClient.executeMethod(httpGet); if (status != 200) { throw new RuntimeException("Failed to change table state, error: " + httpGet.getResponseBodyAsString()); } return true; }
/** * Sets the query string from the list of {@link NameValuePair} objects. Both name & value are encoded in the * default encoding. Null or empty list will clear the query string. */ public void setQuery(final List<NameValuePair> nameValuePairs) throws URIException { if ((nameValuePairs == null) || nameValuePairs.isEmpty()) { super.setQuery(null); } else { final String[] names = new String[nameValuePairs.size()]; final String[] values = new String[nameValuePairs.size()]; for (int i = 0; i < nameValuePairs.size(); i++) { final NameValuePair nvp = nameValuePairs.get(i); names[i] = nvp.getName(); values[i] = nvp.getValue(); } super.setQuery(names, values); } }