Package org.apache.http

Examples of org.apache.http.HttpEntity


      httppost.setEntity(postEntity);
      logger.info("executing POST request to " + httppost.getURI());
      HttpResponse response = httpclient.execute(httppost);
      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


      }
    }
  }
 
  public void copyResponse(HttpResponse internalResponse, HttpServletResponse externalResponse) throws IOException{
    HttpEntity entity = internalResponse.getEntity();
    //System.out.println(entity.getContentType());
   
    OutputStream outputStream = externalResponse.getOutputStream();
    BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream);
    BufferedInputStream bufferedInputStream = new BufferedInputStream(entity.getContent());

    try {
      int currentBytes;
      while ((currentBytes = bufferedInputStream.read()) != -1) {
         //System.out.println("Receiving " + currentBytes + " bytes");
View Full Code Here

      if (!foundMatch)
        Assert.fail(String.format("Could not find request header matching: %s", header));
    }
    if(request instanceof HttpPost) {
      HttpPost post = (HttpPost)request;
      HttpEntity entity = post.getEntity();
      Parameters actualParameters = extractParameters(entity);

      String [] expectedNames = parameters.getNames();
      String [] actualNames = actualParameters.getNames();
      Arrays.sort(expectedNames);
View Full Code Here

  }

  private void assertParameters(final HttpRequestBase request) throws ArrayComparisonFailure {
    if(request instanceof HttpPost) {
      HttpPost post = (HttpPost)request;
      HttpEntity entity = post.getEntity();
      Parameters actualParameters = extractParameters(entity);

      String [] expectedNames = parameters.getNames();
      String [] actualNames = actualParameters.getNames();
      Arrays.sort(expectedNames);
View Full Code Here

                int polls = 0;
                while ((httpResponse = executor.execute(req).returnResponse())
                        .getStatusLine().getStatusCode() == 200
                        && polls < maxNumberOfPackages) {
                    HttpEntity entity = httpResponse.getEntity();
                    if (entity != null) {
                        final ReplicationPackage responsePackage = packageBuilder.readPackage(resourceResolver, entity.getContent());
                        if (responsePackage != null) {
                            String origin = getHostAndPort(replicationURI);
                            responsePackage.getInfo().setOrigin(origin);
                            result.add(responsePackage);
                        }
View Full Code Here

        Response response = mock(Response.class);
        HttpResponse httpResponse = mock(HttpResponse.class);
        StatusLine statusLine = mock(StatusLine.class);
        when(statusLine.getStatusCode()).thenReturn(200);
        when(httpResponse.getStatusLine()).thenReturn(statusLine);
        HttpEntity entity = mock(HttpEntity.class);
        InputStream stream = new ByteArrayInputStream("package binary stuff".getBytes("UTF-8"));
        when(entity.getContent()).thenReturn(stream);
        when(httpResponse.getEntity()).thenReturn(entity);
        when(response.returnResponse()).thenReturn(httpResponse);
        when(executor.execute(any(Request.class))).thenReturn(response);
        when(authProvider.authenticate(any(Executor.class), any(TransportAuthenticationContext.class))).thenReturn(executor);
        ReplicationEndpoint endpoint = new ReplicationEndpoint("http://127.0.0.1:8080/some/resource");
View Full Code Here

    }

    @Override
    protected void onResponseReceived(final HttpResponse response) {
        this.response = response;
        HttpEntity entity = this.response.getEntity();
        if (entity != null) {
            this.consumer = new BufferingNHttpEntity(entity, this.allocator);
            this.response.setEntity(this.consumer);
        }
    }
View Full Code Here

     */
    private void sendRequestBody(
            final HttpEntityEnclosingRequest request,
            final ClientConnState connState,
            final NHttpClientConnection conn) throws IOException {
        HttpEntity entity = request.getEntity();
        if (entity != null) {

            this.executor.execute(new Runnable() {

                public void run() {
                    try {

                        // Block until previous request is fully processed and
                        // the worker thread no longer holds the shared buffer
                        synchronized (connState) {
                            try {
                                for (;;) {
                                    int currentState = connState.getOutputState();
                                    if (!connState.isWorkerRunning()) {
                                        break;
                                    }
                                    if (currentState == ServerConnState.SHUTDOWN) {
                                        return;
                                    }
                                    connState.wait();
                                }
                            } catch (InterruptedException ex) {
                                connState.shutdown();
                                return;
                            }
                            connState.setWorkerRunning(true);
                        }

                        HttpEntity entity = request.getEntity();
                        OutputStream outstream = new ContentOutputStream(
                                connState.getOutbuffer());
                        entity.writeTo(outstream);
                        outstream.flush();
                        outstream.close();

                        synchronized (connState) {
                            connState.setWorkerRunning(false);
View Full Code Here

    @Override
    protected void onRequestReceived(final HttpRequest request) {
        this.request = request;
        if (request instanceof HttpEntityEnclosingRequest) {
            HttpEntity entity = ((HttpEntityEnclosingRequest) this.request).getEntity();
            if (entity != null) {
                this.consumer = new BufferingNHttpEntity(entity, this.allocator);
                ((HttpEntityEnclosingRequest) this.request).setEntity(this.consumer);
            }
        }
View Full Code Here

        httpExchange.setResponse(response);

        context.setAttribute(ExecutionContext.HTTP_RESPONSE, response);
        this.httpProcessor.process(response, context);

        HttpEntity entity = response.getEntity();
        if (entity != null && !canResponseHaveBody(request, response)) {
            response.setEntity(null);
            entity = null;
        }
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.