+ private String getJsonResult(String restUrl, String method) {
+ // initialize response code to indicate error
+ httpResponseCode = 400;
+
+ try {
+ URL url = new URL(restUrl);
+
+ this.users.getAuthorizationList();
+ this.users.authenticate("admin", "admin");
+ String authString = "admin:admin";
+ byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
+ String authStringEnc = new String(authEncBytes);
+
+ HttpURLConnection connection = (HttpURLConnection)url.openConnection();
+ connection.setRequestMethod(method);
+ connection.setRequestProperty("Authorization", "Basic "
+ + authStringEnc);
+ connection.setRequestProperty("Content-Type", "application/json");
+ connection.setRequestProperty("Accept", "application/json");
+
+ connection.connect();
+ connection.getContentType();
+
+ // Response code for success should be 2xx
+ httpResponseCode = connection.getResponseCode();
+
+ InputStream is = connection.getInputStream();
+ BufferedReader rd = new BufferedReader(new InputStreamReader(is,
+ Charset.forName("UTF-8")));
+ StringBuilder sb = new StringBuilder();
+ int cp;
+ while ((cp = rd.read()) != -1) {
+ sb.append((char) cp);
+ }
+ is.close();
+ connection.disconnect();
+ return sb.toString();
+ } catch (Exception e) {
+ return null;
+ }
+
+ }
+