code: private <T> T invokeURL(String toBeInvoked, Class<T> returnType) throws SameAsServiceException {
          URL url;
          try {
              url = new URL(toBeInvoked);
          } catch (MalformedURLException e) {
              throw new SameAsServiceException("An error occurred while building the URL '"
                      + toBeInvoked
                      + "'");
          }
  
          URLConnection connection = null;
          Reader reader = null;
  
          if (this.cache != null) {
              lock.lock();
          }
  
          try {
              connection = url.openConnection();
              long lastModified = connection.getLastModified();
  
              if (this.cache != null) {
                  CacheKey cacheKey = new CacheKey(toBeInvoked, lastModified);
                  T cached = this.cache.get(cacheKey, returnType);
                  if (cached != null) {
                      return cached;
                  }
              }
  
              if (connection instanceof HttpURLConnection) {
                  ((HttpURLConnection) connection).connect();
              }
  
              reader = new InputStreamReader(connection.getInputStream());
              Gson gson = this.gsonBuilder.create();
              T response = gson.fromJson(reader, returnType);
  
              if (this.cache != null) {
                  CacheKey cacheKey = new CacheKey(toBeInvoked, lastModified);
                  this.cache.put(cacheKey, response);
              }
  
              return response;
          } catch (IOException e) {
              throw new SameAsServiceException(format("An error occurred while invoking the URL '%s': %s",
                      toBeInvoked,
                      e.getMessage()));
          } catch (JsonParseException e) {
              throw new SameAsServiceException("An error occurred while parsing the JSON response", e);
          } finally {
              if (this.cache != null) {
                  lock.unlock();
              }
  
              if (connection != null && connection instanceof HttpURLConnection) {
                  ((HttpURLConnection) connection).disconnect();
              }
              if (reader != null) {
                  try {
                      reader.close();
                  } catch (IOException e) {
                      // close it quietly
                  }
              }
          }
      }
docs: Invokes a Sameas.org service URL and parses the JSON response.
  
  @param <T> the expected return type.
  @param toBeInvoked the service URL has to be invoked.
  @param returnType the type the JSON response has to be bind to.
  @return the bound object.
  @throws SameAsServiceException is any error occurs.