Exemplo n.º 1
0
 private Response doMethod(HttpMethod method, HttpEntity entity, String googleUrl) {
   String url = googleBaseUrl + StringUtils.trimLeadingCharacter(googleUrl, '/');
   LOGGER.info("Doing " + method.toString() + " on url " + url);
   RestTemplate restTemplate = new RestTemplate();
   ResponseEntity<String> response = null;
   try {
     response = restTemplate.exchange(url, method, entity, String.class);
     LOGGER.debug("Response: " + response.getStatusCode() + "; body = " + response.getBody());
     LOGGER.debug("Response headers: " + response.getHeaders().toSingleValueMap());
     return ServerResponse.ok()
         .status(response.getStatusCode().value())
         .entity(response.getBody())
         .build();
   } catch (HttpServerErrorException error5xx) {
     LOGGER.error(error5xx.getMessage(), error5xx);
     if (response != null) {
       return ServerResponse.serverError()
           .status(response.getStatusCode().value())
           .entity(response.getBody())
           .build();
     }
   }
   return null;
 }