/** * Returns the HTTP response code from the origin * {@link cz.msebera.android.httpclient.HttpResponse}. */ public int getStatusCode() { return this.statusLine.getStatusCode(); }
@Override public void setStatusLine(final StatusLine statusline) { this.statusline = Args.notNull(statusline, "Status line"); this.ver = statusline.getProtocolVersion(); this.code = statusline.getStatusCode(); this.reasonPhrase = statusline.getReasonPhrase(); }
/** * Read the entity from the response body and pass it to the entity handler * method if the response was successful (a 2xx status code). If no response * body exists, this returns null. If the response was unsuccessful (>= 300 * status code), throws an {@link HttpResponseException}. */ @Override public T handleResponse(final HttpResponse response) throws HttpResponseException, IOException { final StatusLine statusLine = response.getStatusLine(); final HttpEntity entity = response.getEntity(); if (statusLine.getStatusCode() >= 300) { EntityUtils.consume(entity); throw new HttpResponseException(statusLine.getStatusCode(), statusLine.getReasonPhrase()); } return entity == null ? null : handleEntity(entity); }
final int status = response.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_BAD_REQUEST || status == HttpStatus.SC_REQUEST_TIMEOUT || final ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); if (entity.getContentLength() < 0 && (!entity.isChunked() || ver.lessEquals(HttpVersion.HTTP_1_0))) {
/** * Gets the reason phrase from the origin * {@link cz.msebera.android.httpclient.HttpResponse}, for example, "Not Modified". */ public String getReasonPhrase() { return this.statusLine.getReasonPhrase(); }
/** * Returns the {@link ProtocolVersion} from the origin * {@link cz.msebera.android.httpclient.HttpResponse}. */ public ProtocolVersion getProtocolVersion() { return this.statusLine.getProtocolVersion(); }
protected String loadUrlBody(String address) { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = null; String responseString = null; try { response = httpclient.execute(new HttpGet(address)); StatusLine statusLine = response.getStatusLine(); if(statusLine.getStatusCode() == HttpStatus.SC_OK){ ByteArrayOutputStream out = new ByteArrayOutputStream(); response.getEntity().writeTo(out); out.close(); responseString = out.toString(); } else{ response.getEntity().getContent().close(); throw new IOException(statusLine.getReasonPhrase()); } } catch (ClientProtocolException e) { } catch (IOException e) { } return responseString; }
final ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); final HttpEntity entity = response.getEntity(); if (entity != null) { final int status = response.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED
public String getReasonPhrase() throws Exception { return response.getStatusLine().getReasonPhrase(); }
final ProtocolVersion ver = response.getStatusLine().getProtocolVersion(); final Header teh = response.getFirstHeader(HTTP.TRANSFER_ENCODING); if (teh != null) {
private boolean canResponseHaveBody(final HttpResponse response) { final int status = response.getStatusLine().getStatusCode(); return status >= HttpStatus.SC_OK && status != HttpStatus.SC_NO_CONTENT && status != HttpStatus.SC_NOT_MODIFIED && status != HttpStatus.SC_RESET_CONTENT; }
/** * Creates a response from a status line. * The response will not have a reason phrase catalog and * use the system default locale. * * @param statusline the status line */ public BasicHttpResponse(final StatusLine statusline) { super(); this.statusline = Args.notNull(statusline, "Status line"); this.ver = statusline.getProtocolVersion(); this.code = statusline.getStatusCode(); this.reasonPhrase = statusline.getReasonPhrase(); this.reasonCatalog = null; this.locale = null; }
@Override public boolean shouldBackoff(final HttpResponse resp) { return (resp.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE); }
/** * Creates a new response. * This is the constructor to which all others map. * * @param statusline the status line * @param catalog the reason phrase catalog, or * {@code null} to disable automatic * reason phrase lookup * @param locale the locale for looking up reason phrases, or * {@code null} for the system locale */ public BasicHttpResponse(final StatusLine statusline, final ReasonPhraseCatalog catalog, final Locale locale) { super(); this.statusline = Args.notNull(statusline, "Status line"); this.ver = statusline.getProtocolVersion(); this.code = statusline.getStatusCode(); this.reasonPhrase = statusline.getReasonPhrase(); this.reasonCatalog = catalog; this.locale = locale; }
@Override public boolean retryRequest(final HttpResponse response, final int executionCount, final HttpContext context) { return executionCount <= maxRetries && response.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE; }
/** * Actually formats a status line. * Called from {@link #formatStatusLine}. * * @param buffer the empty buffer into which to format, * never {@code null} * @param statline the status line to format, never {@code null} */ protected void doFormatStatusLine(final CharArrayBuffer buffer, final StatusLine statline) { int len = estimateProtocolVersionLen(statline.getProtocolVersion()) + 1 + 3 + 1; // room for "HTTP/1.1 200 " final String reason = statline.getReasonPhrase(); if (reason != null) { len += reason.length(); } buffer.ensureCapacity(len); appendProtocolVersion(buffer, statline.getProtocolVersion()); buffer.append(' '); buffer.append(Integer.toString(statline.getStatusCode())); buffer.append(' '); // keep whitespace even if reason phrase is empty if (reason != null) { buffer.append(reason); } }
public int getStatusCode() throws IOException { return response.getStatusLine().getStatusCode(); }
private boolean backendResponseMustNotHaveBody(final HttpRequest request, final HttpResponse backendResponse) { return HeaderConstants.HEAD_METHOD.equals(request.getRequestLine().getMethod()) || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NO_CONTENT || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_RESET_CONTENT || backendResponse.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED; }
@Override public boolean isAuthenticationRequested( final HttpHost authhost, final HttpResponse response, final HttpContext context) { Args.notNull(response, "HTTP response"); final int status = response.getStatusLine().getStatusCode(); return status == this.challengeCode; }
public boolean isAuthenticationRequested( final HttpResponse response, final HttpContext context) { Args.notNull(response, "HTTP response"); final int status = response.getStatusLine().getStatusCode(); return status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED; }