Adding post and parameters support to the API Client

This adds a post method to the APIClient to perform POST command on the
API and uses the queryParams API to add query parameters to a query.

Signed-off-by: Amnon Heiman <amnon@cloudius-systems.com>
This commit is contained in:
Amnon Heiman 2015-05-25 16:40:37 +03:00
parent 088c7c356b
commit c7aff5bb5f

View File

@ -10,6 +10,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.json.Json;
import javax.json.JsonArray;
import javax.json.JsonObject;
@ -17,6 +18,7 @@ import javax.json.JsonReader;
import javax.json.JsonReaderFactory;
import javax.json.JsonString;
import javax.management.openmbean.TabularData;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriBuilder;
import com.sun.jersey.api.client.Client;
@ -43,6 +45,22 @@ public class APIClient {
return service.path(path).accept(MediaType.APPLICATION_JSON);
}
public Builder get(String path, MultivaluedMap<String, String> queryParams) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri(getBaseUrl())
.build());
return service.queryParams(queryParams).path(path).accept(MediaType.APPLICATION_JSON);
}
public void post(String path, MultivaluedMap<String, String> queryParams) {
if (queryParams != null) {
get(path, queryParams).post();
return;
}
get(path).post();
}
public String getStringValue(String string) {
if (string != "") {
return get(string).get(String.class);
@ -150,7 +168,7 @@ public class APIClient {
String key = "";
long val = -1;
while (it.hasNext()) {
String k = (String) it.next();
String k = it.next();
System.out.println(k);
if (obj.get(k) instanceof JsonString) {
key = obj.getString(k);