src/main/java/util/RESTUtil.java
public <T> T sendGetRestRequest(java.lang.String endPointURL,
                                    Map<String, String> params,
                                    Class<T> responseClass) throws Exception {

        Gson gson = new Gson();

        endPointURL += setGETParams(params);
        //store request
        jsonRequest = endPointURL;
        URL url = new URL(endPointURL);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setConnectTimeout(CONN_TIME_OUT);
        conn.setReadTimeout(READ_TIME_OUT);
        conn.setRequestMethod("GET");
        JsonReader reader =
            new JsonReader(new InputStreamReader(conn.getInputStream()));
        JsonParser parser = new JsonParser();
        JsonElement rootElement = parser.parse(reader);
        if (rootElement.isJsonNull()) {
            return null;
        }
        jsonObject = rootElement.getAsJsonObject();
        if (responseClass == null) {
            return null;
        }
        return gson.fromJson(jsonObject, responseClass);

    }
/** All In One Method for your REST service call , this method is using GET request.
     * @param <T>
     * @param endPointURL : url as string for your REST call with having url params
     * @param params : parameter map to append with URL fill with data u need to pass
     * @param responseClass : pass your class type u want in response:  for Ex: AddressResponse.Class
     * @return your desired object of class which u specified in responseClass param
     * @throws Exception
     */
All In One Method for your REST service call , this method is using GET request.
All In One Method for your REST service call this method is using GET request .
public <T> T sendGetRestRequest(java.lang.String endPointURL,
                                    Map<String, String> params,
                                    Class<T> responseClass) throws Exception {
        Gson gson = new Gson();
        endPointURL += setGETParams(params);
        jsonRequest = endPointURL;
        URL url = new URL(endPointURL);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setConnectTimeout(CONN_TIME_OUT);
        conn.setReadTimeout(READ_TIME_OUT);
        conn.setRequestMethod("GET");
        JsonReader reader =
            new JsonReader(new InputStreamReader(conn.getInputStream()));
        JsonParser parser = new JsonParser();
        JsonElement rootElement = parser.parse(reader);
        if (rootElement.isJsonNull()) {
            return null;
        }
        jsonObject = rootElement.getAsJsonObject();
        if (responseClass == null) {
            return null;
        }
        return gson.fromJson(jsonObject, responseClass);
    }
public < T > T sendGetRestRequest ( java . lang . String endPointURL , Map < String , String > params , Class < T > responseClass ) throws Exception { Gson gson = new Gson ( ) ; endPointURL += setGETParams ( params ) ; jsonRequest = endPointURL ; URL url = new URL ( endPointURL ) ; HttpURLConnection conn = ( HttpURLConnection ) url . openConnection ( ) ; conn . setConnectTimeout ( CONN_TIME_OUT ) ; conn . setReadTimeout ( READ_TIME_OUT ) ; conn . setRequestMethod ( "GET" ) ; JsonReader reader = new JsonReader ( new InputStreamReader ( conn . getInputStream ( ) ) ) ; JsonParser parser = new JsonParser ( ) ; JsonElement rootElement = parser . parse ( reader ) ; if ( rootElement . isJsonNull ( ) ) { return null ; } jsonObject = rootElement . getAsJsonObject ( ) ; if ( responseClass == null ) { return null ; } return gson . fromJson ( jsonObject , responseClass ) ; }
All In One Method for your REST service call , this method is using GET request.
All In One Method for your REST service call this method is using GET request .
//store request