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 2013/08/02 08:38:39 UTC
svn commit: r1509555 - in
/httpcomponents/httpasyncclient/trunk/httpasyncclient/src:
main/java/org/apache/http/impl/nio/conn/
test/java/org/apache/http/impl/nio/conn/
test/java/org/apache/http/nio/client/integration/
Author: olegk
Date: Fri Aug 2 06:38:38 2013
New Revision: 1509555
URL: http://svn.apache.org/r1509555
Log:
Throw UnsupportedSchemeException instead of plain IOException in case of an unsupported protocol scheme
Modified:
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java
httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestRedirects.java
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java?rev=1509555&r1=1509554&r2=1509555&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/main/java/org/apache/http/impl/nio/conn/PoolingNHttpClientConnectionManager.java Fri Aug 2 06:38:38 2013
@@ -233,7 +233,8 @@ public class PoolingNHttpClientConnectio
final SchemeIOSessionFactory sf = this.iosessionFactoryRegistry.lookup(
host.getSchemeName());
if (sf == null) {
- future.failed(new IOException("Unsupported scheme: " + host.getSchemeName()));
+ future.failed(new UnsupportedSchemeException(host.getSchemeName() +
+ " protocol is not supported"));
return future;
}
this.pool.lease(route, state, connectTimeout,
@@ -259,7 +260,7 @@ public class PoolingNHttpClientConnectio
entry.setState(state);
entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
if (this.log.isDebugEnabled()) {
- String s;
+ final String s;
if (keepalive > 0) {
s = "for " + (double) keepalive / 1000 + " seconds";
} else {
@@ -326,10 +327,13 @@ public class PoolingNHttpClientConnectio
throw new UnsupportedSchemeException(host.getSchemeName() +
" protocol is not supported");
}
+ if (!sf.isLayering()) {
+ throw new UnsupportedSchemeException(host.getSchemeName() +
+ " protocol does not support connection upgrade");
+ }
synchronized (managedConn) {
final CPoolEntry entry = CPoolProxy.getPoolEntry(managedConn);
final ManagedNHttpClientConnection conn = entry.getConnection();
- Asserts.check(sf.isLayering(), "Layering is not supported for this scheme");
final IOSession currentSession = sf.create(host, conn.getIOSession());
conn.bind(currentSession);
}
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java?rev=1509555&r1=1509554&r2=1509555&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/impl/nio/conn/TestPoolingHttpClientAsyncConnectionManager.java Fri Aug 2 06:38:38 2013
@@ -56,7 +56,6 @@ import org.apache.http.nio.conn.SchemeIO
import org.apache.http.nio.reactor.ConnectingIOReactor;
import org.apache.http.nio.reactor.IOSession;
import org.apache.http.nio.reactor.SessionRequest;
-import org.apache.http.nio.reactor.SessionRequestCallback;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.junit.Before;
@@ -89,8 +88,6 @@ public class TestPoolingHttpClientAsyncC
private ManagedNHttpClientConnection conn;
@Mock
private NHttpConnectionFactory<ManagedNHttpClientConnection> connFactory;
- @Captor
- private ArgumentCaptor<SessionRequestCallback> sessionRequestCallbackCaptor;
@Mock
private SessionRequest sessionRequest;
@Mock
@@ -363,7 +360,24 @@ public class TestPoolingHttpClientAsyncC
Mockito.verify(conn).bind(iosession);
}
- @Test(expected=IllegalStateException.class)
+ @Test(expected=UnsupportedSchemeException.class)
+ public void testConnectionUpgradeUnknownScheme() throws Exception {
+ final HttpHost target = new HttpHost("somehost", -1, "whatever");
+ final HttpRoute route = new HttpRoute(target);
+ final HttpContext context = new BasicHttpContext();
+
+ final Log log = Mockito.mock(Log.class);
+ final CPoolEntry poolentry = new CPoolEntry(log, "some-id", route, conn, -1, TimeUnit.MILLISECONDS);
+ poolentry.markRouteComplete();
+ final NHttpClientConnection managedConn = CPoolProxy.newProxy(poolentry);
+
+ Mockito.when(conn.getIOSession()).thenReturn(iosession);
+ Mockito.when(sslFactory.create(target, iosession)).thenReturn(iosession);
+
+ connman.upgrade(managedConn, route, context);
+ }
+
+ @Test(expected=UnsupportedSchemeException.class)
public void testConnectionUpgradeIllegalScheme() throws Exception {
final HttpHost target = new HttpHost("somehost", -1, "http");
final HttpRoute route = new HttpRoute(target);
Modified: httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestRedirects.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestRedirects.java?rev=1509555&r1=1509554&r2=1509555&view=diff
==============================================================================
--- httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestRedirects.java (original)
+++ httpcomponents/httpasyncclient/trunk/httpasyncclient/src/test/java/org/apache/http/nio/client/integration/TestRedirects.java Fri Aug 2 06:38:38 2013
@@ -770,7 +770,7 @@ public class TestRedirects extends HttpA
final HttpResponse response,
final HttpContext context) throws HttpException, IOException {
final ProtocolVersion ver = request.getRequestLine().getProtocolVersion();
- String location;
+ final String location;
try {
final URIBuilder uribuilder = new URIBuilder(request.getRequestLine().getUri());
uribuilder.setScheme(this.host.getSchemeName());