public static HttpResponse getJson(String urlStr) throws IOException {
        URL url = new URL(urlStr);
        HttpURLConnection urlConnection = (HttpURLConnection) url
                .openConnection();
        urlConnection.addRequestProperty("Accept", "application/json");

        BufferedReader in = null;
        try {
            int errorCode = urlConnection.getResponseCode();
            if ((errorCode <= 202) && (errorCode >= 200)) {
                in = new BufferedReader(new InputStreamReader(
                        urlConnection.getInputStream()));
            } else {
                InputStream error = urlConnection.getErrorStream();
                if (error != null) {
                    in = new BufferedReader(new InputStreamReader(error));
                }
            }

            String json = null;
            if(in != null){
                json = CharStreams.toString(in);
            }
            return new HttpResponse(errorCode, json);
        } finally {
            if(in != null){
                in.close();
            }
        }
    }
public static HttpResponse getJson ( String urlStr ) throws IOException { URL url = new URL ( urlStr ) ; HttpURLConnection urlConnection = ( HttpURLConnection ) url . openConnection ( ) ; urlConnection . addRequestProperty ( "Accept" , "application/json" ) ; BufferedReader in = null ; try { int errorCode = urlConnection . getResponseCode ( ) ; if ( ( errorCode <= 202 ) && ( errorCode >= 200 ) ) { in = new BufferedReader ( new InputStreamReader ( urlConnection . getInputStream ( ) ) ) ; } else { InputStream error = urlConnection . getErrorStream ( ) ; if ( error != null ) { in = new BufferedReader ( new InputStreamReader ( error ) ) ; } } String json = null ; if ( in != null ) { json = CharStreams . toString ( in ) ; } return new HttpResponse ( errorCode , json ) ; } finally { if ( in != null ) { in . close ( ) ; } } }
Invoke REST Service using GET method.

@param urlStr
the REST service URL String.
@return
the HttpResponse.
@throws IOException