Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CDBBCC361 for ; Fri, 22 Jun 2012 11:14:49 +0000 (UTC) Received: (qmail 24450 invoked by uid 500); 22 Jun 2012 11:14:49 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 24402 invoked by uid 500); 22 Jun 2012 11:14:49 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 24380 invoked by uid 99); 22 Jun 2012 11:14:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2012 11:14:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jun 2012 11:14:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 289EC238890B for ; Fri, 22 Jun 2012 11:14:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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/ Date: Fri, 22 Jun 2012 11:14:25 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120622111426.289EC238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 + * . + * + */ + +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 { + + private final LinkedList list; + private final Map, E> uniqueClasses; + + public ChainBuilder() { + this.list = new LinkedList(); + this.uniqueClasses = new HashMap, 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 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 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 build() { + return new LinkedList(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 requestInterceptors, + final List 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 + * . + * + */ + +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 cb = new ChainBuilder(); + 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) null); + cb.addLast(i4); + cb.addLast(null); + cb.addAllLast(i5); + cb.addAllLast((List) null); + cb.addFirst(i1); + cb.addAllLast(i3, i4, i5); + LinkedList 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