You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ro...@apache.org on 2007/02/04 13:34:36 UTC

svn commit: r503399 - in /jakarta/httpcomponents/httpcore/trunk: ./ module-main/src/main/java/org/apache/http/protocol/

Author: rolandw
Date: Sun Feb  4 04:34:35 2007
New Revision: 503399

URL: http://svn.apache.org/viewvc?view=rev&rev=503399
Log:
HTTPCORE-32

Added:
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java   (with props)
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java   (with props)
Modified:
    jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
    jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java

Modified: jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt?view=diff&rev=503399&r1=503398&r2=503399
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt (original)
+++ jakarta/httpcomponents/httpcore/trunk/RELEASE_NOTES.txt Sun Feb  4 04:34:35 2007
@@ -1,6 +1,9 @@
 Changes since release 4.0 Alpha 3
 -------------------
 
+* [HTTPCORE-32]: HttpRequestInterceptorList, HttpResponseInterceptorList
+  Contributed by Roland Weber <rolandw at apache.org>
+
 * [HTTPCORE-38]: Packages nio.impl.* are now impl.nio.*, same for examples.
   Contributed by Roland Weber <rolandw at apache.org>
 

Modified: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java?view=diff&rev=503399&r1=503398&r2=503399
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java (original)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java Sun Feb  4 04:34:35 2007
@@ -52,80 +52,127 @@
  * 
  * @since 4.0
  */
