@Override
  public boolean hasError(ClientHttpResponse response) throws IOException {
    // checkResponse(response); this is only for debugging purpose

    if (!response.getStatusCode().equals(HttpStatus.OK)) {
      throw new ResponseException(
          "Invalid request, returned with http status " + response.getStatusCode());
    } else if (!supportedMediaTypes.contains(response.getHeaders().getContentType().getSubtype())) {
      throw new ResponseException(
          "Invalid response, contents must be in either "
              + MediaType.APPLICATION_JSON.getSubtype()
              + " or "
              + MediaType.APPLICATION_XML.getSubtype()
              + ", but was "
              + response.getHeaders().getContentType().getSubtype());
    }
    return false;
  }
  /**
   * Responds to the HTTP request with exception. NOTE: Currently, only application/xml content type
   * is supported.
   */
  private void _responseWithException(
      final Exception ex, final HttpStatus http_status, final HttpServletResponse response) {
    _LOG_.error("response with exception: " + ex.getClass().getName() + " - " + ex.getMessage());

    response.setContentType(MediaType.APPLICATION_XML.toString());
    response.setStatus(http_status.value());

    Writer writer = null;
    try {
      writer = response.getWriter();
      _getNvdXmlMapper().marshal(ex, writer);
    } catch (IOException io_ex) {
      _LOG_.error("ERROR in exception handling: " + io_ex);
    } finally {
      if (writer != null) {
        try {
          writer.flush();
          writer.close();
        } catch (Exception ig_ex) {
          _LOG_.warn("ERROR in exception handling: " + ig_ex);
        }
      }
    }
  }
 static {
   supportedMediaTypes.add(MediaType.APPLICATION_JSON.getSubtype());
   supportedMediaTypes.add(MediaType.APPLICATION_XML.getSubtype());
 }