Return-Path: Delivered-To: apmail-jakarta-httpcomponents-commits-archive@www.apache.org Received: (qmail 28179 invoked from network); 16 Jun 2007 17:28:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Jun 2007 17:28:07 -0000 Received: (qmail 25015 invoked by uid 500); 16 Jun 2007 17:28:10 -0000 Delivered-To: apmail-jakarta-httpcomponents-commits-archive@jakarta.apache.org Received: (qmail 25001 invoked by uid 500); 16 Jun 2007 17:28:10 -0000 Mailing-List: contact httpcomponents-commits-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: httpcomponents-dev@jakarta.apache.org Delivered-To: mailing list httpcomponents-commits@jakarta.apache.org Received: (qmail 24992 invoked by uid 99); 16 Jun 2007 17:28:10 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jun 2007 10:28:10 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 16 Jun 2007 10:28:05 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id BD29A1A981A; Sat, 16 Jun 2007 10:27:44 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r547954 - /jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ Date: Sat, 16 Jun 2007 17:27:43 -0000 To: httpcomponents-commits@jakarta.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070616172744.BD29A1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: olegk Date: Sat Jun 16 10:27:42 2007 New Revision: 547954 URL: http://svn.apache.org/viewvc?view=rev&rev=547954 Log: Factored out common code in NHttp protocol handlers into common base classes Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java (with props) jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java (with props) jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java (with props) Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java?view=diff&rev=547954&r1=547953&r2=547954 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpClientHandler.java Sat Jun 16 10:27:42 2007 @@ -36,7 +36,6 @@ import java.net.InetAddress; import org.apache.http.ConnectionReuseStrategy; -import org.apache.http.HttpConnection; import org.apache.http.HttpEntity; import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpException; @@ -48,7 +47,6 @@ import org.apache.http.nio.ContentDecoder; import org.apache.http.nio.ContentEncoder; import org.apache.http.nio.NHttpClientConnection; -import org.apache.http.nio.NHttpClientHandler; import org.apache.http.nio.entity.ContentBufferEntity; import org.apache.http.nio.entity.ContentOutputStream; import org.apache.http.nio.util.ByteBufferAllocator; @@ -74,45 +72,15 @@ * @author Oleg Kalnichevski * */ -public class BufferingHttpClientHandler implements NHttpClientHandler { +public class BufferingHttpClientHandler extends NHttpClientHandlerBase { - private static final String CONN_STATE = "http.nio.conn-state"; - - private final HttpProcessor httpProcessor; - private final ConnectionReuseStrategy connStrategy; - private final ByteBufferAllocator allocator; - private final HttpParams params; - - private HttpRequestExecutionHandler execHandler; - private EventListener eventListener; - public BufferingHttpClientHandler( final HttpProcessor httpProcessor, final HttpRequestExecutionHandler execHandler, final ConnectionReuseStrategy connStrategy, final ByteBufferAllocator allocator, final HttpParams params) { - super(); - if (httpProcessor == null) { - throw new IllegalArgumentException("HTTP processor may not be null."); - } - if (execHandler == null) { - throw new IllegalArgumentException("HTTP request execution handler may not be null."); - } - if (connStrategy == null) { - throw new IllegalArgumentException("Connection reuse strategy may not be null"); - } - if (allocator == null) { - throw new IllegalArgumentException("ByteBuffer allocator may not be null"); - } - if (params == null) { - throw new IllegalArgumentException("HTTP parameters may not be null"); - } - this.httpProcessor = httpProcessor; - this.execHandler = execHandler; - this.connStrategy = connStrategy; - this.params = params; - this.allocator = allocator; + super(httpProcessor, execHandler, connStrategy, allocator, params); } public BufferingHttpClientHandler( @@ -124,17 +92,6 @@ new HeapByteBufferAllocator(), params); } - public void setEventListener(final EventListener eventListener) { - this.eventListener = eventListener; - } - - private void shutdownConnection(final HttpConnection conn) { - try { - conn.shutdown(); - } catch (IOException ignore) { - } - } - public void connected(final NHttpClientConnection conn, final Object attachment) { HttpContext context = conn.getContext(); @@ -167,20 +124,6 @@ } } - public void exception(final NHttpClientConnection conn, final HttpException ex) { - shutdownConnection(conn); - if (this.eventListener != null) { - this.eventListener.fatalProtocolException(ex, conn); - } - } - - public void exception(final NHttpClientConnection conn, final IOException ex) { - shutdownConnection(conn); - if (this.eventListener != null) { - this.eventListener.fatalIOException(ex, conn); - } - } - public void requestReady(final NHttpClientConnection conn) { HttpContext context = conn.getContext(); @@ -403,20 +346,6 @@ outstream.flush(); outstream.close(); } - } - - private boolean canResponseHaveBody( - final HttpRequest request, final HttpResponse response) { - - if (request != null && "HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) { - return false; - } - - int status = response.getStatusLine().getStatusCode(); - return status >= HttpStatus.SC_OK - && status != HttpStatus.SC_NO_CONTENT - && status != HttpStatus.SC_NOT_MODIFIED - && status != HttpStatus.SC_RESET_CONTENT; } private void processResponse( Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java?view=diff&rev=547954&r1=547953&r2=547954 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/BufferingHttpServiceHandler.java Sat Jun 16 10:27:42 2007 @@ -49,7 +49,6 @@ import org.apache.http.entity.ByteArrayEntity; import org.apache.http.nio.ContentDecoder; import org.apache.http.nio.ContentEncoder; -import org.apache.http.nio.NHttpConnection; import org.apache.http.nio.NHttpServerConnection; import org.apache.http.nio.NHttpServiceHandler; import org.apache.http.nio.entity.ContentBufferEntity; @@ -64,10 +63,8 @@ import org.apache.http.params.HttpParamsLinker; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpExecutionContext; -import org.apache.http.protocol.HttpExpectationVerifier; import org.apache.http.protocol.HttpProcessor; import org.apache.http.protocol.HttpRequestHandler; -import org.apache.http.protocol.HttpRequestHandlerResolver; import org.apache.http.util.EncodingUtils; /** @@ -80,47 +77,16 @@ * @author Oleg Kalnichevski * */ -public class BufferingHttpServiceHandler implements NHttpServiceHandler { +public class BufferingHttpServiceHandler extends NHttpServiceHandlerBase + implements NHttpServiceHandler { - private static final String CONN_STATE = "http.nio.conn-state"; - - private final HttpProcessor httpProcessor; - private final HttpResponseFactory responseFactory; - private final ConnectionReuseStrategy connStrategy; - private final ByteBufferAllocator allocator; - private final HttpParams params; - - private HttpRequestHandlerResolver handlerResolver; - private HttpExpectationVerifier expectationVerifier; - private EventListener eventListener; - public BufferingHttpServiceHandler( final HttpProcessor httpProcessor, final HttpResponseFactory responseFactory, final ConnectionReuseStrategy connStrategy, final ByteBufferAllocator allocator, final HttpParams params) { - super(); - if (httpProcessor == null) { - throw new IllegalArgumentException("HTTP processor may not be null."); - } - if (connStrategy == null) { - throw new IllegalArgumentException("Connection reuse strategy may not be null"); - } - if (responseFactory == null) { - throw new IllegalArgumentException("Response factory may not be null"); - } - if (allocator == null) { - throw new IllegalArgumentException("ByteBuffer allocator may not be null"); - } - if (params == null) { - throw new IllegalArgumentException("HTTP parameters may not be null"); - } - this.httpProcessor = httpProcessor; - this.responseFactory = responseFactory; - this.connStrategy = connStrategy; - this.allocator = allocator; - this.params = params; + super(httpProcessor, responseFactory, connStrategy, allocator, params); } public BufferingHttpServiceHandler( @@ -132,22 +98,6 @@ new HeapByteBufferAllocator(), params); } - public void setEventListener(final EventListener eventListener) { - this.eventListener = eventListener; - } - - public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver) { - this.handlerResolver = handlerResolver; - } - - public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) { - this.expectationVerifier = expectationVerifier; - } - - public HttpParams getParams() { - return this.params; - } - public void connected(final NHttpServerConnection conn) { HttpContext context = conn.getContext(); @@ -264,13 +214,6 @@ } } - public void exception(final NHttpServerConnection conn, final IOException ex) { - shutdownConnection(conn); - if (this.eventListener != null) { - this.eventListener.fatalIOException(ex, conn); - } - } - public void inputReady(final NHttpServerConnection conn, final ContentDecoder decoder) { HttpContext context = conn.getContext(); HttpRequest request = conn.getHttpRequest(); @@ -346,20 +289,6 @@ } } - public void timeout(final NHttpServerConnection conn) { - shutdownConnection(conn); - if (this.eventListener != null) { - this.eventListener.connectionTimeout(conn); - } - } - - private void shutdownConnection(final NHttpConnection conn) { - try { - conn.shutdown(); - } catch (IOException ignore) { - } - } - private void handleException(final HttpException ex, final HttpResponse response) { int code = HttpStatus.SC_INTERNAL_SERVER_ERROR; if (ex instanceof MethodNotSupportedException) { @@ -458,20 +387,6 @@ conn.requestInput(); } } - } - - private boolean canResponseHaveBody( - final HttpRequest request, final HttpResponse response) { - - if (request != null && "HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) { - return false; - } - - int status = response.getStatusLine().getStatusCode(); - return status >= HttpStatus.SC_OK - && status != HttpStatus.SC_NO_CONTENT - && status != HttpStatus.SC_NOT_MODIFIED - && status != HttpStatus.SC_RESET_CONTENT; } static class ServerConnState { Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java?view=auto&rev=547954 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java (added) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java Sat Jun 16 10:27:42 2007 @@ -0,0 +1,82 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.nio.protocol; + +import java.io.IOException; + +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.HttpException; +import org.apache.http.nio.NHttpClientConnection; +import org.apache.http.nio.NHttpClientHandler; +import org.apache.http.nio.util.ByteBufferAllocator; +import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HttpProcessor; + +public abstract class NHttpClientHandlerBase extends NHttpHandlerBase + implements NHttpClientHandler { + + protected HttpRequestExecutionHandler execHandler; + + public NHttpClientHandlerBase( + final HttpProcessor httpProcessor, + final HttpRequestExecutionHandler execHandler, + final ConnectionReuseStrategy connStrategy, + final ByteBufferAllocator allocator, + final HttpParams params) { + super(httpProcessor, connStrategy, allocator, params); + if (execHandler == null) { + throw new IllegalArgumentException("HTTP request execution handler may not be null."); + } + this.execHandler = execHandler; + } + + public void closed(final NHttpClientConnection conn) { + if (this.eventListener != null) { + this.eventListener.connectionClosed(conn); + } + } + + public void exception(final NHttpClientConnection conn, final HttpException ex) { + shutdownConnection(conn); + if (this.eventListener != null) { + this.eventListener.fatalProtocolException(ex, conn); + } + } + + public void exception(final NHttpClientConnection conn, final IOException ex) { + shutdownConnection(conn); + if (this.eventListener != null) { + this.eventListener.fatalIOException(ex, conn); + } + } + +} Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpClientHandlerBase.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java?view=auto&rev=547954 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java (added) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java Sat Jun 16 10:27:42 2007 @@ -0,0 +1,109 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.nio.protocol; + +import java.io.IOException; + +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.HttpConnection; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.nio.util.ByteBufferAllocator; +import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HttpProcessor; + +public abstract class NHttpHandlerBase { + + protected static final String CONN_STATE = "http.nio.conn-state"; + + protected final HttpProcessor httpProcessor; + protected final ConnectionReuseStrategy connStrategy; + protected final ByteBufferAllocator allocator; + protected final HttpParams params; + + protected EventListener eventListener; + + public NHttpHandlerBase( + final HttpProcessor httpProcessor, + final ConnectionReuseStrategy connStrategy, + final ByteBufferAllocator allocator, + final HttpParams params) { + super(); + if (httpProcessor == null) { + throw new IllegalArgumentException("HTTP processor may not be null."); + } + if (connStrategy == null) { + throw new IllegalArgumentException("Connection reuse strategy may not be null"); + } + if (allocator == null) { + throw new IllegalArgumentException("ByteBuffer allocator may not be null"); + } + if (params == null) { + throw new IllegalArgumentException("HTTP parameters may not be null"); + } + this.httpProcessor = httpProcessor; + this.connStrategy = connStrategy; + this.allocator = allocator; + this.params = params; + } + + public HttpParams getParams() { + return this.params; + } + + public void setEventListener(final EventListener eventListener) { + this.eventListener = eventListener; + } + + protected void shutdownConnection(final HttpConnection conn) { + try { + conn.shutdown(); + } catch (IOException ignore) { + } + } + + protected boolean canResponseHaveBody( + final HttpRequest request, final HttpResponse response) { + + if (request != null && "HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) { + return false; + } + + int status = response.getStatusLine().getStatusCode(); + return status >= HttpStatus.SC_OK + && status != HttpStatus.SC_NO_CONTENT + && status != HttpStatus.SC_NOT_MODIFIED + && status != HttpStatus.SC_RESET_CONTENT; + } + +} \ No newline at end of file Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpHandlerBase.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java?view=auto&rev=547954 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java (added) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java Sat Jun 16 10:27:42 2007 @@ -0,0 +1,101 @@ +/* + * $HeadURL$ + * $Revision$ + * $Date$ + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + * + */ + +package org.apache.http.nio.protocol; + +import java.io.IOException; + +import org.apache.http.ConnectionReuseStrategy; +import org.apache.http.HttpResponseFactory; +import org.apache.http.nio.NHttpServerConnection; +import org.apache.http.nio.NHttpServiceHandler; +import org.apache.http.nio.util.ByteBufferAllocator; +import org.apache.http.nio.util.HeapByteBufferAllocator; +import org.apache.http.params.HttpParams; +import org.apache.http.protocol.HttpExpectationVerifier; +import org.apache.http.protocol.HttpProcessor; +import org.apache.http.protocol.HttpRequestHandlerResolver; + +public abstract class NHttpServiceHandlerBase extends NHttpHandlerBase + implements NHttpServiceHandler { + + protected final HttpResponseFactory responseFactory; + + protected HttpRequestHandlerResolver handlerResolver; + protected HttpExpectationVerifier expectationVerifier; + + public NHttpServiceHandlerBase( + final HttpProcessor httpProcessor, + final HttpResponseFactory responseFactory, + final ConnectionReuseStrategy connStrategy, + final ByteBufferAllocator allocator, + final HttpParams params) { + super(httpProcessor, connStrategy, allocator, params); + if (responseFactory == null) { + throw new IllegalArgumentException("Response factory may not be null"); + } + this.responseFactory = responseFactory; + } + + public NHttpServiceHandlerBase( + final HttpProcessor httpProcessor, + final HttpResponseFactory responseFactory, + final ConnectionReuseStrategy connStrategy, + final HttpParams params) { + this(httpProcessor, responseFactory, connStrategy, + new HeapByteBufferAllocator(), params); + } + + public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver) { + this.handlerResolver = handlerResolver; + } + + public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) { + this.expectationVerifier = expectationVerifier; + } + + public void exception(final NHttpServerConnection conn, final IOException ex) { + shutdownConnection(conn); + + if (this.eventListener != null) { + this.eventListener.fatalIOException(ex, conn); + } + } + + public void timeout(final NHttpServerConnection conn) { + shutdownConnection(conn); + + if (this.eventListener != null) { + this.eventListener.connectionTimeout(conn); + } + } + +} Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java ------------------------------------------------------------------------------ svn:keywords = Date Author Id Revision HeadURL Propchange: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/NHttpServiceHandlerBase.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java?view=diff&rev=547954&r1=547953&r2=547954 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpClientHandler.java Sat Jun 16 10:27:42 2007 @@ -37,7 +37,6 @@ import java.net.InetAddress; import org.apache.http.ConnectionReuseStrategy; -import org.apache.http.HttpConnection; import org.apache.http.HttpEntity; import org.apache.http.HttpEntityEnclosingRequest; import org.apache.http.HttpException; @@ -50,7 +49,6 @@ import org.apache.http.nio.ContentEncoder; import org.apache.http.nio.IOControl; import org.apache.http.nio.NHttpClientConnection; -import org.apache.http.nio.NHttpClientHandler; import org.apache.http.nio.entity.ContentBufferEntity; import org.apache.http.nio.entity.ContentOutputStream; import org.apache.http.nio.params.HttpNIOParams; @@ -86,18 +84,9 @@ * @author Oleg Kalnichevski * */ -public class ThrottlingHttpClientHandler implements NHttpClientHandler { +public class ThrottlingHttpClientHandler extends NHttpClientHandlerBase { - private static final String CONN_STATE = "http.nio.conn-state"; - - private final HttpProcessor httpProcessor; - private final ConnectionReuseStrategy connStrategy; - private final ByteBufferAllocator allocator; - private final Executor executor; - private final HttpParams params; - - private HttpRequestExecutionHandler execHandler; - private EventListener eventListener; + protected final Executor executor; public ThrottlingHttpClientHandler( final HttpProcessor httpProcessor, @@ -106,31 +95,11 @@ final ByteBufferAllocator allocator, final Executor executor, final HttpParams params) { - super(); - if (httpProcessor == null) { - throw new IllegalArgumentException("HTTP processor may not be null."); - } - if (execHandler == null) { - throw new IllegalArgumentException("HTTP request execution handler may not be null."); - } - if (connStrategy == null) { - throw new IllegalArgumentException("Connection reuse strategy may not be null"); - } - if (allocator == null) { - throw new IllegalArgumentException("ByteBuffer allocator may not be null"); - } + super(httpProcessor, execHandler, connStrategy, allocator, params); if (executor == null) { throw new IllegalArgumentException("Executor may not be null"); } - if (params == null) { - throw new IllegalArgumentException("HTTP parameters may not be null"); - } - this.httpProcessor = httpProcessor; - this.execHandler = execHandler; - this.connStrategy = connStrategy; - this.allocator = allocator; this.executor = executor; - this.params = params; } public ThrottlingHttpClientHandler( @@ -143,17 +112,6 @@ new DirectByteBufferAllocator(), executor, params); } - public void setEventListener(final EventListener eventListener) { - this.eventListener = eventListener; - } - - private void shutdownConnection(final HttpConnection conn) { - try { - conn.shutdown(); - } catch (IOException ignore) { - } - } - public void connected(final NHttpClientConnection conn, final Object attachment) { HttpContext context = conn.getContext(); @@ -188,20 +146,6 @@ } } - public void exception(final NHttpClientConnection conn, final HttpException ex) { - shutdownConnection(conn); - if (this.eventListener != null) { - this.eventListener.fatalProtocolException(ex, conn); - } - } - - public void exception(final NHttpClientConnection conn, final IOException ex) { - shutdownConnection(conn); - if (this.eventListener != null) { - this.eventListener.fatalIOException(ex, conn); - } - } - public void requestReady(final NHttpClientConnection conn) { HttpContext context = conn.getContext(); @@ -444,20 +388,6 @@ (HttpEntityEnclosingRequest) request, connState, conn); - } - - private boolean canResponseHaveBody( - final HttpRequest request, final HttpResponse response) { - - if (request != null && "HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) { - return false; - } - - int status = response.getStatusLine().getStatusCode(); - return status >= HttpStatus.SC_OK - && status != HttpStatus.SC_NO_CONTENT - && status != HttpStatus.SC_NOT_MODIFIED - && status != HttpStatus.SC_RESET_CONTENT; } private void sendRequestBody( Modified: jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java URL: http://svn.apache.org/viewvc/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java?view=diff&rev=547954&r1=547953&r2=547954 ============================================================================== --- jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java (original) +++ jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/ThrottlingHttpServiceHandler.java Sat Jun 16 10:27:42 2007 @@ -53,7 +53,6 @@ import org.apache.http.nio.IOControl; import org.apache.http.nio.NHttpConnection; import org.apache.http.nio.NHttpServerConnection; -import org.apache.http.nio.NHttpServiceHandler; import org.apache.http.nio.entity.ContentBufferEntity; import org.apache.http.nio.entity.ContentOutputStream; import org.apache.http.nio.params.HttpNIOParams; @@ -67,10 +66,8 @@ import org.apache.http.params.HttpParamsLinker; import org.apache.http.protocol.HttpContext; import org.apache.http.protocol.HttpExecutionContext; -import org.apache.http.protocol.HttpExpectationVerifier; import org.apache.http.protocol.HttpProcessor; import org.apache.http.protocol.HttpRequestHandler; -import org.apache.http.protocol.HttpRequestHandlerResolver; import org.apache.http.util.EncodingUtils; import org.apache.http.util.concurrent.Executor; @@ -91,20 +88,9 @@ * @author Oleg Kalnichevski * */ -public class ThrottlingHttpServiceHandler implements NHttpServiceHandler { +public class ThrottlingHttpServiceHandler extends NHttpServiceHandlerBase { - private static final String CONN_STATE = "http.nio.conn-state"; - - private final HttpProcessor httpProcessor; - private final HttpResponseFactory responseFactory; - private final ConnectionReuseStrategy connStrategy; - private final ByteBufferAllocator allocator; - private final Executor executor; - private final HttpParams params; - - private HttpRequestHandlerResolver handlerResolver; - private HttpExpectationVerifier expectationVerifier; - private EventListener eventListener; + protected final Executor executor; public ThrottlingHttpServiceHandler( final HttpProcessor httpProcessor, @@ -113,31 +99,8 @@ final ByteBufferAllocator allocator, final Executor executor, final HttpParams params) { - super(); - if (httpProcessor == null) { - throw new IllegalArgumentException("HTTP processor may not be null."); - } - if (connStrategy == null) { - throw new IllegalArgumentException("Connection reuse strategy may not be null"); - } - if (responseFactory == null) { - throw new IllegalArgumentException("Response factory may not be null"); - } - if (allocator == null) { - throw new IllegalArgumentException("ByteBuffer allocator may not be null"); - } - if (executor == null) { - throw new IllegalArgumentException("Executor may not be null"); - } - if (params == null) { - throw new IllegalArgumentException("HTTP parameters may not be null"); - } - this.httpProcessor = httpProcessor; - this.connStrategy = connStrategy; - this.responseFactory = responseFactory; - this.allocator = allocator; + super(httpProcessor, responseFactory, connStrategy, allocator, params); this.executor = executor; - this.params = params; } public ThrottlingHttpServiceHandler( @@ -150,22 +113,6 @@ new DirectByteBufferAllocator(), executor, params); } - public void setEventListener(final EventListener eventListener) { - this.eventListener = eventListener; - } - - public void setHandlerResolver(final HttpRequestHandlerResolver handlerResolver) { - this.handlerResolver = handlerResolver; - } - - public void setExpectationVerifier(final HttpExpectationVerifier expectationVerifier) { - this.expectationVerifier = expectationVerifier; - } - - public HttpParams getParams() { - return this.params; - } - public void connected(final NHttpServerConnection conn) { HttpContext context = conn.getContext(); @@ -228,22 +175,6 @@ } - public void exception(final NHttpServerConnection conn, final IOException ex) { - shutdownConnection(conn); - - if (this.eventListener != null) { - this.eventListener.fatalIOException(ex, conn); - } - } - - public void timeout(final NHttpServerConnection conn) { - shutdownConnection(conn); - - if (this.eventListener != null) { - this.eventListener.connectionTimeout(conn); - } - } - public void requestReceived(final NHttpServerConnection conn) { HttpContext context = conn.getContext(); @@ -581,20 +512,6 @@ } } - private boolean canResponseHaveBody( - final HttpRequest request, final HttpResponse response) { - - if (request != null && "HEAD".equalsIgnoreCase(request.getRequestLine().getMethod())) { - return false; - } - - int status = response.getStatusLine().getStatusCode(); - return status >= HttpStatus.SC_OK - && status != HttpStatus.SC_NO_CONTENT - && status != HttpStatus.SC_NOT_MODIFIED - && status != HttpStatus.SC_RESET_CONTENT; - } - static class ServerConnState { public static final int SHUTDOWN = -1;