Пример #1
0
 /** @return {@link InputStream} from a {@link HttpResponse} */
 InputStream getStream(HttpResponse response) {
   try {
     return response.getEntity().getContent();
   } catch (Exception e) {
     log.error("Error reading response. " + e.getMessage());
     throw new CouchDbException(e);
   }
 }
Пример #2
0
 /**
  * Validates a HTTP response; on error cases logs status and throws relevant exceptions.
  *
  * @param response The HTTP response.
  */
 private void validate(HttpResponse response) throws IOException {
   int code = response.getStatusLine().getStatusCode();
   if (code == 200 || code == 201 || code == 202) { // success (ok | created | accepted)
     return;
   }
   String msg = format("<< Status: %s (%s) ", code, response.getStatusLine().getReasonPhrase());
   switch (code) {
     case HttpStatus.SC_NOT_FOUND:
       {
         log.info(msg);
         throw new NoDocumentException(msg);
       }
     case HttpStatus.SC_CONFLICT:
       {
         log.warn(msg);
         throw new DocumentConflictException(msg);
       }
     default:
       { // other errors: 400 | 401 | 500 etc.
         log.error(msg += EntityUtils.toString(response.getEntity()));
         throw new CouchDbException(msg);
       }
   }
 }