Package org.apache.http

Examples of org.apache.http.HttpEntity


        HttpContext context = new BasicHttpContext();
        HttpGet httpget = new HttpGet("/oldlocation/");

       
        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }
       
        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
View Full Code Here


       
        HttpGet httpget = new HttpGet("/oldlocation/");

       
        HttpResponse response = client.execute(getServerHttp(), httpget, context);
        HttpEntity e = response.getEntity();
        if (e != null) {
            e.consumeContent();
        }
       
        HttpRequest reqWrapper = (HttpRequest) context.getAttribute(
                ExecutionContext.HTTP_REQUEST);
View Full Code Here

            if (contentType != null){
                String ct = contentType.getValue();
                res.setContentType(ct);
                res.setEncodingAndType(ct);                   
            }
            HttpEntity entity = httpResponse.getEntity();
            if (entity != null) {
                InputStream instream = entity.getContent();
                res.setResponseData(readResponse(res, instream, (int) entity.getContentLength()));
            }
           
            res.sampleEnd(); // Done with the sampling proper.
            currentRequest = null;
View Full Code Here

        T result;
        try {
            result = responseHandler.handleResponse(response);
        } catch (Throwable t) {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                try {
                    entity.consumeContent();
                } catch (Throwable t2) {
                    // Log this exception. The original exception is more
                    // important and will be thrown to the caller.
                    this.log.warn("Error consuming content after an exception.", t2);
                }
            }

            if (t instanceof Error) {
                throw (Error) t;
            }

            if (t instanceof RuntimeException) {
                throw (RuntimeException) t;
            }

            if (t instanceof IOException) {
                throw (IOException) t;
            }
           
            throw new UndeclaredThrowableException(t);
        }

        // Handling the response was successful. Ensure that the content has
        // been fully consumed.
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            // Let this exception go to the caller.
            entity.consumeContent();
        }

        return result;
    }
View Full Code Here

        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

                if (followup == null) {
                    done = true;
                } else {
                    if (reuse) {
                        // Make sure the response body is fully consumed, if present
                        HttpEntity entity = response.getEntity();
                        if (entity != null) {
                            entity.consumeContent();
                        }
                        // entity consumed above is not an auto-release entity,
                        // need to mark the connection re-usable explicitly
                        managedConn.markReusable();
                    } else {
                        managedConn.close();
                    }
                    // check if we can use the same connection for the followup
                    if (!followup.getRoute().equals(roureq.getRoute())) {
                        releaseConnection();
                    }
                    roureq = followup;
                }
               
                userToken = this.userTokenHandler.getUserToken(context);
                context.setAttribute(ClientContext.USER_TOKEN, userToken);
                if (managedConn != null) {
                    managedConn.setState(userToken);
                }
            } // while not done


            // check for entity, release connection if possible
            if ((response == null) || (response.getEntity() == null) ||
                !response.getEntity().isStreaming()) {
                // connection not needed and (assumed to be) in re-usable state
                if (reuse)
                    managedConn.markReusable();
                releaseConnection();
            } else {
                // install an auto-release entity
                HttpEntity entity = response.getEntity();
                entity = new BasicManagedEntity(entity, managedConn, reuse);
                response.setEntity(entity);
            }

            return response;
View Full Code Here

                        // Retry request
                        if (this.reuseStrategy.keepAlive(response, context)) {
                            this.log.debug("Connection kept alive");
                            // Consume response content
                            HttpEntity entity = response.getEntity();
                            if (entity != null) {
                                entity.consumeContent();
                            }               
                        } else {
                            this.managedConn.close();
                        }
                       
                    }
                   
                } else {
                    // Reset proxy auth scope
                    this.proxyAuthState.setAuthScope(null);
                }
            }
        }
       
        int status = response.getStatusLine().getStatusCode();

        if (status > 299) {

            // Buffer response content
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                response.setEntity(new BufferedHttpEntity(entity));
            }               
           
            this.managedConn.close();
View Full Code Here

     @param data the content
     *  @param length Use -1 if unknown
     *  @param createFolders if true, intermediate folders are created via mkdirs
     */
    public void upload(String path, InputStream data, int length, boolean createFolders) throws IOException {
        final HttpEntity e = new InputStreamEntity(data, length);
        if(createFolders) {
            mkdirs(getParentPath(path));
        }
        executor.execute(
        builder.buildOtherRequest(
View Full Code Here

      logger.info("Response code: " + Integer.toString(response.getStatusLine().getStatusCode()));
      if (response.getStatusLine().getStatusCode() != 200){
        throw new Exception("Attempt to download " + layerName + " failed.");
      }
     
      HttpEntity entity = response.getEntity();
      String contentType = entity.getContentType().getValue();
      logger.info("returned content type:" + contentType);
      if (contentType.toLowerCase().contains("xml")){
        String responseContent = EntityUtils.toString(entity);
        logger.error(responseContent);
        throw new Exception("Remote server reported an error");
      }
      File directory = directoryRetriever.getDirectory("download");
      outputFile = new File(directory, OgpFileUtils.filterName(layerName) + ".zip");
      InputStream inputStream = entity.getContent();
      InputStream bufferedIn = new BufferedInputStream(inputStream);
      FileUtils.copyInputStreamToFile(bufferedIn, outputFile);
      bufferedIn.close();
     
    } catch (ClientProtocolException e) {
View Full Code Here

      logger.info("executing get request " + httpget.getURI());

      HttpResponse response = httpclient.execute(httpget);
      this.setStatus(response.getStatusLine().getStatusCode());
      this.setHeaders(response.getAllHeaders());
      HttpEntity entity = response.getEntity();
      this.setContentType(entity.getContentType().getValue());
     
      if (entity != null) {
         replyStream = entity.getContent();
      }
    } catch (ClientProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.http.HttpEntity

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.