-public class BasicHttpProcessor implements HttpProcessor {
+public class BasicHttpProcessor implements
+    HttpProcessor, HttpRequestInterceptorList, HttpResponseInterceptorList {
 
     private List requestInterceptors = null; 
-    private List responseInterceptors = null; 
-    
-    public void addInterceptor(final HttpRequestInterceptor interceptor) {
-        if (interceptor == null) {
+    private List responseInterceptors = null;
+
+
+    // non-Javadoc, see interface HttpRequestInterceptorList
+    public void addRequestInterceptor(final HttpRequestInterceptor itcp) {
+
+        if (itcp == null) {
             return;
         }
         if (this.requestInterceptors == null) {
             this.requestInterceptors = new ArrayList();
         }
-        this.requestInterceptors.add(interceptor);
+        this.requestInterceptors.add(itcp);
     }
-    
-    public void removeInterceptor(final HttpRequestInterceptor interceptor) {
-        if (interceptor == null) {
-            return;
-        }
-        if (this.requestInterceptors == null) {
-            return;
-        }
-        this.requestInterceptors.remove(interceptor);
-        if (this.requestInterceptors.isEmpty()) {
-            this.requestInterceptors = null;
-        }
+
+    /**
+     * Same as {@link #addRequestInterceptor addRequestInterceptor}.
+     *
+     * @param interceptor       the interceptor to add
+     */
+    public final
+        void addInterceptor(final HttpRequestInterceptor interceptor) {
+        addRequestInterceptor(interceptor);
+    }
+
+
+    // non-Javadoc, see interface HttpRequestInterceptorList
+    public int getRequestInterceptorCount() {
+        return (this.requestInterceptors == null) ?
+            0 : this.requestInterceptors.size();
+    }
+
+
+    // non-Javadoc, see interface HttpRequestInterceptorList
+    public HttpRequestInterceptor getRequestInterceptor(int index) {
+        
+        if ((this.requestInterceptors == null) ||
+            (index < 0) || (index >= this.requestInterceptors.size()))
+            return null;
+
+        return (HttpRequestInterceptor) this.requestInterceptors.get(index);
+    }
+
+
+    // non-Javadoc, see interface HttpRequestInterceptorList
+    public void clearRequestInterceptors() {
+        this.requestInterceptors = null;
     }
-    
-    public void addInterceptor(final HttpResponseInterceptor interceptor) {
-        if (interceptor == null) {
+
+
+
+    // non-Javadoc, see interface HttpResponseInterceptorList
+    public void addResponseInterceptor(final HttpResponseInterceptor itcp) {
+        if (itcp == null) {
             return;
         }
         if (this.responseInterceptors == null) {
             this.responseInterceptors = new ArrayList();
         }
-        this.responseInterceptors.add(interceptor);
+        this.responseInterceptors.add(itcp);
     }
-    
-    public void removeInterceptor(final HttpResponseInterceptor interceptor) {
-        if (interceptor == null) {
-            return;
-        }
-        if (this.responseInterceptors == null) {
-            return;
-        }
-        this.responseInterceptors.remove(interceptor);
-        if (this.responseInterceptors.isEmpty()) {
-            this.responseInterceptors = null;
-        }
+
+    /**
+     * Same as {@link #addResponseInterceptor addResponseInterceptor}.
+     *
+     * @param interceptor       the interceptor to add
+     */
+    public final
+        void addInterceptor(final HttpResponseInterceptor interceptor) {
+        addResponseInterceptor(interceptor);
     }
-    
-    public void removeInterceptors(final Class clazz) {
-        if (clazz == null) {
-            return;
-        }
-        if (this.requestInterceptors != null) {
-            for (Iterator i = this.requestInterceptors.iterator(); i.hasNext(); ) {
-                if (clazz.isInstance(i.next())) {
-                    i.remove();
-                }
-            }
-        }
-        if (this.responseInterceptors != null) {
-            for (Iterator i = this.responseInterceptors.iterator(); i.hasNext(); ) {
-                if (clazz.isInstance(i.next())) {
-                    i.remove();
-                }
-            }
-        }
+
+
+    // non-Javadoc, see interface HttpResponseInterceptorList
+    public int getResponseInterceptorCount() {
+        return (this.responseInterceptors == null) ?
+            0 : this.responseInterceptors.size();
     }
 
+
+    // non-Javadoc, see interface HttpResponseInterceptorList
+    public HttpResponseInterceptor getResponseInterceptor(int index) {
+        
+        if ((this.responseInterceptors == null) ||
+            (index < 0) || (index >= this.responseInterceptors.size()))
+            return null;
+
+        return (HttpResponseInterceptor) this.responseInterceptors.get(index);
+    }
+
+
+    // non-Javadoc, see interface HttpResponseInterceptorList
+    public void clearResponseInterceptors() {
+        this.responseInterceptors = null;
+    }
+
+
+    /**
+     * Sets the interceptor lists.
+     * First, both interceptor lists maintained by this processor
+     * will be cleared.
+     * Subsequently,
+     * elements of the argument list that are request interceptors will be
+     * added to the request interceptor list.
+     * Elements that are response interceptors will be
+     * added to the response interceptor list.
+     * Elements that are both request and response interceptor will be
+     * added to both lists.
+     * Elements that are neither request nor response interceptor
+     * will be ignored.
+     *
+     * @param list      the list of request and response interceptors
+     *                  from which to initialize
+     */
     public void setInterceptors(final List list) {
         if (list == null) {
-            return;
+            throw new IllegalArgumentException("List must not be null.");
         }
         if (this.requestInterceptors != null) {
             this.requestInterceptors.clear();
@@ -143,12 +190,16 @@
             }
         }
     }
-    
+
+    /**
+     * Clears both interceptor lists maintained by this processor.
+     */
     public void clearInterceptors() {
-        this.requestInterceptors = null;
-        this.responseInterceptors = null;
+        clearRequestInterceptors();
+        clearResponseInterceptors();
     }
-    
+
+    // non-Javadoc, see interface HttpRequestInterceptor (via HttpProcessor)
     public void process(
             final HttpRequest request,
             final HttpContext context) 
@@ -161,6 +212,7 @@
         }
     }
 
+    // non-Javadoc, see interface HttpResponseInterceptor (via HttpProcessor)
     public void process(
             final HttpResponse response,
             final HttpContext context) 

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java?view=auto&rev=503399
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java Sun Feb  4 04:34:35 2007
@@ -0,0 +1,107 @@
+/*
+ * $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.protocol;
+
+
+import java.util.List;
+
+import org.apache.http.HttpRequestInterceptor;
+
+
+
+/**
+ * Provides access to an ordered list of request interceptors.
+ * Lists are expected to be built upfront and used read-only afterwards
+ * for {@link HttpProcessor processing}.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public interface HttpRequestInterceptorList {
+
+    /**
+     * Appends an interceptor to this list.
+     *
+     * @param itcp      the request interceptor to add, or
+     *                  <code>null</code> to do nothing
+     */
+    void addRequestInterceptor(HttpRequestInterceptor itcp)
+        ;
+
+
+    /**
+     * Obtains the current size of this list.
+     *
+     * @return  the number of request interceptors in this list
+     */
+    int getRequestInterceptorCount()
+        ;
+
+
+    /**
+     * Obtains an interceptor of this list.
+     *
+     * @param index     the index of the interceptor to obtain,
+     *                  0 for first
+     *
+     * @return  the interceptor at the given index, or
+     *          <code>null</code> if the index is out of range
+     */
+    HttpRequestInterceptor getRequestInterceptor(int index)
+        ;
+
+
+    /**
+     * Removes all interceptors from this list.
+     */
+    void clearRequestInterceptors()
+        ;
+
+
+    /**
+     * Sets the interceptors in this list.
+     * This list will be cleared and re-initialized to contain
+     * all request interceptors from the argument list.
+     * If the argument list includes elements that are not request
+     * interceptors, the behavior is implementation dependent.
+     *
+     * @param itcps     the list of request interceptors
+     */
+    void setInterceptors(List itcps)
+        ;
+
+
+} // interface HttpRequestInterceptorList
+

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java?view=auto&rev=503399
==============================================================================
--- jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java (added)
+++ jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java Sun Feb  4 04:34:35 2007
@@ -0,0 +1,106 @@
+/*
+ * $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.protocol;
+
+
+import java.util.List;
+
+import org.apache.http.HttpResponseInterceptor;
+
+
+/**
+ * Provides access to an ordered list of response interceptors.
+ * Lists are expected to be built upfront and used read-only afterwards
+ * for {@link HttpProcessor processing}.
+ *
+ * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
+ *
+ * @version $Revision$
+ * 
+ * @since 4.0
+ */
+public interface HttpResponseInterceptorList {
+
+    /**
+     * Appends an interceptor to this list.
+     *
+     * @param itcp      the response interceptor to add, or
+     *                  <code>null</code> to do nothing
+     */
+    void addResponseInterceptor(HttpResponseInterceptor itcp)
+        ;
+
+
+    /**
+     * Obtains the current size of this list.
+     *
+     * @return  the number of response interceptors in this list
+     */
+    int getResponseInterceptorCount()
+        ;
+
+
+    /**
+     * Obtains an interceptor of this list.
+     *
+     * @param index     the index of the interceptor to obtain,
+     *                  0 for first
+     *
+     * @return  the interceptor at the given index, or
+     *          <code>null</code> if the index is out of range
+     */
+    HttpResponseInterceptor getResponseInterceptor(int index)
+        ;
+
+
+    /**
+     * Removes all interceptors from this list.
+     */
+    void clearResponseInterceptors()
+        ;
+
+
+    /**
+     * Sets the interceptors in this list.
+     * This list will be cleared and re-initialized to contain
+     * all response interceptors from the argument list.
+     * If the argument list includes elements that are not response
+     * interceptors, the behavior is implementation dependent.
+     *
+     * @param itcps     the list of response interceptors
+     */
+    void setInterceptors(List itcps)
+        ;
+
+
+} // interface HttpResponseInterceptorList
+

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain