Package org.apache.http

Examples of org.apache.http.HeaderElementIterator


                new BasicHeader("Name", null),
                new BasicHeader("Name", "    "),
                new BasicHeader("Name", ",,,")
        };

        HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));

        assertFalse(hei.hasNext());
        try {
            hei.next();
            fail("NoSuchElementException should have been thrown");
        } catch (NoSuchElementException ex) {
            // expected
        }

        assertFalse(hei.hasNext());
        try {
            hei.next();
            fail("NoSuchElementException should have been thrown");
        } catch (NoSuchElementException ex) {
            // expected
        }
    }
View Full Code Here


   
    public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
        if (response == null) {
            throw new IllegalArgumentException("HTTP response may not be null");
        }
        HeaderElementIterator it = new BasicHeaderElementIterator(
                response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext()) {
            HeaderElement he = it.nextElement();
            String param = he.getName();
            String value = he.getValue();
            if (value != null && param.equalsIgnoreCase("timeout")) {
                try {
                    return Long.parseLong(value) * 1000;
 
View Full Code Here

        Header[] headers = new Header[]{
                new BasicHeader("name", "value0,value1"),
                new BasicHeader("nAme", "cookie1=1,cookie2=2")
        };

        HeaderElementIterator hei =
                new BasicHeaderElementIterator(new BasicHeaderIterator(headers, "Name"));

        HeaderElement elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value0", elem.getName());
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value1", elem.getName());
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "cookie1", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "1", elem.getValue());

        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "cookie2", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "2", elem.getValue());
    }
View Full Code Here

                new BasicHeader("Name", null),
                new BasicHeader("Name", "    "),
                new BasicHeader("Name", ",,,")
        };

        HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (NoSuchElementException ex) {
            // expected
        }

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (NoSuchElementException ex) {
            // expected
        }
    }
View Full Code Here

        Header[] headers = new Header[]{
                new BasicHeader("Name", "value0"),
                new BasicHeader("Name", "value1")
        };

        HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));

        Assert.assertTrue(hei.hasNext());
        HeaderElement elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value0", elem.getName());

        Assert.assertTrue(hei.hasNext());
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value1", elem.getName());

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (NoSuchElementException ex) {
            // expected
        }

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (NoSuchElementException ex) {
            // expected
        }
    }
View Full Code Here

        final Header[] headers = new Header[]{
                new BasicHeader("Name", "value0"),
                new BasicHeader("Name", "value1")
        };

        final HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));

        Assert.assertTrue(hei.hasNext());
        HeaderElement elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value0", elem.getName());

        Assert.assertTrue(hei.hasNext());
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value1", elem.getName());

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (final NoSuchElementException ex) {
            // expected
        }

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (final NoSuchElementException ex) {
            // expected
        }
    }
View Full Code Here

        final Header[] headers = new Header[]{
                new BasicHeader("name", "value0,value1"),
                new BasicHeader("nAme", "cookie1=1,cookie2=2")
        };

        final HeaderElementIterator hei =
                new BasicHeaderElementIterator(new BasicHeaderIterator(headers, "Name"));

        HeaderElement elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value0", elem.getName());
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "value1", elem.getName());
        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "cookie1", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "1", elem.getValue());

        elem = hei.nextElement();
        Assert.assertEquals("The two header values must be equal",
                "cookie2", elem.getName());
        Assert.assertEquals("The two header values must be equal",
                "2", elem.getValue());
    }
View Full Code Here

                new BasicHeader("Name", null),
                new BasicHeader("Name", "    "),
                new BasicHeader("Name", ",,,")
        };

        final HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (final NoSuchElementException ex) {
            // expected
        }

        Assert.assertFalse(hei.hasNext());
        try {
            hei.next();
            Assert.fail("NoSuchElementException should have been thrown");
        } catch (final NoSuchElementException ex) {
            // expected
        }
    }
View Full Code Here

    {
      @Override
      public long getKeepAliveDuration(HttpResponse response, HttpContext context)
      {
        // Honor 'keep-alive' header
        HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE));
        while (it.hasNext())
        {
          HeaderElement he = it.nextElement();
          String param = he.getName();
          String value = he.getValue();
          if ((value != null) && param.equalsIgnoreCase("timeout"))
          {
            try
View Full Code Here

  private static class DBKeepAliveStrategy implements ConnectionKeepAliveStrategy {
    public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
      // Keep-alive for the shorter of 20 seconds or what the server specifies.
      long timeout = KEEP_ALIVE_DURATION_SECS * 1000;

      HeaderElementIterator i = new BasicHeaderElementIterator(
          response.headerIterator(HTTP.CONN_KEEP_ALIVE));
      while (i.hasNext()) {
        HeaderElement element = i.nextElement();
        String name = element.getName();
        String value = element.getValue();
        if (value != null && name.equalsIgnoreCase("timeout")) {
          try {
            timeout = Math.min(timeout, Long.parseLong(value) * 1000);
 
View Full Code Here

TOP

Related Classes of org.apache.http.HeaderElementIterator

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.