The following class "GetData" can retrieve data from Sonarqube. But you have to
import java.net.URL; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; public class GetData { private static String url = "http://10.0.2.74:9000/api/resources?resource=ESB:com.boco.esb.analysismgr.service.impl&metrics=classes"; public static void main(String[] args) { HttpURLConnection myURLConnection = null; int status = -1; String cont = null; try { URL myURL = new URL(url); myURLConnection = (HttpURLConnection)myURL.openConnection(); myURLConnection.connect(); status = myURLConnection.getResponseCode(); switch (status) { case 200: case 201: BufferedReader br = new BufferedReader(new InputStreamReader(myURLConnection.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line+"\n"); } br.close(); cont = sb.toString(); } } catch (MalformedURLException e) { System.out.println("url error"); } catch (IOException e) { System.out.println("other io error"); } System.out.println("my conn ret code: " + status); System.out.println("my conn: " + cont); } }
$ java GetData
my conn ret code: 200 my conn: [{"id":8251,"key":"ESB:com.boco.esb.analysismgr.service.impl","name":"com.boco.esb.analysismgr.service.impl","scope":"DIR","qualifier":"PAC","date":"2013-11-29T17:02:10+0800","lname":"com.boco.esb.analysismgr.service.impl","lang":"java","msr":[{"key":"classes","val":5.0,"frmt_val":"5"}]}]