Skip to content

Instantly share code, notes, and snippets.

@weissjeffm
Created March 29, 2011 18:28
Show Gist options
  • Select an option

  • Save weissjeffm/892938 to your computer and use it in GitHub Desktop.

Select an option

Save weissjeffm/892938 to your computer and use it in GitHub Desktop.
public static JSONObject getOwnerOfConsumerId(String server, String port, String prefix, String authenticator, String authenticatorPassword, String consumerId) throws JSONException, Exception {
JSONObject jsonOwner = null;
JSONObject jsonConsumer = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(server, port, prefix, authenticator, authenticatorPassword,"/consumers/"+consumerId));
JSONObject jsonOwner_ = (JSONObject) jsonConsumer.getJSONObject("owner");
// Warning: this authenticator, authenticatorPassword needs to be superAdmin
jsonOwner = new JSONObject(CandlepinTasks.getResourceUsingRESTfulAPI(server, port, prefix, authenticator, authenticatorPassword,jsonOwner_.getString("href")));
return jsonOwner;
}
static public String getResourceUsingRESTfulAPI(String server, String port, String prefix, String authenticator, String password, String path) throws Exception {
GetMethod get = new GetMethod("https://"+server+":"+port+prefix+path);
String credentials = authenticator.equals("")? "":"-u "+authenticator+":"+password;
log.info("SSH alternative to HTTP request: curl -k "+credentials+" --request GET https://"+server+":"+port+prefix+path);
return getHTTPResponseAsString(client, get, authenticator, password);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment