public Multistatus handleResponse(HttpResponse response) throws SardineException, IOException { super.validateResponse(response); // Process the response from the server. HttpEntity entity = response.getEntity(); StatusLine statusLine = response.getStatusLine(); if (entity == null) { throw new SardineException( "No entity found in response", statusLine.getStatusCode(), statusLine.getReasonPhrase()); } return this.getMultistatus(entity.getContent()); }
/** * Save an HTTP response to a file. * * @param response the response whose entity content will be saved * @param targetFile the target file, which will be created if necessary * @return true if the operation was successful, false otherwise, in which case the file will not * exist */ public static boolean saveEntityToFile(final HttpResponse response, final File targetFile) { if (response == null) { return false; } try { final boolean saved = saveToFile(response.getEntity().getContent(), targetFile); saveHeader(HEADER_ETAG, saved ? response : null, targetFile); saveHeader(HEADER_LAST_MODIFIED, saved ? response : null, targetFile); return saved; } catch (final IOException e) { Log.e("LocalStorage.saveEntityToFile", e); } return false; }
private String readResult(HttpResponse response) { HttpEntity entity = response.getEntity(); String result = ""; try { result = EntityUtils.toString(entity); } catch (IOException e) { AppLogger.e(e.getMessage()); ActivityUtils.showTips(R.string.timeout); } AppLogger.d(result); return result; }
// Interface to AsyncHttpRequest void sendResponseMessage(HttpResponse response) { StatusLine status = response.getStatusLine(); String responseBody = null; try { HttpEntity entity = null; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); responseBody = EntityUtils.toString(entity, "UTF-8"); } } catch (IOException e) { sendFailureMessage(e, (String) null); } if (status.getStatusCode() >= 300) { sendFailureMessage( new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()), responseBody); } else { sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody); } }