Index: module-main/src/main/java/org/apache/http/impl/protocol/DefaultHttpProcessor.java =================================================================== --- module-main/src/main/java/org/apache/http/impl/protocol/DefaultHttpProcessor.java (revision 0) +++ module-main/src/main/java/org/apache/http/impl/protocol/DefaultHttpProcessor.java (working copy) @@ -27,7 +27,7 @@ * */ -package org.apache.http.protocol; +package org.apache.http.impl.protocol; import java.io.IOException; import java.util.ArrayList; @@ -39,7 +39,10 @@ import org.apache.http.HttpRequestInterceptor; import org.apache.http.HttpResponse; import org.apache.http.HttpResponseInterceptor; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpProcessor; + /** * Keeps lists of interceptors for processing requests and responses. * @@ -49,7 +52,7 @@ * * @since 4.0 */ -public abstract class AbstractHttpProcessor { +public class DefaultHttpProcessor implements HttpProcessor { private List requestInterceptors = null; private List responseInterceptors = null; @@ -146,7 +149,7 @@ this.responseInterceptors = null; } - protected void preprocessRequest( + public void preprocessRequest( final HttpRequest request, final HttpContext context) throws IOException, HttpException { @@ -158,7 +161,7 @@ } } - protected void postprocessResponse( + public void postprocessResponse( final HttpResponse response, final HttpContext context) throws IOException, HttpException { Index: module-main/src/main/java/org/apache/http/protocol/HttpService.java =================================================================== --- module-main/src/main/java/org/apache/http/protocol/HttpService.java (revision 449665) +++ module-main/src/main/java/org/apache/http/protocol/HttpService.java (working copy) @@ -58,16 +58,26 @@ * * @version $Revision$ */ -public class HttpService extends AbstractHttpProcessor { +public class HttpService { private HttpParams params = null; + private final HttpProcessor processor; private ConnectionReuseStrategy connStrategy = null; private HttpResponseFactory responseFactory = null; private final Map handlerMap; - public HttpService() { - super(); + /** + * Create a new HTTP service. + * + * @param proc the processor to use on requests and responses + */ + public HttpService(HttpProcessor proc) { + if (proc == null) + throw new IllegalArgumentException + ("HTTP processor must not be null."); + + this.processor = proc; this.handlerMap = new HashMap(); this.connStrategy = new DefaultConnectionReuseStrategy(); this.responseFactory = new DefaultHttpResponseFactory(); @@ -159,7 +169,7 @@ } conn.receiveRequestEntity((HttpEntityEnclosingRequest) request); } - preprocessRequest(request, context); + processor.preprocessRequest(request, context); context.setAttribute(HttpExecutionContext.HTTP_REQUEST, request); context.setAttribute(HttpExecutionContext.HTTP_RESPONSE, response); @@ -178,7 +188,7 @@ response.getParams().setDefaults(this.params); handleException(ex, response); } - postprocessResponse(response, context); + processor.postprocessResponse(response, context); conn.sendResponseHeader(response); conn.sendResponseEntity(response); conn.flush(); Index: module-main/src/main/java/org/apache/http/protocol/AbstractHttpProcessor.java =================================================================== --- module-main/src/main/java/org/apache/http/protocol/AbstractHttpProcessor.java (revision 449665) +++ module-main/src/main/java/org/apache/http/protocol/AbstractHttpProcessor.java (working copy) @@ -1,173 +0,0 @@ -/* - * $HeadURL$ - * $Revision$ - * $Date$ - * - * ==================================================================== - * - * Copyright 1999-2006 The Apache Software Foundation - * - * Licensed 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.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -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; - -/** - * Keeps lists of interceptors for processing requests and responses. - * - * @author Oleg Kalnichevski - * - * @version $Revision$ - * - * @since 4.0 - */ -public abstract class AbstractHttpProcessor { - - private List requestInterceptors = null; - private List responseInterceptors = null; - - public void addInterceptor(final HttpRequestInterceptor interceptor) { - if (interceptor == null) { - return; - } - if (this.requestInterceptors == null) { - this.requestInterceptors = new ArrayList(); - } - this.requestInterceptors.add(interceptor); - } - - 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; - } - } - - public void addInterceptor(final HttpResponseInterceptor interceptor) { - if (interceptor == null) { - return; - } - if (this.responseInterceptors == null) { - this.responseInterceptors = new ArrayList(); - } - this.responseInterceptors.add(interceptor); - } - - 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; - } - } - - 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(); - } - } - } - } - - public void setInterceptors(final List list) { - if (list == null) { - return; - } - if (this.requestInterceptors != null) { - this.requestInterceptors.clear(); - } - if (this.responseInterceptors != null) { - this.responseInterceptors.clear(); - } - for (int i = 0; i < list.size(); i++) { - Object obj = list.get(i); - if (obj instanceof HttpRequestInterceptor) { - addInterceptor((HttpRequestInterceptor)obj); - } - if (obj instanceof HttpResponseInterceptor) { - addInterceptor((HttpResponseInterceptor)obj); - } - } - } - - public void clearInterceptors() { - this.requestInterceptors = null; - this.responseInterceptors = null; - } - - protected void preprocessRequest( - final HttpRequest request, - final HttpContext context) - throws IOException, HttpException { - if (this.requestInterceptors != null) { - for (int i = 0; i < this.requestInterceptors.size(); i++) { - HttpRequestInterceptor interceptor = (HttpRequestInterceptor) this.requestInterceptors.get(i); - interceptor.process(request, context); - } - } - } - - protected void postprocessResponse( - final HttpResponse response, - final HttpContext context) - throws IOException, HttpException { - if (this.responseInterceptors != null) { - for (int i = 0; i < this.responseInterceptors.size(); i++) { - HttpResponseInterceptor interceptor = (HttpResponseInterceptor) this.responseInterceptors.get(i); - interceptor.process(response, context); - } - } - } - -} Index: module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java =================================================================== --- module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java (revision 449666) +++ module-main/src/main/java/org/apache/http/protocol/HttpRequestExecutor.java (working copy) @@ -52,17 +52,24 @@ * * @since 4.0 */ -public class HttpRequestExecutor extends AbstractHttpProcessor { +public class HttpRequestExecutor { protected static final int WAIT_FOR_CONTINUE_MS = 10000; - private HttpParams params = null; + private HttpParams params; + private final HttpProcessor processor; /** * Create a new request executor. + * + * @param proc the processor to use on requests and responses */ - public HttpRequestExecutor() { - super(); + public HttpRequestExecutor(HttpProcessor proc) { + if (proc == null) + throw new IllegalArgumentException + ("HTTP processor must not be null."); + + this.processor = proc; } /** @@ -179,7 +186,7 @@ } // link default parameters request.getParams().setDefaults(this.params); - preprocessRequest(request, context); + processor.preprocessRequest(request, context); } /** @@ -333,7 +340,7 @@ if (context == null) { throw new IllegalArgumentException("HTTP context may not be null"); } - postprocessResponse(response, context); + processor.postprocessResponse(response, context); } } // class HttpRequestExecutor Index: module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java =================================================================== --- module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java (revision 0) +++ module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java (revision 0) @@ -0,0 +1,90 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * + * Copyright 1999-2006 The Apache Software Foundation + * + * Licensed 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.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +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; + +/** + * Performs interceptor processing of requests and responses. + * + * @author Oleg Kalnichevski + * @author Roland Weber + * + * @version $Revision$ + * + * @since 4.0 + */ +public interface HttpProcessor { + + /** + * Preprocesses a request. + * On the client side, this step is performed before the request is + * sent to the server. On the server side, this step is performed + * on incoming messages before the message body is evaluated. + * + * @param request the request to preprocess + * @param context the context for the request + * + * @throws IOException in case of an IO problem + * @throws HttpException in case of a protocol or other problem + */ + void preprocessRequest(HttpRequest request, + HttpContext context) + throws IOException, HttpException + ; + + + /** + * Preprocesses a request. + * On the client side, this step is performed before the request is + * sent to the server. On the server side, this step is performed + * on incoming messages before the message body is evaluated. + * + * @param request the request to preprocess + * @param context the context for the request + * + * @throws IOException in case of an IO problem + * @throws HttpException in case of a protocol or other problem + */ + void postprocessResponse(HttpResponse response, + HttpContext context) + throws IOException, HttpException + ; + +} Property changes on: module-main/src/main/java/org/apache/http/protocol/HttpProcessor.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:keywords + Date Author Id Revision HeadURL Name: svn:eol-style + native Index: module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java =================================================================== --- module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java (revision 449665) +++ module-main/src/examples/org/apache/http/examples/ElementalHttpGet.java (working copy) @@ -40,6 +40,7 @@ import org.apache.http.impl.DefaultHttpClientConnection; import org.apache.http.impl.DefaultHttpParams; import org.apache.http.impl.io.PlainSocketFactory; +import org.apache.http.impl.protocol.DefaultHttpProcessor; import org.apache.http.io.SocketFactory; import org.apache.http.message.HttpGet; import org.apache.http.params.HttpParams; @@ -75,16 +76,18 @@ HttpProtocolParams.setContentCharset(params, "UTF-8"); HttpProtocolParams.setUserAgent(params, "Jakarta-HttpComponents/1.1"); HttpProtocolParams.setUseExpectContinue(params, true); - - HttpRequestExecutor httpexecutor = new HttpRequestExecutor(); - httpexecutor.setParams(params); + + DefaultHttpProcessor httpproc = new DefaultHttpProcessor(); // Required protocol interceptors - httpexecutor.addInterceptor(new RequestContent()); - httpexecutor.addInterceptor(new RequestTargetHost()); + httpproc.addInterceptor(new RequestContent()); + httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors - httpexecutor.addInterceptor(new RequestConnControl()); - httpexecutor.addInterceptor(new RequestUserAgent()); - httpexecutor.addInterceptor(new RequestExpectContinue()); + httpproc.addInterceptor(new RequestConnControl()); + httpproc.addInterceptor(new RequestUserAgent()); + httpproc.addInterceptor(new RequestExpectContinue()); + + HttpRequestExecutor httpexecutor = new HttpRequestExecutor(httpproc); + httpexecutor.setParams(params); HttpContext context = new HttpExecutionContext(null); Index: module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java =================================================================== --- module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java (revision 449665) +++ module-main/src/examples/org/apache/http/examples/ElementalHttpPost.java (working copy) @@ -45,6 +45,7 @@ import org.apache.http.impl.DefaultHttpClientConnection; import org.apache.http.impl.DefaultHttpParams; import org.apache.http.impl.io.PlainSocketFactory; +import org.apache.http.impl.protocol.DefaultHttpProcessor; import org.apache.http.io.SocketFactory; import org.apache.http.message.HttpPost; import org.apache.http.params.HttpParams; @@ -81,16 +82,18 @@ HttpProtocolParams.setUserAgent(params, "Jakarta-HttpComponents/1.1"); HttpProtocolParams.setUseExpectContinue(params, true); - HttpRequestExecutor httpexecutor = new HttpRequestExecutor(); - httpexecutor.setParams(params); + DefaultHttpProcessor httpproc = new DefaultHttpProcessor(); // Required protocol interceptors - httpexecutor.addInterceptor(new RequestContent()); - httpexecutor.addInterceptor(new RequestTargetHost()); + httpproc.addInterceptor(new RequestContent()); + httpproc.addInterceptor(new RequestTargetHost()); // Recommended protocol interceptors - httpexecutor.addInterceptor(new RequestConnControl()); - httpexecutor.addInterceptor(new RequestUserAgent()); - httpexecutor.addInterceptor(new RequestExpectContinue()); + httpproc.addInterceptor(new RequestConnControl()); + httpproc.addInterceptor(new RequestUserAgent()); + httpproc.addInterceptor(new RequestExpectContinue()); + HttpRequestExecutor httpexecutor = new HttpRequestExecutor(httpproc); + httpexecutor.setParams(params); + HttpContext context = new HttpExecutionContext(null); HttpHost host = new HttpHost("localhost", 8080); Index: module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java =================================================================== --- module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java (revision 449665) +++ module-main/src/examples/org/apache/http/examples/ElementalHttpServer.java (working copy) @@ -50,6 +50,7 @@ import org.apache.http.entity.FileEntity; import org.apache.http.impl.DefaultHttpParams; import org.apache.http.impl.DefaultHttpServerConnection; +import org.apache.http.impl.protocol.DefaultHttpProcessor; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; import org.apache.http.params.HttpProtocolParams; @@ -177,12 +178,14 @@ System.out.println("Incoming connection from " + socket.getInetAddress()); conn.bind(socket, this.params); - // Set up HTTP service - HttpService httpService = new HttpService(); - httpService.addInterceptor(new ResponseDate()); - httpService.addInterceptor(new ResponseServer()); - httpService.addInterceptor(new ResponseContent()); - httpService.addInterceptor(new ResponseConnControl()); + // Set up HTTP processor and service + DefaultHttpProcessor httpproc = new DefaultHttpProcessor(); + httpproc.addInterceptor(new ResponseDate()); + httpproc.addInterceptor(new ResponseServer()); + httpproc.addInterceptor(new ResponseContent()); + httpproc.addInterceptor(new ResponseConnControl()); + + HttpService httpService = new HttpService(httpproc); httpService.setParams(this.params); httpService.registerRequestHandler("*", new HttpFileHandler()); Index: src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java =================================================================== --- src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java (revision 449665) +++ src/contrib/org/apache/http/contrib/benchmark/BenchmarkWorker.java (working copy) @@ -42,6 +42,7 @@ import org.apache.http.HttpResponse; import org.apache.http.impl.DefaultConnectionReuseStrategy; import org.apache.http.impl.DefaultHttpClientConnection; +import org.apache.http.impl.protocol.DefaultHttpProcessor; import org.apache.http.io.SocketFactory; import org.apache.http.params.HttpParams; import org.apache.http.protocol.HTTP; @@ -79,15 +80,18 @@ super(); this.params = params; this.context = new HttpExecutionContext(null); - this.httpexecutor = new HttpRequestExecutor(); + + DefaultHttpProcessor httpproc = new DefaultHttpProcessor(); + this.httpexecutor = new HttpRequestExecutor(httpproc); this.httpexecutor.setParams(params); + // Required request interceptors - this.httpexecutor.addInterceptor(new RequestContent()); - this.httpexecutor.addInterceptor(new RequestTargetHost()); + httpproc.addInterceptor(new RequestContent()); + httpproc.addInterceptor(new RequestTargetHost()); // Recommended request interceptors - this.httpexecutor.addInterceptor(new RequestConnControl()); - this.httpexecutor.addInterceptor(new RequestUserAgent()); - this.httpexecutor.addInterceptor(new RequestExpectContinue()); + httpproc.addInterceptor(new RequestConnControl()); + httpproc.addInterceptor(new RequestUserAgent()); + httpproc.addInterceptor(new RequestExpectContinue()); this.connstrategy = new DefaultConnectionReuseStrategy(); this.verbosity = verbosity;