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 2012/06/22 13:14:25 UTC
svn commit: r1352847 - in /httpcomponents/httpcore/trunk:
httpcore-ab/src/main/java/org/apache/http/benchmark/
httpcore/src/main/java/org/apache/http/protocol/
httpcore/src/test/java/org/apache/http/protocol/
Author: olegk
Date: Fri Jun 22 11:14:22 2012
New Revision: 1352847
URL: http://svn.apache.org/viewvc?rev=1352847&view=rev
Log:
Deprecated BasicHttpProcessor in favor of ImmutableHttpProcessor and ChainBuilder
Added:
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java (with props)
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java (with props)
Modified:
httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java
httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestBasicHttpProcessor.java
Modified: httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java?rev=1352847&r1=1352846&r2=1352847&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-ab/src/main/java/org/apache/http/benchmark/BenchmarkWorker.java Fri Jun 22 11:14:22 2012
@@ -48,11 +48,12 @@ import org.apache.http.impl.DefaultConne
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.BasicHttpContext;
-import org.apache.http.protocol.BasicHttpProcessor;
import org.apache.http.protocol.ExecutionContext;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestExecutor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
@@ -70,7 +71,7 @@ class BenchmarkWorker implements Runnabl
private final byte[] buffer = new byte[4096];
private final int verbosity;
private final HttpContext context;
- private final BasicHttpProcessor httpProcessor;
+ private final HttpProcessor httpProcessor;
private final HttpRequestExecutor httpexecutor;
private final ConnectionReuseStrategy connstrategy;
private final HttpRequest request;
@@ -95,17 +96,14 @@ class BenchmarkWorker implements Runnabl
this.count = count;
this.keepalive = keepalive;
- this.httpProcessor = new BasicHttpProcessor();
+ this.httpProcessor = new ImmutableHttpProcessor(
+ new RequestContent(),
+ new RequestTargetHost(),
+ new RequestConnControl(),
+ new RequestUserAgent(),
+ new RequestExpectContinue());
this.httpexecutor = new HttpRequestExecutor();
- // Required request interceptors
- this.httpProcessor.addInterceptor(new RequestContent());
- this.httpProcessor.addInterceptor(new RequestTargetHost());
- // Recommended request interceptors
- this.httpProcessor.addInterceptor(new RequestConnControl());
- this.httpProcessor.addInterceptor(new RequestUserAgent());
- this.httpProcessor.addInterceptor(new RequestExpectContinue());
-
this.connstrategy = new DefaultConnectionReuseStrategy();
this.verbosity = verbosity;
this.socketFactory = socketFactory;
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java?rev=1352847&r1=1352846&r2=1352847&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/BasicHttpProcessor.java Fri Jun 22 11:14:22 2012
@@ -46,8 +46,11 @@ import org.apache.http.annotation.NotThr
* synchronized and therefore this class may be thread-unsafe.
*
* @since 4.0
+ *
+ * @deprecated (4.3)
*/
@NotThreadSafe
+@Deprecated
public final class BasicHttpProcessor implements
HttpProcessor, HttpRequestInterceptorList, HttpResponseInterceptorList, Cloneable {
Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java?rev=1352847&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java Fri Jun 22 11:14:22 2012
@@ -0,0 +1,120 @@
+/*
+ * ====================================================================
+ * 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.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import org.apache.http.annotation.NotThreadSafe;
+
+/**
+ * Builder class to build a linked list (chain) of unique class instances. Each class can have
+ * only one instance in the list. Useful for building lists of protocol interceptors.
+ *
+ * @see ImmutableHttpProcessor
+ *
+ * @since 4.3
+ */
+@NotThreadSafe
+public final class ChainBuilder<E> {
+
+ private final LinkedList<E> list;
+ private final Map<Class<?>, E> uniqueClasses;
+
+ public ChainBuilder() {
+ this.list = new LinkedList<E>();
+ this.uniqueClasses = new HashMap<Class<?>, E>();
+ }
+
+ private void ensureUnique(final E e) {
+ E previous = this.uniqueClasses.remove(e.getClass());
+ if (previous != null) {
+ this.list.remove(previous);
+ }
+ this.uniqueClasses.put(e.getClass(), e);
+ }
+
+ public void addFirst(final E e) {
+ if (e == null) {
+ return;
+ }
+ ensureUnique(e);
+ this.list.addFirst(e);
+ }
+
+ public void addLast(final E e) {
+ if (e == null) {
+ return;
+ }
+ ensureUnique(e);
+ this.list.addLast(e);
+ }
+
+ public void addAllFirst(final Collection<E> c) {
+ if (c == null) {
+ return;
+ }
+ for (E e: c) {
+ addFirst(e);
+ }
+ }
+
+ public void addAllFirst(E... c) {
+ if (c == null) {
+ return;
+ }
+ for (E e: c) {
+ addFirst(e);
+ }
+ }
+
+ public void addAllLast(final Collection<E> c) {
+ if (c == null) {
+ return;
+ }
+ for (E e: c) {
+ addLast(e);
+ }
+ }
+
+ public void addAllLast(E... c) {
+ if (c == null) {
+ return;
+ }
+ for (E e: c) {
+ addLast(e);
+ }
+ }
+
+ public LinkedList<E> build() {
+ return new LinkedList<E>(this.list);
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ChainBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java?rev=1352847&r1=1352846&r2=1352847&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpRequestInterceptorList.java Fri Jun 22 11:14:22 2012
@@ -37,7 +37,10 @@ import org.apache.http.HttpRequestInterc
* for {@link HttpProcessor processing}.
*
* @since 4.0
+ *
+ * @deprecated (4.3)
*/
+@Deprecated
public interface HttpRequestInterceptorList {
/**
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java?rev=1352847&r1=1352846&r2=1352847&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/HttpResponseInterceptorList.java Fri Jun 22 11:14:22 2012
@@ -37,7 +37,10 @@ import org.apache.http.HttpResponseInter
* for {@link HttpProcessor processing}.
*
* @since 4.0
+ *
+ * @deprecated (4.3)
*/
+@Deprecated
public interface HttpResponseInterceptorList {
/**
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java?rev=1352847&r1=1352846&r2=1352847&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java Fri Jun 22 11:14:22 2012
@@ -27,6 +27,7 @@
package org.apache.http.protocol;
import java.io.IOException;
+import java.util.List;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
@@ -51,25 +52,46 @@ public final class ImmutableHttpProcesso
final HttpResponseInterceptor[] responseInterceptors) {
super();
if (requestInterceptors != null) {
- int count = requestInterceptors.length;
- this.requestInterceptors = new HttpRequestInterceptor[count];
- for (int i = 0; i < count; i++) {
- this.requestInterceptors[i] = requestInterceptors[i];
- }
+ int l = requestInterceptors.length;
+ this.requestInterceptors = new HttpRequestInterceptor[l];
+ System.arraycopy(requestInterceptors, 0, this.requestInterceptors, 0, l);
} else {
this.requestInterceptors = new HttpRequestInterceptor[0];
}
if (responseInterceptors != null) {
- int count = responseInterceptors.length;
- this.responseInterceptors = new HttpResponseInterceptor[count];
- for (int i = 0; i < count; i++) {
- this.responseInterceptors[i] = responseInterceptors[i];
- }
+ int l = responseInterceptors.length;
+ this.responseInterceptors = new HttpResponseInterceptor[l];
+ System.arraycopy(responseInterceptors, 0, this.responseInterceptors, 0, l);
+ } else {
+ this.responseInterceptors = new HttpResponseInterceptor[0];
+ }
+ }
+
+ /**
+ * @since 4.3
+ */
+ public ImmutableHttpProcessor(
+ final List<HttpRequestInterceptor> requestInterceptors,
+ final List<HttpResponseInterceptor> responseInterceptors) {
+ super();
+ if (requestInterceptors != null) {
+ int l = requestInterceptors.size();
+ this.requestInterceptors = requestInterceptors.toArray(new HttpRequestInterceptor[l]);
+ } else {
+ this.requestInterceptors = new HttpRequestInterceptor[0];
+ }
+ if (responseInterceptors != null) {
+ int l = responseInterceptors.size();
+ this.responseInterceptors = responseInterceptors.toArray(new HttpResponseInterceptor[l]);
} else {
this.responseInterceptors = new HttpResponseInterceptor[0];
}
}
+ /**
+ * @deprecated (4.3) do not use.
+ */
+ @Deprecated
public ImmutableHttpProcessor(
final HttpRequestInterceptorList requestInterceptors,
final HttpResponseInterceptorList responseInterceptors) {
@@ -94,11 +116,11 @@ public final class ImmutableHttpProcesso
}
}
- public ImmutableHttpProcessor(final HttpRequestInterceptor[] requestInterceptors) {
+ public ImmutableHttpProcessor(final HttpRequestInterceptor... requestInterceptors) {
this(requestInterceptors, null);
}
- public ImmutableHttpProcessor(final HttpResponseInterceptor[] responseInterceptors) {
+ public ImmutableHttpProcessor(final HttpResponseInterceptor... responseInterceptors) {
this(null, responseInterceptors);
}
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestBasicHttpProcessor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestBasicHttpProcessor.java?rev=1352847&r1=1352846&r2=1352847&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestBasicHttpProcessor.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestBasicHttpProcessor.java Fri Jun 22 11:14:22 2012
@@ -35,6 +35,7 @@ import org.apache.http.HttpRequestInterc
import org.junit.Assert;
import org.junit.Test;
+@Deprecated
public class TestBasicHttpProcessor {
static class TestHttpRequestInterceptorPlaceHolder implements HttpRequestInterceptor {
Added: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java?rev=1352847&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java Fri Jun 22 11:14:22 2012
@@ -0,0 +1,68 @@
+/*
+ * ====================================================================
+ * 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.LinkedList;
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.apache.http.HttpRequestInterceptor;
+import org.junit.Test;
+
+public class TestChainBuilder {
+
+ @Test
+ public void testBuildChain() throws Exception {
+ ChainBuilder<HttpRequestInterceptor> cb = new ChainBuilder<HttpRequestInterceptor>();
+ HttpRequestInterceptor i1 = new RequestContent();
+ HttpRequestInterceptor i2 = new RequestTargetHost();
+ HttpRequestInterceptor i3 = new RequestConnControl();
+ HttpRequestInterceptor i4 = new RequestUserAgent();
+ HttpRequestInterceptor i5 = new RequestExpectContinue();
+ cb.addFirst(i1);
+ cb.addAllFirst(i2, i3);
+ cb.addFirst(null);
+ cb.addAllFirst((List<HttpRequestInterceptor>) null);
+ cb.addLast(i4);
+ cb.addLast(null);
+ cb.addAllLast(i5);
+ cb.addAllLast((List<HttpRequestInterceptor>) null);
+ cb.addFirst(i1);
+ cb.addAllLast(i3, i4, i5);
+ LinkedList<HttpRequestInterceptor> list = cb.build();
+ Assert.assertNotNull(list);
+ Assert.assertEquals(5, list.size());
+ Assert.assertSame(i1, list.get(0));
+ Assert.assertSame(i2, list.get(1));
+ Assert.assertSame(i3, list.get(2));
+ Assert.assertSame(i4, list.get(3));
+ Assert.assertSame(i5, list.get(4));
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/protocol/TestChainBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain