Package org.apache.http

Examples of org.apache.http.TokenIterator


    public void testSingleHeader() {
        Header[] headers = new Header[]{
            new BasicHeader("Name", "token0,token1, token2 , token3")
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token1", "token1", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token2", "token2", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token3", "token3", ti.nextToken());
        assertFalse(ti.hasNext());


        headers = new Header[]{
            new BasicHeader("Name", "token0")
        };
        hit = new BasicHeaderIterator(headers, null);
        ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertFalse(ti.hasNext());
    }
View Full Code Here


            new BasicHeader("Name", "token3 "),
            new BasicHeader("Name", ","),
            new BasicHeader("Name", "token4"),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token1", "token1", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token2", "token2", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token3", "token3", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token4", "token4", ti.nextToken());
        assertFalse(ti.hasNext());
    }
View Full Code Here

            new BasicHeader("Name", ""),
            new BasicHeader("Name", ","),
            new BasicHeader("Name", " ,, "),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertFalse(ti.hasNext());


        hit = new BasicHeaderIterator(headers, "empty");
        ti  = new BasicTokenIterator(hit);

        assertFalse(ti.hasNext());
    }
View Full Code Here

            new BasicHeader("Name", " ,token3"),
            new BasicHeader("Name", ", token4"),
            new BasicHeader("Name", " , token5"),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token1", "token1", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token2", "token2", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token3", "token3", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token4", "token4", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token5", "token5", ti.nextToken());
        assertFalse(ti.hasNext());
    }
View Full Code Here

            new BasicHeader("Name", "token3 ,"),
            new BasicHeader("Name", "token4, "),
            new BasicHeader("Name", "token5 , "),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token1", "token1", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token2", "token2", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token3", "token3", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token4", "token4", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token5", "token5", ti.nextToken());
        assertFalse(ti.hasNext());
    }
View Full Code Here

            new BasicHeader("no", "token0 token1"),
            new BasicHeader("pre", "<token0,token1"),
            new BasicHeader("post", "token0,token1="),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, "in");
        TokenIterator  ti  = new BasicTokenIterator(hit);

        // constructor located token0
        assertTrue(ti.hasNext());
        try {
            ti.nextToken();
            fail("invalid infix character not detected");
        } catch (ParseException px) {
            // expected
        }


        // constructor located token0
        hit = new BasicHeaderIterator(headers, "no");
        ti  = new BasicTokenIterator(hit);
        assertTrue(ti.hasNext());
        try {
            ti.nextToken();
            fail("missing token separator not detected");
        } catch (ParseException px) {
            // expected
        }


        // constructor seeks for the first token
        hit = new BasicHeaderIterator(headers, "pre");
        try {
            new BasicTokenIterator(hit);
            fail("invalid prefix character not detected");
        } catch (ParseException px) {
            // expected
        }


        hit = new BasicHeaderIterator(headers, "post");
        ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
        // failure after the last must not go unpunished
        try {
            ti.nextToken();
            fail("invalid postfix character not detected");
        } catch (ParseException px) {
            // expected
        }
    }
View Full Code Here

            new BasicHeader("Name", ""),
            new BasicHeader("Name", ","),
            new BasicHeader("Name", " ,, "),
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        try {
            // call next() instead of nextToken() to get that covered, too
            ti.next();
            fail("next after end not detected");
        } catch (NoSuchElementException nsx) {
            // expected
        }

        try {
            ti.remove();
            fail("unsupported remove not detected");
        } catch (UnsupportedOperationException uox) {
            // expected
        }
    }
View Full Code Here

        // it takes precedence and indicates a non-persistent connection.
        // If there is no "close" but a "keep-alive", we take the hint.

        if (hit.hasNext()) {
            try {
                TokenIterator ti = createTokenIterator(hit);
                boolean keepalive = false;
                while (ti.hasNext()) {
                    final String token = ti.nextToken();
                    if (HTTP.CONN_CLOSE.equalsIgnoreCase(token)) {
                        return false;
                    } else if (HTTP.CONN_KEEP_ALIVE.equalsIgnoreCase(token)) {
                        // continue the loop, there may be a "close" afterwards
                        keepalive = true;
View Full Code Here

        // it takes precedence and indicates a non-persistent connection.
        // If there is no "close" but a "keep-alive", we take the hint.

        if (hit.hasNext()) {
            try {
                TokenIterator ti = createTokenIterator(hit);
                boolean keepalive = false;
                while (ti.hasNext()) {
                    final String token = ti.nextToken();
                    if (HTTP.CONN_CLOSE.equalsIgnoreCase(token)) {
                        return false;
                    } else if (HTTP.CONN_KEEP_ALIVE.equalsIgnoreCase(token)) {
                        // continue the loop, there may be a "close" afterwards
                        keepalive = true;
View Full Code Here

    public void testSingleHeader() {
        Header[] headers = new Header[]{
            new BasicHeader("Name", "token0,token1, token2 , token3")
        };
        HeaderIterator hit = new BasicHeaderIterator(headers, null);
        TokenIterator  ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token1", "token1", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token2", "token2", ti.nextToken());
        assertTrue(ti.hasNext());
        assertEquals("token3", "token3", ti.nextToken());
        assertFalse(ti.hasNext());


        headers = new Header[]{
            new BasicHeader("Name", "token0")
        };
        hit = new BasicHeaderIterator(headers, null);
        ti  = new BasicTokenIterator(hit);

        assertTrue(ti.hasNext());
        assertEquals("token0", "token0", ti.nextToken());
        assertFalse(ti.hasNext());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.TokenIterator

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.