hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r937235 - in /httpcomponents/httpclient/trunk/httpclient/src: examples/org/apache/http/examples/client/ main/java/org/apache/http/conn/scheme/ main/java/org/apache/http/conn/ssl/ main/java/org/apache/http/impl/conn/ test/java/org/apache/htt...
Date Fri, 23 Apr 2010 10:30:24 GMT
Author: olegk
Date: Fri Apr 23 10:30:24 2010
New Revision: 937235

URL: http://svn.apache.org/viewvc?rev=937235&view=rev
Log:
Make it easier to support connections via SOCKS proxies

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/examples/org/apache/http/examples/client/ClientExecuteSOCKS.java
Fri Apr 23 10:30:24 2010
@@ -89,8 +89,16 @@ public class ClientExecuteSOCKS {
     
     static class MySchemeSocketFactory implements SchemeSocketFactory {
 
-        public Socket createSocket() throws IOException {
-            return new Socket();
+        public Socket createSocket(final HttpParams params) throws IOException {
+            if (params == null) {
+                throw new IllegalArgumentException("HTTP parameters may not be null");
+            }
+            String proxyHost = (String) params.getParameter("socks.host");
+            Integer proxyPort = (Integer) params.getParameter("socks.port");
+
+            InetSocketAddress socksaddr = new InetSocketAddress(proxyHost, proxyPort); 
+            Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr);
+            return new Socket(proxy);
         }
 
         public Socket connectSocket(
@@ -105,12 +113,12 @@ public class ClientExecuteSOCKS {
             if (params == null) {
                 throw new IllegalArgumentException("HTTP parameters may not be null");
             }
-            String proxyHost = (String) params.getParameter("socks.host");
-            Integer proxyPort = (Integer) params.getParameter("socks.port");
-
-            InetSocketAddress socksaddr = new InetSocketAddress(proxyHost, proxyPort); 
-            Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr);
-            Socket sock = new Socket(proxy);
+            Socket sock;
+            if (socket != null) {
+                sock = socket;
+            } else {
+                sock = createSocket(params);
+            }
             if (localAddress != null) {
                 sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
                 sock.bind(localAddress);

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java
Fri Apr 23 10:30:24 2010
@@ -84,6 +84,13 @@ public final class PlainSocketFactory im
         this.nameResolver = null;
     }
 
+    /**
+     * @since 4.1
+     */
+    public Socket createSocket(final HttpParams params) {
+        return new Socket();
+    }
+
     public Socket createSocket() {
         return new Socket();
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactory.java
Fri Apr 23 10:30:24 2010
@@ -47,11 +47,12 @@ public interface SchemeSocketFactory {
      * Creates a new, unconnected socket. The socket should subsequently be passed to
      * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}.
      *
+     * @param params    additional {@link HttpParams parameters}
      * @return  a new socket
      * 
      * @throws IOException if an I/O error occurs while creating the socket
      */
-    Socket createSocket() throws IOException;
+    Socket createSocket(HttpParams params) throws IOException;
 
     /**
      * Connects a socket to the target host with the given remote address.

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SchemeSocketFactoryAdaptor.java
Fri Apr 23 10:30:24 2010
@@ -62,7 +62,7 @@ class SchemeSocketFactoryAdaptor impleme
         return this.factory.connectSocket(sock, host, port, local, localPort, params);
     }
 
-    public Socket createSocket() throws IOException {
+    public Socket createSocket(final HttpParams params) throws IOException {
         return this.factory.createSocket();
     }
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/scheme/SocketFactoryAdaptor.java
Fri Apr 23 10:30:24 2010
@@ -34,6 +34,7 @@ import java.net.Socket;
 import java.net.UnknownHostException;
 
 import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.params.BasicHttpParams;
 import org.apache.http.params.HttpParams;
 
 @Deprecated
@@ -47,7 +48,8 @@ class SocketFactoryAdaptor implements So
     }
     
     public Socket createSocket() throws IOException {
-        return this.factory.createSocket();
+        HttpParams params = new BasicHttpParams();
+        return this.factory.createSocket(params);
     }
 
     public Socket connectSocket(

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.java
Fri Apr 23 10:30:24 2010
@@ -334,6 +334,14 @@ public class SSLSocketFactory implements
         this.nameResolver = null;
     }
     
+    /**
+     * @since 4.1
+     */
+    public Socket createSocket(final HttpParams params) throws IOException {
+        // the cast makes sure that the factory is working as expected
+        return (SSLSocket) this.socketfactory.createSocket();
+    }
+
     @SuppressWarnings("cast")
     public Socket createSocket() throws IOException {
         // the cast makes sure that the factory is working as expected

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/impl/conn/DefaultClientConnectionOperator.java
Fri Apr 23 10:30:24 2010
@@ -133,7 +133,7 @@ public class DefaultClientConnectionOper
             InetAddress address = addresses[i];
             boolean last = i == addresses.length - 1;
             
-            Socket sock = sf.createSocket();
+            Socket sock = sf.createSocket(params);
             conn.opening(sock, target);
 
             InetSocketAddress remoteAddress = new InetSocketAddress(address, port);
@@ -164,7 +164,7 @@ public class DefaultClientConnectionOper
             }
             if (this.log.isDebugEnabled()) {
                 this.log.debug("Connect to " + remoteAddress + " timed out. " +
-                		"Connection will be retried using another IP address");
+                        "Connection will be retried using another IP address");
             }
         }
     }

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/TestTSCCMWithServer.java
Fri Apr 23 10:30:24 2010
@@ -812,11 +812,11 @@ public class TestTSCCMWithServer extends
             return socket;
         }
 
-        public Socket createSocket() throws IOException {
+        public Socket createSocket(final HttpParams params) throws IOException {
             if(waitPolicy == WaitPolicy.BEFORE_CREATE)
                 latch();
             
-            return delegate.createSocket();
+            return delegate.createSocket(params);
         }
 
         public boolean isSecure(Socket sock) throws IllegalArgumentException {

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java?rev=937235&r1=937234&r2=937235&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SocketFactoryMockup.java
Fri Apr 23 10:30:24 2010
@@ -58,7 +58,7 @@ public class SocketFactoryMockup impleme
         return "SocketFactoryMockup." + mockup_name;
     }
 
-    public Socket createSocket() {
+    public Socket createSocket(final HttpParams params) {
         throw new UnsupportedOperationException("I'm a mockup!");
     }
 



Mime
View raw message