hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1479825 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/conn/ main/java/org/apache/http/impl/conn/ test/java/org/apache/http/impl/conn/
Date Tue, 07 May 2013 09:23:40 GMT
Author: olegk
Date: Tue May  7 09:23:40 2013
New Revision: 1479825

URL: http://svn.apache.org/r1479825
Log:
Throw UnsupportedSchemeException instead of plain IOException in case of an unsupported protocol
scheme

Added:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java
  (with props)
Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java

Added: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java?rev=1479825&view=auto
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java
(added)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java
Tue May  7 09:23:40 2013
@@ -0,0 +1,51 @@
+/*
+ * ====================================================================
+ * 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.conn;
+
+import java.io.IOException;
+
+import org.apache.http.annotation.Immutable;
+
+/**
+ * Signals failure to establish connection using an unknown protocol scheme.
+ *
+ * @since 4.3
+ */
+@Immutable
+public class UnsupportedSchemeException extends IOException {
+
+    private static final long serialVersionUID = 3597127619218687636L;
+
+    /**
+     * Creates a UnsupportedSchemeException with the specified detail message.
+     */
+    public UnsupportedSchemeException(final String message) {
+        super(message);
+    }
+
+}

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/UnsupportedSchemeException.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java?rev=1479825&r1=1479824&r2=1479825&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/HttpClientConnectionOperator.java
Tue May  7 09:23:40 2013
@@ -45,12 +45,11 @@ import org.apache.http.conn.HttpClientCo
 import org.apache.http.conn.HttpHostConnectException;
 import org.apache.http.conn.ManagedHttpClientConnection;
 import org.apache.http.conn.SchemePortResolver;
+import org.apache.http.conn.UnsupportedSchemeException;
 import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
-import org.apache.http.conn.socket.PlainSocketFactory;
 import org.apache.http.protocol.HttpContext;
 import org.apache.http.util.Args;
-import org.apache.http.util.Asserts;
 
 @Immutable
 class HttpClientConnectionOperator {
@@ -94,7 +93,8 @@ class HttpClientConnectionOperator {
         final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(context);
         final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
         if (sf == null) {
-            throw new IOException("Unsupported scheme: " + host.getSchemeName());
+            throw new UnsupportedSchemeException(host.getSchemeName() +
+                    " protocol is not supported");
         }
         final InetAddress[] addresses = this.dnsResolver.resolve(host.getHostName());
         final int port = this.schemePortResolver.resolve(host);
@@ -144,12 +144,15 @@ class HttpClientConnectionOperator {
             final HttpContext context) throws IOException {
         final HttpClientContext clientContext = HttpClientContext.adapt(context);
         final Lookup<ConnectionSocketFactory> registry = getSocketFactoryRegistry(clientContext);
-        ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
+        final ConnectionSocketFactory sf = registry.lookup(host.getSchemeName());
         if (sf == null) {
-            sf = PlainSocketFactory.INSTANCE;
+            throw new UnsupportedSchemeException(host.getSchemeName() +
+                    " protocol is not supported");
+        }
+        if (!(sf instanceof LayeredConnectionSocketFactory)) {
+            throw new UnsupportedSchemeException(host.getSchemeName() +
+                    " protocol does not support connection upgrade");
         }
-        Asserts.check(sf instanceof LayeredConnectionSocketFactory,
-            "Socket factory must implement LayeredConnectionSocketFactory");
         final LayeredConnectionSocketFactory lsf = (LayeredConnectionSocketFactory) sf;
         Socket sock = conn.getSocket();
         try {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java?rev=1479825&r1=1479824&r2=1479825&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestHttpClientConnectionOperator.java
Tue May  7 09:23:40 2013
@@ -38,6 +38,7 @@ import org.apache.http.conn.ConnectTimeo
 import org.apache.http.conn.DnsResolver;
 import org.apache.http.conn.SchemePortResolver;
 import org.apache.http.conn.ManagedHttpClientConnection;
+import org.apache.http.conn.UnsupportedSchemeException;
 import org.apache.http.conn.socket.ConnectionSocketFactory;
 import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
 import org.apache.http.protocol.BasicHttpContext;
@@ -198,10 +199,20 @@ public class TestHttpClientConnectionOpe
         Mockito.verify(conn).bind(socket);
     }
 
-    @Test(expected=IllegalStateException.class)
+    @Test(expected=UnsupportedSchemeException.class)
+    public void testUpgradeUpsupportedScheme() throws Exception {
+        final HttpContext context = new BasicHttpContext();
+        final HttpHost host = new HttpHost("somehost", -1, "httpsssss");
+        Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
+
+        connectionOperator.upgrade(conn, host, context);
+    }
+
+    @Test(expected=UnsupportedSchemeException.class)
     public void testUpgradeNonLayeringScheme() throws Exception {
         final HttpContext context = new BasicHttpContext();
         final HttpHost host = new HttpHost("somehost", -1, "http");
+        Mockito.when(socketFactoryRegistry.lookup("http")).thenReturn(plainSocketFactory);
 
         connectionOperator.upgrade(conn, host, context);
     }



Mime
View raw message