You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2007/10/14 15:29:34 UTC
svn commit: r584542 - in /jakarta/httpcomponents/httpcore/trunk: ./
module-main/src/main/java/org/apache/http/
module-main/src/main/java/org/apache/http/message/
module-main/src/main/java/org/apache/http/util/
module-main/src/test/java/org/apache/http/...
Author: olegk
Date: Sun Oct 14 06:29:34 2007
New Revision: 584542
URL: http://svn.apache.org/viewvc?rev=584542&view=rev
Log:
HTTPCORE-121: new interface HeaderElementIterator and its default impl
Contributed by Andrea Selva <selva.andre at gmail.com>
Reviewed by Oleg Kalnichevski
Added:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java (with props)
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java (with props)
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicListHeaderIterator.java
- copied, changed from r584540, jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/ListHeaderIterator.java
jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java (with props)
Removed:
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/ListHeaderIterator.java
Modified:
jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/HeaderGroup.java
jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java
Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?rev=584542&r1=584541&r2=584542&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Sun Oct 14 06:29:34 2007
@@ -1,5 +1,8 @@
Changes since 4.0 Alpha 6
+* [HTTPCORE-121] new interface HeaderElementIterator
+ Contributed by Andrea Selva <selva.andre at gmail.com>
+
* [HTTPCORE-123] Fixed problem with SSLSession losing buffered data, if the
connection has been closed by the peer.
Contributed by Risto Reinpõld <risto.reinpold at gmail.com>
Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java?rev=584542&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java Sun Oct 14 06:29:34 2007
@@ -0,0 +1,61 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http;
+
+import java.util.Iterator;
+
+/**
+ * A type-safe iterator for {@link HeaderElement HeaderElement} objects.
+ *
+ * @version $Revision$
+ */
+public interface HeaderElementIterator extends Iterator {
+
+ /**
+ * Indicates whether there is another header element in this
+ * iteration.
+ *
+ * @return <code>true</code> if there is another header element,
+ * <code>false</code> otherwise
+ */
+ boolean hasNext();
+
+ /**
+ * Obtains the next header element from this iteration.
+ * This method should only be called while {@link #hasNext hasNext}
+ * is true.
+ *
+ * @return the next header element in this iteration
+ */
+ HeaderElement nextElement();
+
+}
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/HeaderElementIterator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java?rev=584542&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java Sun Oct 14 06:29:34 2007
@@ -0,0 +1,113 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation. For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+
+package org.apache.http.message;
+
+import java.util.NoSuchElementException;
+import org.apache.http.HeaderElement;
+import org.apache.http.HeaderElementIterator;
+import org.apache.http.HeaderIterator;
+
+/**
+ * Basic implementation of a {@link HeaderElementIterator}.
+ *
+ * @version $Revision$
+ *
+ * @author Andrea Selva <selva.andre at gmail.com>
+ */
+public class BasicHeaderElementIterator implements HeaderElementIterator {
+
+ private final HeaderIterator headerIt;
+
+ private int currentElementIdx = -1;
+
+ private HeaderElement[] currentElements = null;
+
+ private HeaderElement currentElement = null;
+
+ /**
+ * Creates a new instance of BasicHeaderElementIterator
+ */
+ public BasicHeaderElementIterator(final HeaderIterator headerIterator) {
+ if (headerIterator == null) {
+ throw new IllegalArgumentException("Header iterator may not be null");
+ }
+ this.headerIt = headerIterator;
+
+ if (this.headerIt.hasNext()) {
+ this.currentElementIdx = 0;
+ this.currentElements = this.headerIt.nextHeader().getElements();
+ this.currentElement = findNext();
+ }
+ }
+
+
+ protected HeaderElement findNext() {
+ HeaderElement tmpHeader;
+
+ if (this.currentElementIdx == this.currentElements.length) {
+ if (!this.headerIt.hasNext()) {
+ return null;
+ }
+ this.currentElements = this.headerIt.nextHeader().getElements();
+ this.currentElementIdx = 0;
+ }
+
+ tmpHeader = this.currentElements[this.currentElementIdx++];
+ return tmpHeader;
+
+ }
+
+ public boolean hasNext() {
+ return (this.currentElement != null);
+ }
+
+ public HeaderElement nextElement() throws NoSuchElementException {
+
+ final HeaderElement current = this.currentElement;
+ if (current == null) {
+ throw new NoSuchElementException("Iteration already finished.");
+ }
+
+ this.currentElement = findNext();
+
+ return current;
+ }
+
+ public final Object next() throws NoSuchElementException {
+ return nextElement();
+ }
+
+ public void remove() throws UnsupportedOperationException {
+ throw new UnsupportedOperationException("Remove not supported");
+ }
+
+}
\ No newline at end of file
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicHeaderElementIterator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Copied: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicListHeaderIterator.java (from r584540, jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/ListHeaderIterator.java)
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicListHeaderIterator.java?p2=jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicListHeaderIterator.java&p1=jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/ListHeaderIterator.java&r1=584540&r2=584542&rev=584542&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/ListHeaderIterator.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/message/BasicListHeaderIterator.java Sun Oct 14 06:29:34 2007
@@ -29,7 +29,7 @@
*
*/
-package org.apache.http.util;
+package org.apache.http.message;
import java.util.List;
@@ -45,7 +45,7 @@
*
* @version $Revision$
*/
-public class ListHeaderIterator implements HeaderIterator {
+public class BasicListHeaderIterator implements HeaderIterator {
/**
* A list of headers to iterate over.
@@ -83,7 +83,7 @@
* @param name the name of the headers over which to iterate, or
* <code>null</code> for any
*/
- public ListHeaderIterator(List headers, String name) {
+ public BasicListHeaderIterator(List headers, String name) {
if (headers == null) {
throw new IllegalArgumentException
("Header list must not be null.");
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/HeaderGroup.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/HeaderGroup.java?rev=584542&r1=584541&r2=584542&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/HeaderGroup.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/util/HeaderGroup.java Sun Oct 14 06:29:34 2007
@@ -37,6 +37,7 @@
import org.apache.http.Header;
import org.apache.http.HeaderIterator;
import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicListHeaderIterator;
import org.apache.http.util.CharArrayBuffer;
/**
@@ -258,7 +259,7 @@
* @since 4.0
*/
public HeaderIterator iterator() {
- return new ListHeaderIterator(this.headers, null);
+ return new BasicListHeaderIterator(this.headers, null);
}
/**
@@ -271,7 +272,8 @@
*
* @since 4.0
*/
- public HeaderIterator iterator(String name) {
- return new ListHeaderIterator(this.headers, name);
+ public HeaderIterator iterator(final String name) {
+ return new BasicListHeaderIterator(this.headers, name);
}
+
}
Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java?rev=584542&r1=584541&r2=584542&view=diff
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestAllMessage.java Sun Oct 14 06:29:34 2007
@@ -46,6 +46,7 @@
suite.addTest(TestHeader.suite());
suite.addTest(TestHeaderElement.suite());
suite.addTest(TestBasicHeaderIterator.suite());
+ suite.addTest(TestBasicHeaderElementIterator.suite());
suite.addTest(TestBasicHeaderValueParser.suite());
suite.addTest(TestBasicHeaderValueFormatter.suite());
suite.addTest(TestStatusLine.suite());
Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java?rev=584542&view=auto
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java Sun Oct 14 06:29:34 2007
@@ -0,0 +1,84 @@
+package org.apache.http.message;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.http.Header;
+import org.apache.http.HeaderElement;
+import org.apache.http.HeaderElementIterator;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicHeaderElementIterator;
+import org.apache.http.message.BasicHeaderIterator;
+
+/**
+ * Tests for {@link BasicHeaderElementIterator}.
+ *
+ * @version $Revision$
+ *
+ * @author Andrea Selva <selva.andre at gmail.com>
+ */
+public class TestBasicHeaderElementIterator extends TestCase {
+
+ // ------------------------------------------------------------ Constructor
+ public TestBasicHeaderElementIterator(String testName) {
+ super(testName);
+ }
+
+ // ------------------------------------------------------------------- Main
+ public static void main(String args[]) {
+ String[] testCaseName = { TestBasicHeaderElementIterator.class.getName() };
+ junit.textui.TestRunner.main(testCaseName);
+ }
+
+ // ------------------------------------------------------- TestCase Methods
+ public static Test suite() {
+ return new TestSuite(TestBasicHeaderElementIterator.class);
+ }
+
+ public void testMultiHeader() {
+ Header[] headers = new Header[]{
+ new BasicHeader("Name", "value0"),
+ new BasicHeader("Name", "value1")
+ };
+
+ 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());
+ }
+
+ public void testMultiHeaderSameLine() {
+ 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());
+ }
+
+}
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/test/java/org/apache/http/message/TestBasicHeaderElementIterator.java
------------------------------------------------------------------------------
svn:mime-type = text/plain