Package org.apache.http.client

Examples of org.apache.http.client.HttpResponseException


     */
    public String handleResponse(final HttpResponse response)
            throws HttpResponseException, IOException {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }

        HttpEntity entity = response.getEntity();
        return entity == null ? null : EntityUtils.toString(entity);
View Full Code Here


            public Content handleResponse(
                    final HttpResponse response) throws ClientProtocolException, IOException {
                StatusLine statusLine = response.getStatusLine();
                HttpEntity entity = response.getEntity();
                if (statusLine.getStatusCode() >= 300) {
                    throw new HttpResponseException(statusLine.getStatusCode(),
                            statusLine.getReasonPhrase());
                }
                if (entity != null) {
                    return new Content(
                            EntityUtils.toByteArray(entity),
View Full Code Here

    public void saveContent(final File file) throws IOException {
        assertNotConsumed();
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }
        FileOutputStream out = new FileOutputStream(file);
        try {
            HttpEntity entity = this.response.getEntity();
View Full Code Here

    HttpGet httpget = new HttpGet(uri);
    HttpResponse response = httpclient.execute(httpget);
    StatusLine statusline = response.getStatusLine();
    if (statusline.getStatusCode() >= HttpStatus.SC_BAD_REQUEST) {
      httpget.abort();
      throw new HttpResponseException(
          statusline.getStatusCode(), statusline.getReasonPhrase());
    }
    HttpEntity entity = response.getEntity();
    if (entity == null) {
      // Should _almost_ never happen with HTTP GET requests.
View Full Code Here

     */
    public String handleResponse(final HttpResponse response)
            throws HttpResponseException, IOException {
        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }

        HttpEntity entity = response.getEntity();
        return entity == null ? null : EntityUtils.toString(entity);
View Full Code Here

                    outputStream.close();
                    outputStream = null;
                    // write ID tags
                    store.writeTrackInfo(track);
                } else {
                    throw new HttpResponseException(statusCode,
                        format("%s: %d %s", url, statusCode, statusLine.getReasonPhrase()));
                }
            } finally {
                close(httpEntity);
                Utils.closeQuietly(outputStream, track.getStore().getDescription());
View Full Code Here

    case HttpStatus.SC_OK:
    case HttpStatus.SC_NO_CONTENT:
      logSuccess(response, bucket, response.getStatusLine().getStatusCode());
      break;
    default:
      throw new HttpResponseException(response.getStatusLine().getStatusCode(),
          "Unexpected response when archiving bucket.");
    }
  }
View Full Code Here

            if (status >= HttpStatus.SC_OK && status < HttpStatus.SC_MULTIPLE_CHOICES) {
                return readResponse(response);
            } if (status == HttpStatus.SC_UNAUTHORIZED) {
                String error = "Unable to perform request. You need to be authenticated.";
                logger.log(Level.SEVERE, error);
                throw new HttpResponseException(status, error);
            } if (status == HttpStatus.SC_BAD_REQUEST) {
                String error = "Unable to perform request since this one seems to be bad... ";
                logger.log(Level.SEVERE, error);
                throw new HttpResponseException(status, error);
            } else {
                String error = EntityUtils.toString(response.getEntity());
                logger.log(Level.SEVERE, "Unexpected response status: {0} - {1}", new Object[]{status, error});
                throw new HttpResponseException(status, error);
            }
        }
View Full Code Here

   public ParseResult handleResponse(HttpResponse response) throws IOException {

      StatusLine statusLine = response.getStatusLine();
      HttpEntity entity = response.getEntity();
      if (statusLine.getStatusCode() >= 300) {
         throw new HttpResponseException(
               statusLine.getStatusCode(),
               statusLine.getReasonPhrase());
      }
      if (entity == null) {
         throw new ClientProtocolException("Response contains no content");
View Full Code Here

        public List<LangSuggestion> handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            StatusLine statusLine = response.getStatusLine();
            HttpEntity entity = response.getEntity();
            if (statusLine.getStatusCode() >= 300) {
                EntityUtils.consume(entity);
                throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
            }
            //parse the results
            InputStream in = null;
            try {
View Full Code Here

TOP

Related Classes of org.apache.http.client.HttpResponseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.