HTTPCLIENT-881: An I/O operation on an aborted or released connection will result in an InterruptedIOException

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk@826037 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2009-10-16 19:00:17 +00:00
parent 077281ba27
commit 64c481f4bf
4 changed files with 66 additions and 12 deletions

View File

@ -80,6 +80,7 @@ import org.apache.http.conn.routing.HttpRouteDirector;
import org.apache.http.conn.routing.HttpRoutePlanner;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.entity.BufferedHttpEntity;
import org.apache.http.impl.conn.ConnectionShutdownException;
import org.apache.http.message.BasicHttpRequest;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
@ -559,6 +560,8 @@ public class DefaultRequestDirector implements RequestDirector {
return response;
} catch (ConnectionShutdownException ex) {
throw new InterruptedIOException("Connection has been shut down");
} catch (HttpException ex) {
abortConnection();
throw ex;

View File

@ -129,7 +129,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti
*/
protected final void assertNotAborted() throws InterruptedIOException {
if (shutdown) {
throw new InterruptedIOException("Connection has been shut down.");
throw new InterruptedIOException("Connection has been shut down");
}
}
@ -142,7 +142,7 @@ public abstract class AbstractClientConnAdapter implements ManagedClientConnecti
protected final void assertValid(
final OperatedClientConnection wrappedConn) {
if (wrappedConn == null) {
throw new IllegalStateException("No wrapped connection.");
throw new ConnectionShutdownException();
}
}

View File

@ -72,7 +72,7 @@ public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapte
*/
protected final void assertAttached() {
if (poolEntry == null) {
throw new IllegalStateException("Adapter is detached.");
throw new ConnectionShutdownException();
}
}
@ -87,7 +87,6 @@ public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapte
}
public HttpRoute getRoute() {
assertAttached();
return (poolEntry.tracker == null) ?
null : poolEntry.tracker.toRoute();
@ -96,35 +95,36 @@ public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapte
public void open(HttpRoute route,
HttpContext context, HttpParams params)
throws IOException {
assertNotAborted();
assertAttached();
poolEntry.open(route, context, params);
}
public void tunnelTarget(boolean secure, HttpParams params)
throws IOException {
assertNotAborted();
assertAttached();
poolEntry.tunnelTarget(secure, params);
}
public void tunnelProxy(HttpHost next, boolean secure, HttpParams params)
throws IOException {
assertNotAborted();
assertAttached();
poolEntry.tunnelProxy(next, secure, params);
}
public void layerProtocol(HttpContext context, HttpParams params)
throws IOException {
assertNotAborted();
assertAttached();
poolEntry.layerProtocol(context, params);
}
public void close() throws IOException {
if (poolEntry != null)
poolEntry.shutdownEntry();
AbstractPoolEntry entry = poolEntry;
if (entry != null)
entry.shutdownEntry();
OperatedClientConnection conn = getWrappedConnection();
if (conn != null) {
@ -133,8 +133,9 @@ public abstract class AbstractPooledConnAdapter extends AbstractClientConnAdapte
}
public void shutdown() throws IOException {
if (poolEntry != null)
poolEntry.shutdownEntry();
AbstractPoolEntry entry = poolEntry;
if (entry != null)
entry.shutdownEntry();
OperatedClientConnection conn = getWrappedConnection();
if (conn != null) {

View File

@ -0,0 +1,50 @@
/*
* ====================================================================
* 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.impl.conn;
import org.apache.http.annotation.Immutable;
/**
* Signals that the connection has been shut down or released back to the
* the connection pool
*
* @since 4.1
*/
@Immutable
public class ConnectionShutdownException extends IllegalStateException {
private static final long serialVersionUID = 5868657401162844497L;
/**
* Creates a new ConnectionShutdownException with a <tt>null</tt> detail message.
*/
public ConnectionShutdownException() {
super();
}
}