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 2007/06/16 19:27:43 UTC
svn commit: r547954 -
/jakarta/httpcomponents/httpcore/trunk/module-nio/src/main/java/org/apache/http/nio/protocol/
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 <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
*/
-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 <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
*/
-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
+ * <http://www.apache.org/>.
+ *
+ */
+
+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
+ * <http://www.apache.org/>.
+ *
+ */
+
+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
+ * <http://www.apache.org/>.
+ *
+ */
+
+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 <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
*/
-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 <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a>
*
*/
-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;