Package org.apache.http

Examples of org.apache.http.HttpResponseInterceptor


        if (!request.containsHeader("Accept-Encoding")) {
          request.addHeader("Accept-Encoding", "gzip, deflate");
        }
      }
    });
    client.addResponseInterceptor(new HttpResponseInterceptor() {
      public void process(
          final org.apache.http.HttpResponse response,
          final HttpContext context) throws HttpException, IOException {
        HttpEntity entity = response.getEntity();
        if (entity != null) {
View Full Code Here


  @Test
  public void testGetSingleFileGzip() throws Exception
  {
    final HttpClientBuilder client = HttpClientBuilder.create();
    client.addInterceptorFirst(new HttpResponseInterceptor()
    {
      public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
      {
        assertEquals(200, r.getStatusLine().getStatusCode());
        assertNotNull(r.getHeaders(HttpHeaders.CONTENT_ENCODING));
View Full Code Here

  @Test
  public void testPutRange() throws Exception
  {
    final HttpClientBuilder client = HttpClientBuilder.create();
    client.addInterceptorFirst(new HttpResponseInterceptor()
    {
      public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
      {
        assertEquals(201, r.getStatusLine().getStatusCode());
      }
    });
    Sardine sardine = new SardineImpl(client);
    // mod_dav supports Range headers for PUT
    final String url = "http://sudo.ch/dav/anon/sardine/" + UUID.randomUUID().toString();
    sardine.put(url, new ByteArrayInputStream("Te".getBytes("UTF-8")));
    try
    {
      // Append to existing file
      final Map<String, String> header = Collections.singletonMap(HttpHeaders.CONTENT_RANGE,
          "bytes " + 2 + "-" + 3 + "/" + 4);

      client.addInterceptorFirst(new HttpRequestInterceptor()
      {
        public void process(final HttpRequest r, final HttpContext context) throws HttpException, IOException
        {
          assertNotNull(r.getHeaders(HttpHeaders.CONTENT_RANGE));
          assertEquals(1, r.getHeaders(HttpHeaders.CONTENT_RANGE).length);
        }
      });
      client.addInterceptorFirst(new HttpResponseInterceptor()
      {
        public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
        {
          assertEquals(204, r.getStatusLine().getStatusCode());
        }
View Full Code Here

  @Test
  public void testGetRange() throws Exception
  {
    final HttpClientBuilder client = HttpClientBuilder.create();
    client.addInterceptorFirst(new HttpResponseInterceptor()
    {
      public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
      {
        // Verify partial content response
        assertEquals(206, r.getStatusLine().getStatusCode());
View Full Code Here

    public void process(
            final HttpResponse response,
            final HttpContext context)
            throws IOException, HttpException {
        for (int i = 0; i < this.responseInterceptors.size(); i++) {
            HttpResponseInterceptor interceptor =
                (HttpResponseInterceptor) this.responseInterceptors.get(i);
            interceptor.process(response, context);
        }
    }
View Full Code Here

    public void sendHttpRequest() throws Exception {

        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/path");
        TestHttpClient client = new TestHttpClient();
        final AtomicReference<ChunkedInputStream> stream = new AtomicReference<>();
        client.addResponseInterceptor(new HttpResponseInterceptor() {

            public void process(final HttpResponse response, final HttpContext context) throws IOException {
                HttpEntity entity = response.getEntity();
                if (entity != null) {
                    InputStream instream = entity.getContent();
View Full Code Here

                    }
                }

            });

            httpClient.addResponseInterceptor(new HttpResponseInterceptor() {

                public void process(final HttpResponse response,
                        final HttpContext context) throws HttpException,
                        IOException {
                    HttpEntity entity = response.getEntity();
View Full Code Here

  @Test
  public void testGetSingleFileGzip() throws Exception
  {
    final DefaultHttpClient client = new DefaultHttpClient();
    client.addResponseInterceptor(new HttpResponseInterceptor()
    {
      public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
      {
        assertEquals(200, r.getStatusLine().getStatusCode());
        assertNotNull(r.getHeaders(HttpHeaders.CONTENT_ENCODING));
View Full Code Here

  {
    final DefaultHttpClient client = new DefaultHttpClient();
    Sardine sardine = new SardineImpl(client);
    // mod_dav supports Range headers for PUT
    final String url = "http://sudo.ch/dav/anon/sardine/" + UUID.randomUUID().toString();
    client.addResponseInterceptor(new HttpResponseInterceptor()
    {
      public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
      {
        assertEquals(201, r.getStatusLine().getStatusCode());
        client.removeResponseInterceptorByClass(this.getClass());
      }
    });
    sardine.put(url, new ByteArrayInputStream("Te".getBytes("UTF-8")));

    try
    {
      // Append to existing file
      final Map<String, String> header = Collections.singletonMap(HttpHeaders.CONTENT_RANGE,
          "bytes " + 2 + "-" + 3 + "/" + 4);

      client.addRequestInterceptor(new HttpRequestInterceptor()
      {
        public void process(final HttpRequest r, final HttpContext context) throws HttpException, IOException
        {
          assertNotNull(r.getHeaders(HttpHeaders.CONTENT_RANGE));
          assertEquals(1, r.getHeaders(HttpHeaders.CONTENT_RANGE).length);
          client.removeRequestInterceptorByClass(this.getClass());
        }
      });
      client.addResponseInterceptor(new HttpResponseInterceptor()
      {
        public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
        {
          assertEquals(204, r.getStatusLine().getStatusCode());
          client.removeResponseInterceptorByClass(this.getClass());
View Full Code Here

  @Test
  public void testGetRange() throws Exception
  {
    final DefaultHttpClient client = new DefaultHttpClient();
    client.addResponseInterceptor(new HttpResponseInterceptor()
    {
      public void process(final HttpResponse r, final HttpContext context) throws HttpException, IOException
      {
        // Verify partial content response
        assertEquals(206, r.getStatusLine().getStatusCode());
View Full Code Here

TOP

Related Classes of org.apache.http.HttpResponseInterceptor

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.