public RESTResponse call() throws IOException {
  HttpURLConnection urlConnect=null;
  RESTResponse response=new RESTResponse();
  List<String> returnList=new ArrayList<>();
  try {
    URL serviceURL=new URL(path + paramsToString());
    urlConnect=(HttpURLConnection)serviceURL.openConnection();
    if (httpMethod == HTTPMethod.GET) {
      urlConnect.setRequestMethod("GET");
    }
 else {
      urlConnect.setRequestMethod("POST");
      urlConnect.setDoOutput(true);
    }
    urlConnect.setUseCaches(false);
    if (!headers.isEmpty()) {
      for (      Map.Entry<String,String> entry : headers.entrySet()) {
        urlConnect.setRequestProperty(entry.getKey(),entry.getValue());
      }
    }
    if (httpMethod == HTTPMethod.POST) {
      try (DataOutputStream output=new DataOutputStream(urlConnect.getOutputStream())){
        output.writeBytes(postData);
        output.flush();
      }
     }
    response.setResponseCode(urlConnect.getResponseCode());
    try (BufferedReader reader=new BufferedReader(new InputStreamReader(urlConnect.getInputStream()))){
      String line;
      while ((line=reader.readLine()) != null) {
        returnList.add(line);
      }
    }
   }
 catch (  FileNotFoundException|UnknownHostException|ConnectException ex) {
    throw ex;
  }
catch (  IOException ex) {
    if (urlConnect != null) {
      InputStream is=urlConnect.getErrorStream();
      try (BufferedReader br=new BufferedReader(new InputStreamReader(is))){
        String line;
        while ((line=br.readLine()) != null) {
          returnList.add(line);
        }
      }
     }
  }
  response.setContent(returnList);
  return response;
}

public RESTResponse call ( ) throws IOException { HttpURLConnection urlConnect = null ; RESTResponse response = new RESTResponse ( ) ; List < String > returnList = new ArrayList < > ( ) ; try { URL serviceURL = new URL ( path + paramsToString ( ) ) ; urlConnect = ( HttpURLConnection ) serviceURL . openConnection ( ) ; if ( httpMethod == HTTPMethod . GET ) { urlConnect . setRequestMethod ( "GET" ) ; } else { urlConnect . setRequestMethod ( "POST" ) ; urlConnect . setDoOutput ( true ) ; } urlConnect . setUseCaches ( false ) ; if ( ! headers . isEmpty ( ) ) { for ( Map . Entry < String , String > entry : headers . entrySet ( ) ) { urlConnect . setRequestProperty ( entry . getKey ( ) , entry . getValue ( ) ) ; } } if ( httpMethod == HTTPMethod . POST ) { try ( DataOutputStream output = new DataOutputStream ( urlConnect . getOutputStream ( ) ) ) { output . writeBytes ( postData ) ; output . flush ( ) ; } } response . setResponseCode ( urlConnect . getResponseCode ( ) ) ; try ( BufferedReader reader = new BufferedReader ( new InputStreamReader ( urlConnect . getInputStream ( ) ) ) ) { String line ; while ( ( line = reader . readLine ( ) ) != null ) { returnList . add ( line ) ; } } } catch ( FileNotFoundException | UnknownHostException | ConnectException ex ) { throw ex ; } catch ( IOException ex ) { if ( urlConnect != null ) { InputStream is = urlConnect . getErrorStream ( ) ; try ( BufferedReader br = new BufferedReader ( new InputStreamReader ( is ) ) ) { String line ; while ( ( line = br . readLine ( ) ) != null ) { returnList . add ( line ) ; } } } } response . setContent ( returnList ) ; return response ; }
call a rest endpoint , returning its response .
