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 2009/07/11 17:50:32 UTC
svn commit: r793188 [2/2] - in /httpcomponents/httpcore/trunk:
httpcore-nio/src/examples/org/apache/http/examples/nio/
httpcore-nio/src/test/java/org/apache/http/
httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/
httpcore-nio/src/test/java/o...
Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/test/java/org/apache/http/nio/protocol/TestTruncatedChunks.java Sat Jul 11 15:50:30 2009
@@ -42,7 +42,9 @@
import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpStatus;
import org.apache.http.MalformedChunkCodingException;
import org.apache.http.TruncatedChunkException;
@@ -78,12 +80,13 @@
import org.apache.http.nio.util.ByteBufferAllocator;
import org.apache.http.nio.util.HeapByteBufferAllocator;
import org.apache.http.nio.util.SimpleInputBuffer;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpParams;
-import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.HttpContext;
+import org.apache.http.protocol.HttpProcessor;
+import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
@@ -218,7 +221,7 @@
@Override
protected void setUp() throws Exception {
- HttpParams serverParams = new BasicHttpParams();
+ HttpParams serverParams = new SyncBasicHttpParams();
serverParams
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
@@ -228,7 +231,7 @@
this.server = new CustomTestHttpServer(serverParams);
- HttpParams clientParams = new BasicHttpParams();
+ HttpParams clientParams = new SyncBasicHttpParams();
clientParams
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000)
.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 30000)
@@ -285,11 +288,12 @@
Queue<TestJob> queue = new ConcurrentLinkedQueue<TestJob>();
queue.add(testjob);
- BasicHttpProcessor serverHttpProc = new BasicHttpProcessor();
- serverHttpProc.addInterceptor(new ResponseDate());
- serverHttpProc.addInterceptor(new ResponseServer());
- serverHttpProc.addInterceptor(new ResponseContent());
- serverHttpProc.addInterceptor(new ResponseConnControl());
+ HttpProcessor serverHttpProc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
+ new ResponseDate(),
+ new ResponseServer(),
+ new ResponseContent(),
+ new ResponseConnControl()
+ });
AsyncNHttpServiceHandler serviceHandler = new AsyncNHttpServiceHandler(
serverHttpProc,
@@ -302,12 +306,12 @@
serviceHandler.setEventListener(
new SimpleEventListener());
- BasicHttpProcessor clientHttpProc = new BasicHttpProcessor();
- clientHttpProc.addInterceptor(new RequestContent());
- clientHttpProc.addInterceptor(new RequestTargetHost());
- clientHttpProc.addInterceptor(new RequestConnControl());
- clientHttpProc.addInterceptor(new RequestUserAgent());
- clientHttpProc.addInterceptor(new RequestExpectContinue());
+ HttpProcessor clientHttpProc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
+ new RequestContent(),
+ new RequestTargetHost(),
+ new RequestConnControl(),
+ new RequestUserAgent(),
+ new RequestExpectContinue()});
AsyncNHttpClientHandler clientHandler = new AsyncNHttpClientHandler(
clientHttpProc,
@@ -445,11 +449,12 @@
Queue<TestJob> queue = new ConcurrentLinkedQueue<TestJob>();
queue.add(testjob);
- BasicHttpProcessor serverHttpProc = new BasicHttpProcessor();
- serverHttpProc.addInterceptor(new ResponseDate());
- serverHttpProc.addInterceptor(new ResponseServer());
- serverHttpProc.addInterceptor(new ResponseContent());
- serverHttpProc.addInterceptor(new ResponseConnControl());
+ HttpProcessor serverHttpProc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
+ new ResponseDate(),
+ new ResponseServer(),
+ new ResponseContent(),
+ new ResponseConnControl()
+ });
AsyncNHttpServiceHandler serviceHandler = new AsyncNHttpServiceHandler(
serverHttpProc,
@@ -462,12 +467,12 @@
serviceHandler.setEventListener(
new SimpleEventListener());
- BasicHttpProcessor clientHttpProc = new BasicHttpProcessor();
- clientHttpProc.addInterceptor(new RequestContent());
- clientHttpProc.addInterceptor(new RequestTargetHost());
- clientHttpProc.addInterceptor(new RequestConnControl());
- clientHttpProc.addInterceptor(new RequestUserAgent());
- clientHttpProc.addInterceptor(new RequestExpectContinue());
+ HttpProcessor clientHttpProc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
+ new RequestContent(),
+ new RequestTargetHost(),
+ new RequestConnControl(),
+ new RequestUserAgent(),
+ new RequestExpectContinue()});
AsyncNHttpClientHandler clientHandler = new AsyncNHttpClientHandler(
clientHttpProc,
Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpGet.java Sat Jul 11 15:50:30 2009
@@ -35,19 +35,21 @@
import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpHost;
+import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpClientConnection;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
+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,21 +72,21 @@
public static void main(String[] args) throws Exception {
- HttpParams params = new BasicHttpParams();
+ HttpParams params = new SyncBasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
HttpProtocolParams.setUseExpectContinue(params, true);
- BasicHttpProcessor httpproc = new BasicHttpProcessor();
- // Required protocol interceptors
- httpproc.addInterceptor(new RequestContent());
- httpproc.addInterceptor(new RequestTargetHost());
- // Recommended protocol interceptors
- httpproc.addInterceptor(new RequestConnControl());
- httpproc.addInterceptor(new RequestUserAgent());
- httpproc.addInterceptor(new RequestExpectContinue());
-
+ HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
+ // Required protocol interceptors
+ new RequestContent(),
+ new RequestTargetHost(),
+ // Recommended protocol interceptors
+ new RequestConnControl(),
+ new RequestUserAgent(),
+ new RequestExpectContinue()});
+
HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
HttpContext context = new BasicHttpContext(null);
Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpPost.java Sat Jul 11 15:50:30 2009
@@ -37,6 +37,7 @@
import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
+import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.entity.ByteArrayEntity;
@@ -44,15 +45,16 @@
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpClientConnection;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
-import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
+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;
@@ -75,20 +77,20 @@
public static void main(String[] args) throws Exception {
- HttpParams params = new BasicHttpParams();
+ HttpParams params = new SyncBasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUserAgent(params, "HttpComponents/1.1");
HttpProtocolParams.setUseExpectContinue(params, true);
- BasicHttpProcessor httpproc = new BasicHttpProcessor();
- // Required protocol interceptors
- httpproc.addInterceptor(new RequestContent());
- httpproc.addInterceptor(new RequestTargetHost());
- // Recommended protocol interceptors
- httpproc.addInterceptor(new RequestConnControl());
- httpproc.addInterceptor(new RequestUserAgent());
- httpproc.addInterceptor(new RequestExpectContinue());
+ HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpRequestInterceptor[] {
+ // Required protocol interceptors
+ new RequestContent(),
+ new RequestTargetHost(),
+ // Recommended protocol interceptors
+ new RequestConnControl(),
+ new RequestUserAgent(),
+ new RequestExpectContinue()});
HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalHttpServer.java Sat Jul 11 15:50:30 2009
@@ -47,6 +47,7 @@
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpServerConnection;
import org.apache.http.HttpStatus;
import org.apache.http.MethodNotSupportedException;
@@ -56,16 +57,17 @@
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.DefaultHttpServerConnection;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams;
import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.HttpRequestHandlerRegistry;
import org.apache.http.protocol.HttpService;
+import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.ResponseConnControl;
import org.apache.http.protocol.ResponseContent;
import org.apache.http.protocol.ResponseDate;
@@ -178,7 +180,7 @@
public RequestListenerThread(int port, final String docroot) throws IOException {
this.serversocket = new ServerSocket(port);
- this.params = new BasicHttpParams();
+ this.params = new SyncBasicHttpParams();
this.params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
@@ -187,11 +189,12 @@
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up the HTTP protocol processor
- BasicHttpProcessor httpproc = new BasicHttpProcessor();
- httpproc.addInterceptor(new ResponseDate());
- httpproc.addInterceptor(new ResponseServer());
- httpproc.addInterceptor(new ResponseContent());
- httpproc.addInterceptor(new ResponseConnControl());
+ HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[] {
+ new ResponseDate(),
+ new ResponseServer(),
+ new ResponseContent(),
+ new ResponseConnControl()
+ });
// Set up request handlers
HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
Modified: httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/examples/org/apache/http/examples/ElementalReverseProxy.java Sat Jul 11 15:50:30 2009
@@ -42,18 +42,19 @@
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpServerConnection;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpClientConnection;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.DefaultHttpServerConnection;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpParams;
+import org.apache.http.params.SyncBasicHttpParams;
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;
@@ -62,6 +63,7 @@
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.HttpRequestHandlerRegistry;
import org.apache.http.protocol.HttpService;
+import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.RequestConnControl;
import org.apache.http.protocol.RequestContent;
import org.apache.http.protocol.RequestExpectContinue;
@@ -180,7 +182,7 @@
public RequestListenerThread(int port, final HttpHost target) throws IOException {
this.target = target;
this.serversocket = new ServerSocket(port);
- this.params = new BasicHttpParams();
+ this.params = new SyncBasicHttpParams();
this.params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
@@ -189,19 +191,23 @@
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");
// Set up HTTP protocol processor for incoming connections
- BasicHttpProcessor inhttpproc = new BasicHttpProcessor();
- inhttpproc.addInterceptor(new ResponseDate());
- inhttpproc.addInterceptor(new ResponseServer());
- inhttpproc.addInterceptor(new ResponseContent());
- inhttpproc.addInterceptor(new ResponseConnControl());
-
+ HttpProcessor inhttpproc = new ImmutableHttpProcessor(
+ new HttpRequestInterceptor[] {
+ new RequestContent(),
+ new RequestTargetHost(),
+ new RequestConnControl(),
+ new RequestUserAgent(),
+ new RequestExpectContinue()
+ });
+
// Set up HTTP protocol processor for outgoing connections
- BasicHttpProcessor outhttpproc = new BasicHttpProcessor();
- outhttpproc.addInterceptor(new RequestContent());
- outhttpproc.addInterceptor(new RequestTargetHost());
- outhttpproc.addInterceptor(new RequestConnControl());
- outhttpproc.addInterceptor(new RequestUserAgent());
- outhttpproc.addInterceptor(new RequestExpectContinue());
+ HttpProcessor outhttpproc = new ImmutableHttpProcessor(
+ new HttpResponseInterceptor[] {
+ new ResponseDate(),
+ new ResponseServer(),
+ new ResponseContent(),
+ new ResponseConnControl()
+ });
// Set up outgoing request executor
HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/BasicHttpParams.java Sat Jul 11 15:50:30 2009
@@ -46,8 +46,7 @@
*
* @since 4.0
*/
-public final class BasicHttpParams extends AbstractHttpParams
- implements Serializable, Cloneable {
+public class BasicHttpParams extends AbstractHttpParams implements Serializable, Cloneable {
private static final long serialVersionUID = -7086398485908701455L;
@@ -77,7 +76,6 @@
}
}
-
/**
* Assigns the value to all the parameter with the given names
*
@@ -133,11 +131,15 @@
*
* @return a new set of params holding a copy of the
* <i>local</i> parameters in this object.
+ *
+ * @deprecated
*/
public HttpParams copy() {
- BasicHttpParams clone = new BasicHttpParams();
- copyParams(clone);
- return clone;
+ try {
+ return (HttpParams) clone();
+ } catch (CloneNotSupportedException ex) {
+ throw new UnsupportedOperationException("Cloning not supported");
+ }
}
public Object clone() throws CloneNotSupportedException {
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/DefaultedHttpParams.java Sat Jul 11 15:50:30 2009
@@ -57,6 +57,8 @@
/**
* Creates a copy of the local collection with the same default
+ *
+ * @deprecated
*/
public HttpParams copy() {
HttpParams clone = this.local.copy();
Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParams.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/HttpParams.java Sat Jul 11 15:50:30 2009
@@ -77,6 +77,8 @@
* Creates a copy of these parameters.
*
* @return a new set of parameters holding the same values as this one
+ *
+ * @deprecated
*/
HttpParams copy();
Added: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/SyncBasicHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/SyncBasicHttpParams.java?rev=793188&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/SyncBasicHttpParams.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/SyncBasicHttpParams.java Sat Jul 11 15:50:30 2009
@@ -0,0 +1,74 @@
+/*
+ * ====================================================================
+ * 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.params;
+
+/**
+ * Thread-safe extension of the {@link BasicHttpParams}.
+ *
+ * @since 4.1
+ */
+public class SyncBasicHttpParams extends BasicHttpParams {
+
+ private static final long serialVersionUID = 5387834869062660642L;
+
+ public SyncBasicHttpParams() {
+ super();
+ }
+
+ public synchronized boolean removeParameter(final String name) {
+ return super.removeParameter(name);
+ }
+
+ public synchronized HttpParams setParameter(final String name, final Object value) {
+ return super.setParameter(name, value);
+ }
+
+ public synchronized Object getParameter(final String name) {
+ return super.getParameter(name);
+ }
+
+ public synchronized boolean isParameterSet(final String name) {
+ return super.isParameterSet(name);
+ }
+
+ public synchronized boolean isParameterSetLocally(final String name) {
+ return super.isParameterSetLocally(name);
+ }
+
+ public synchronized void setParameters(final String[] names, final Object value) {
+ super.setParameters(names, value);
+ }
+
+ public synchronized void clear() {
+ super.clear();
+ }
+
+ public synchronized Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/SyncBasicHttpParams.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/SyncBasicHttpParams.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/params/SyncBasicHttpParams.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=793188&r1=793187&r2=793188&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 Sat Jul 11 15:50:30 2009
@@ -58,37 +58,29 @@
protected final List requestInterceptors = new ArrayList();
protected final List responseInterceptors = new ArrayList();
- // non-Javadoc, see interface HttpRequestInterceptorList
public void addRequestInterceptor(final HttpRequestInterceptor itcp) {
-
if (itcp == null) {
return;
}
this.requestInterceptors.add(itcp);
}
- // non-Javadoc, see interface HttpRequestInterceptorList
- public void addRequestInterceptor(final HttpRequestInterceptor itcp,
- int index) {
+ public void addRequestInterceptor(
+ final HttpRequestInterceptor itcp, int index) {
if (itcp == null) {
return;
}
-
this.requestInterceptors.add(index, itcp);
}
-
- public void addResponseInterceptor(HttpResponseInterceptor itcp,
- int index) {
+ public void addResponseInterceptor(
+ final HttpResponseInterceptor itcp, int index) {
if (itcp == null) {
return;
}
-
this.responseInterceptors.add(index, itcp);
}
-
- // non-Javadoc, see interface HttpRequestInterceptorList
public void removeRequestInterceptorByClass(final Class clazz) {
for (Iterator it = this.requestInterceptors.iterator();
it.hasNext(); ) {
@@ -99,7 +91,6 @@
}
}
- // non-Javadoc, see interface HttpResponseInterceptorList
public void removeResponseInterceptorByClass(final Class clazz) {
for (Iterator it = this.responseInterceptors.iterator();
it.hasNext(); ) {
@@ -110,47 +101,28 @@
}
}
- /**
- * Same as {@link #addRequestInterceptor(HttpRequestInterceptor) addRequestInterceptor}.
- *
- * @param interceptor the interceptor to add
- */
- public final
- void addInterceptor(final HttpRequestInterceptor interceptor) {
+ public final void addInterceptor(final HttpRequestInterceptor interceptor) {
addRequestInterceptor(interceptor);
}
- public final
- void addInterceptor(final HttpRequestInterceptor interceptor,
- int index) {
+ public final void addInterceptor(final HttpRequestInterceptor interceptor, int index) {
addRequestInterceptor(interceptor, index);
}
-
- // non-Javadoc, see interface HttpRequestInterceptorList
public int getRequestInterceptorCount() {
return this.requestInterceptors.size();
}
-
- // non-Javadoc, see interface HttpRequestInterceptorList
public HttpRequestInterceptor getRequestInterceptor(int index) {
-
if ((index < 0) || (index >= this.requestInterceptors.size()))
return null;
-
return (HttpRequestInterceptor) this.requestInterceptors.get(index);
}
-
- // non-Javadoc, see interface HttpRequestInterceptorList
public void clearRequestInterceptors() {
this.requestInterceptors.clear();
}
-
-
- // non-Javadoc, see interface HttpResponseInterceptorList
public void addResponseInterceptor(final HttpResponseInterceptor itcp) {
if (itcp == null) {
return;
@@ -158,45 +130,28 @@
this.responseInterceptors.add(itcp);
}
- /**
- * Same as {@link #addResponseInterceptor(HttpResponseInterceptor) addResponseInterceptor}.
- *
- * @param interceptor the interceptor to add
- */
- public final
- void addInterceptor(final HttpResponseInterceptor interceptor) {
+ public final void addInterceptor(final HttpResponseInterceptor interceptor) {
addResponseInterceptor(interceptor);
}
- public final void addInterceptor(final HttpResponseInterceptor interceptor,
- int index) {
+ public final void addInterceptor(final HttpResponseInterceptor interceptor, int index) {
addResponseInterceptor(interceptor, index);
}
-
-
- // non-Javadoc, see interface HttpResponseInterceptorList
public int getResponseInterceptorCount() {
return this.responseInterceptors.size();
}
-
- // non-Javadoc, see interface HttpResponseInterceptorList
public HttpResponseInterceptor getResponseInterceptor(int index) {
-
if ((index < 0) || (index >= this.responseInterceptors.size()))
return null;
-
return (HttpResponseInterceptor) this.responseInterceptors.get(index);
}
-
- // non-Javadoc, see interface HttpResponseInterceptorList
public void clearResponseInterceptors() {
this.responseInterceptors.clear();
}
-
/**
* Sets the interceptor lists.
* First, both interceptor lists maintained by this processor
@@ -239,7 +194,6 @@
clearResponseInterceptors();
}
- // non-Javadoc, see interface HttpRequestInterceptor (via HttpProcessor)
public void process(
final HttpRequest request,
final HttpContext context)
@@ -251,7 +205,6 @@
}
}
- // non-Javadoc, see interface HttpResponseInterceptor (via HttpProcessor)
public void process(
final HttpResponse response,
final HttpContext context)
Added: 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=793188&view=auto
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java (added)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java Sat Jul 11 15:50:30 2009
@@ -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.io.IOException;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
+
+/**
+ * Immutable {@link HttpProcessor}.
+ *
+ * @since 4.1
+ */
+//@ThreadSafe
+public final class ImmutableHttpProcessor implements HttpProcessor {
+
+ private final HttpRequestInterceptor[] requestInterceptors;
+ private final HttpResponseInterceptor[] responseInterceptors;
+
+ public ImmutableHttpProcessor(
+ final HttpRequestInterceptor[] requestInterceptors,
+ 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];
+ }
+ } 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];
+ }
+ } else {
+ this.responseInterceptors = new HttpResponseInterceptor[0];
+ }
+ }
+
+ public ImmutableHttpProcessor(
+ final HttpRequestInterceptorList requestInterceptors,
+ final HttpResponseInterceptorList responseInterceptors) {
+ super();
+ if (requestInterceptors != null) {
+ int count = requestInterceptors.getRequestInterceptorCount();
+ this.requestInterceptors = new HttpRequestInterceptor[count];
+ for (int i = 0; i < count; i++) {
+ this.requestInterceptors[i] = requestInterceptors.getRequestInterceptor(i);
+ }
+ } else {
+ this.requestInterceptors = new HttpRequestInterceptor[0];
+ }
+ if (responseInterceptors != null) {
+ int count = responseInterceptors.getResponseInterceptorCount();
+ this.responseInterceptors = new HttpResponseInterceptor[count];
+ for (int i = 0; i < count; i++) {
+ this.responseInterceptors[i] = responseInterceptors.getResponseInterceptor(i);
+ }
+ } else {
+ this.responseInterceptors = new HttpResponseInterceptor[0];
+ }
+ }
+
+ public ImmutableHttpProcessor(final HttpRequestInterceptor[] requestInterceptors) {
+ this(requestInterceptors, null);
+ }
+
+ public ImmutableHttpProcessor(final HttpResponseInterceptor[] responseInterceptors) {
+ this(null, responseInterceptors);
+ }
+
+ public void process(
+ final HttpRequest request,
+ final HttpContext context) throws IOException, HttpException {
+ for (int i = 0; i < this.requestInterceptors.length; i++) {
+ this.requestInterceptors[i].process(request, context);
+ }
+ }
+
+ public void process(
+ final HttpResponse response,
+ final HttpContext context) throws IOException, HttpException {
+ for (int i = 0; i < this.responseInterceptors.length; i++) {
+ this.responseInterceptors[i].process(response, context);
+ }
+ }
+
+}
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/protocol/ImmutableHttpProcessor.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpClient.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpClient.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpClient.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpClient.java Sat Jul 11 15:50:30 2009
@@ -38,19 +38,21 @@
import org.apache.http.HttpException;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.DefaultedHttpParams;
-import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.ExecutionContext;
+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;
@@ -60,32 +62,30 @@
public class TestHttpClient {
private final HttpParams params;
- private final BasicHttpProcessor httpproc;
+ private final HttpProcessor httpproc;
private final HttpRequestExecutor httpexecutor;
private final ConnectionReuseStrategy connStrategy;
private final HttpContext context;
public TestHttpClient() {
super();
- this.params = new BasicHttpParams();
+ this.params = new SyncBasicHttpParams();
this.params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1)
.setParameter(CoreProtocolPNames.USER_AGENT, "TEST-CLIENT/1.1");
-
- this.httpproc = new BasicHttpProcessor();
- // Required protocol interceptors
- this.httpproc.addInterceptor(new RequestContent());
- this.httpproc.addInterceptor(new RequestTargetHost());
- // Recommended protocol interceptors
- this.httpproc.addInterceptor(new RequestConnControl());
- this.httpproc.addInterceptor(new RequestUserAgent());
- this.httpproc.addInterceptor(new RequestExpectContinue());
-
+ this.httpproc = new ImmutableHttpProcessor(
+ new HttpRequestInterceptor[] {
+ new RequestContent(),
+ new RequestTargetHost(),
+ new RequestConnControl(),
+ new RequestUserAgent(),
+ new RequestExpectContinue()
+ });
this.httpexecutor = new HttpRequestExecutor();
this.connStrategy = new DefaultConnectionReuseStrategy();
- this.context = new BasicHttpContext(null);
+ this.context = new BasicHttpContext();
}
public HttpParams getParams() {
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/mockup/TestHttpServer.java Sat Jul 11 15:50:30 2009
@@ -41,21 +41,23 @@
import org.apache.http.ConnectionReuseStrategy;
import org.apache.http.HttpException;
import org.apache.http.HttpResponseFactory;
+import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpServerConnection;
import org.apache.http.impl.DefaultConnectionReuseStrategy;
import org.apache.http.impl.DefaultHttpResponseFactory;
import org.apache.http.impl.DefaultHttpServerConnection;
-import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
import org.apache.http.params.HttpParams;
import org.apache.http.params.CoreProtocolPNames;
-import org.apache.http.protocol.BasicHttpProcessor;
+import org.apache.http.params.SyncBasicHttpParams;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpExpectationVerifier;
+import org.apache.http.protocol.HttpProcessor;
import org.apache.http.protocol.HttpRequestHandler;
import org.apache.http.protocol.HttpRequestHandlerRegistry;
import org.apache.http.protocol.HttpService;
+import org.apache.http.protocol.ImmutableHttpProcessor;
import org.apache.http.protocol.ResponseConnControl;
import org.apache.http.protocol.ResponseContent;
import org.apache.http.protocol.ResponseDate;
@@ -64,7 +66,7 @@
public class TestHttpServer {
private final HttpParams params;
- private final BasicHttpProcessor httpproc;
+ private final HttpProcessor httpproc;
private final ConnectionReuseStrategy connStrategy;
private final HttpResponseFactory responseFactory;
private final HttpRequestHandlerRegistry reqistry;
@@ -77,18 +79,20 @@
public TestHttpServer() throws IOException {
super();
- this.params = new BasicHttpParams();
+ this.params = new SyncBasicHttpParams();
this.params
.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
.setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
.setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
.setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
.setParameter(CoreProtocolPNames.ORIGIN_SERVER, "TEST-SERVER/1.1");
- this.httpproc = new BasicHttpProcessor();
- this.httpproc.addInterceptor(new ResponseDate());
- this.httpproc.addInterceptor(new ResponseServer());
- this.httpproc.addInterceptor(new ResponseContent());
- this.httpproc.addInterceptor(new ResponseConnControl());
+ this.httpproc = new ImmutableHttpProcessor(
+ new HttpResponseInterceptor[] {
+ new ResponseDate(),
+ new ResponseServer(),
+ new ResponseContent(),
+ new ResponseConnControl()
+ });
this.connStrategy = new DefaultConnectionReuseStrategy();
this.responseFactory = new DefaultHttpResponseFactory();
this.reqistry = new HttpRequestHandlerRegistry();
Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java?rev=793188&r1=793187&r2=793188&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java (original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/params/TestBasicHttpParams.java Sat Jul 11 15:50:30 2009
@@ -54,46 +54,6 @@
return new TestSuite(TestBasicHttpParams.class);
}
-
-
- public void testCopyParams() {
- HttpParams parent = new BasicHttpParams();
- HttpParams child = new DefaultedHttpParams(
- new BasicHttpParams(), parent);
- parent.setParameter("parent", "something");
- child.setParameter("child", "something");
-
- HttpParams copy = child.copy();
- assertSame("copied parameters have wrong class",
- child.getClass(), copy.getClass());
- assertEquals("local parameter missing in copy",
- "something", copy.getParameter("child"));
- assertEquals("default parameter missing in copy",
- "something", copy.getParameter("parent"));
-
- // now modify stuff to make sure the copy is a copy
- child.setParameter("child", "else-child");
- assertEquals("modification in child reflected in copy",
- "something", copy.getParameter("child"));
- child.setParameter("child+", "something");
- assertNull("new parameter in child reflected in copy",
- copy.getParameter("child+"));
-
- copy.setParameter("child", "else-copy");
- assertEquals("modification in copy reflected in child",
- "else-child", child.getParameter("child"));
- copy.setParameter("copy+", "something");
- assertNull("new parameter in copy reflected in child",
- child.getParameter("copy+"));
-
- // and modify the parent to make sure there is only one
- parent.setParameter("parent+", "something");
- assertEquals("parent parameter not known in child",
- "something", child.getParameter("parent+"));
- assertEquals("parent parameter not known in copy",
- "something", copy.getParameter("parent+"));
- }
-
public void testRemoveParam() {
BasicHttpParams params = new BasicHttpParams();
params.setParameter("param1", "paramValue1");