Package org.apache.http

Examples of org.apache.http.HeaderElementIterator


        Header[] headers = new Header[]{
                new BasicHeader("Name", "value0"),
                new BasicHeader("Name", "value1")
        };
      
        HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));
       
        assertTrue(hei.hasNext());
        HeaderElement elem = (HeaderElement) hei.next();
        assertEquals("The two header values must be equal",
                "value0", elem.getName());
       
        assertTrue(hei.hasNext());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value1", elem.getName());

        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


        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 = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value0", elem.getName());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value1", elem.getName());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "cookie1", elem.getName());
        assertEquals("The two header values must be equal",
                "1", elem.getValue());
       
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "cookie2", elem.getName());
        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"));
       
        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

  }
 
 
  public Map<String, Integer> getCacheControl() {
    Map<String, Integer> out = new HashMap<String, Integer>();
    HeaderElementIterator it = new BasicHeaderElementIterator(
        this.resp.headerIterator("Cache-Control"));
    while (it.hasNext()) {
        HeaderElement elem = it.nextElement();
        String elemName = elem.getName().toLowerCase();
        Integer v = null;
        if (elemName.equals("max-age") || elemName.equals("s-maxage")) {
          v = new Integer(elem.getValue());
        }
View Full Code Here

    httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {

      public long getKeepAliveDuration(HttpResponse response,
          HttpContext context) {
        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

    httpClient.setKeepAliveStrategy(new ConnectionKeepAliveStrategy() {

      public long getKeepAliveDuration(HttpResponse response,
          HttpContext context) {
        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"),
                new BasicHeader("Name", "value1")
        };
      
        HeaderElementIterator hei =
                new BasicHeaderElementIterator(
                        new BasicHeaderIterator(headers, "Name"));
       
        assertTrue(hei.hasNext());
        HeaderElement elem = (HeaderElement) hei.next();
        assertEquals("The two header values must be equal",
                "value0", elem.getName());
       
        assertTrue(hei.hasNext());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value1", elem.getName());

        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

        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 = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value0", elem.getName());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "value1", elem.getName());
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "cookie1", elem.getName());
        assertEquals("The two header values must be equal",
                "1", elem.getValue());
       
        elem = (HeaderElement)hei.next();
        assertEquals("The two header values must be equal",
                "cookie2", elem.getName());
        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"));
       
        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

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.