public void abort() { httpResponse.abort(); } public void close() {
@Override public String success(HttpResponse hr) throws Exception { return objectMapper.readValue(hr.getContent(), String.class); } });
@Override public String success(HttpResponse hr) throws Exception { return hr.getETag(); } });
private AttachmentInputStream getAttachment(String attachmentId, URI uri) { HttpResponse r = restTemplate.get(uri.toString()); return new AttachmentInputStream(attachmentId, r.getContent(), r.getContentType(), r.getContentLength()); }
private void handleVoidResponse(HttpResponse hr) { if (hr == null) return; try { if (!hr.isSuccessful()) { new StdResponseHandler<Void>().error(hr); } } finally { hr.releaseConnection(); } }
JsonNode responseBody; try { InputStream content = hr.getContent(); if (content != null) { responseBody = responseBodyAsNode(IOUtils.toString(content)); responseBody = NullNode.getInstance(); switch (hr.getCode()) { case HttpStatus.NOT_FOUND: return new DocumentNotFoundException(hr.getRequestURI(), responseBody); case HttpStatus.CONFLICT: return new UpdateConflictException(); body = "unavailable"; return new DbAccessException(hr.toString() + "\nURI: " + hr.getRequestURI() + "\nResponse Body: \n" + body);
@Override public List<Revision> error(HttpResponse hr) { if (hr.getCode() == HttpStatus.NOT_FOUND) { return Collections.emptyList(); } return super.error(hr); } });
private HttpResponse handleRawResponse(HttpResponse hr) { try { if (!hr.isSuccessful()) { throw StdResponseHandler.createDbAccessException(hr); } return hr; } catch (Exception e) { hr.releaseConnection(); throw Exceptions.propagate(e); } } }
@Override public Boolean error(HttpResponse hr) { if(hr.getCode() == HttpStatus.NOT_FOUND) { // only 404 is a valid response, anything else is an error // see http://docs.couchdb.org/en/latest/api/database/common.html#head--db return false; } throw StdResponseHandler.createDbAccessException(hr); } @Override
@Override public T success(HttpResponse hr) throws Exception { return objectMapper.readValue(hr.getContent(), c); } });
private <T> T handleResponse(ResponseCallback<T> callback, HttpResponse hr) { try { return hr.isSuccessful() ? callback.success(hr) : callback.error(hr); } catch (Exception e) { throw Exceptions.propagate(e); } finally { hr.releaseConnection(); } }
@Override public Boolean error(HttpResponse hr) { if (hr.getCode() == HttpStatus.NOT_FOUND) { return Boolean.FALSE; } throw new DbAccessException(hr.toString()); }
/** * Aborts the stream immediately */ public void abort() { try{ response.abort(); }finally { close(); } } public void close() {
@Override public Security success(HttpResponse hr) throws Exception { return objectMapper.readValue(hr.getContent(), Security.class); } }
@Override public T error(HttpResponse hr) { return hr.getCode() == HttpStatus.NOT_FOUND ? null : super.error(hr); } });
public void run() { try { String line = reader.readLine(); while(shouldRun && line != null) { if (line.length() > 0) { handleChange(line); } else { handleHeartbeat(); } line = reader.readLine(); } String reason = !shouldRun ? "Cancelled" : "EOF"; LOG.info("Changes feed stopped. Reason: " + reason); } catch (Exception e) { handleException(e); } finally { sendInterruptMarker(); httpResponse.abort(); try { reader.close(); } catch (IOException e) {} } }
@Override public String success(HttpResponse hr) throws JsonProcessingException, IOException { return IOUtils.toString(hr.getContent(), "UTF-8"); }
@Override public Boolean error(HttpResponse hr) { if (hr.getCode() == HttpStatus.PRECONDITION_FAILED) { // 412 indicates existing database // see http://docs.couchdb.org/en/latest/api/database/common.html#put--db LOG.debug("database at db path {} already exists.", db.getPath()); return false; } throw StdResponseHandler.createDbAccessException(hr); } @Override
@Override public PurgeResult success(HttpResponse hr) throws Exception { return objectMapper.readValue(hr.getContent(), PurgeResult.class); } });
@Override public T error(HttpResponse hr) { if (hr.getCode() == HttpStatus.CONFLICT) { throw new UpdateConflictException(req.getDocId(), "<Update Handler>"); } return null; } });