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 2010/04/07 19:28:16 UTC
svn commit: r931624 [2/2] - in /httpcomponents/httpclient/trunk:
httpclient/src/main/java/org/apache/http/conn/
httpclient/src/main/java/org/apache/http/conn/scheme/
httpclient/src/main/java/org/apache/http/conn/ssl/
httpclient/src/main/java/org/apache...
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=931624&r1=931623&r2=931624&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 Wed Apr 7 17:28:15 2010
@@ -30,6 +30,7 @@ package org.apache.http.impl.conn;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
@@ -56,7 +57,7 @@ import org.apache.http.conn.routing.Http
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.localserver.ServerTestBase;
import org.apache.http.message.BasicHttpRequest;
@@ -505,8 +506,9 @@ public class TestTSCCMWithServer extends
public void testAbortDuringConnecting() throws Exception {
final CountDownLatch connectLatch = new CountDownLatch(1);
- final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.BEFORE_CONNECT, PlainSocketFactory.getSocketFactory());
- Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
+ final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
+ connectLatch, WaitPolicy.BEFORE_CONNECT, PlainSocketFactory.getSocketFactory());
+ Scheme scheme = new Scheme("http", 80, stallingSocketFactory);
SchemeRegistry registry = new SchemeRegistry();
registry.register(scheme);
@@ -555,8 +557,9 @@ public class TestTSCCMWithServer extends
public void testAbortBeforeSocketCreate() throws Exception {
final CountDownLatch connectLatch = new CountDownLatch(1);
- final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.BEFORE_CREATE, PlainSocketFactory.getSocketFactory());
- Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
+ final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
+ connectLatch, WaitPolicy.BEFORE_CREATE, PlainSocketFactory.getSocketFactory());
+ Scheme scheme = new Scheme("http", 80, stallingSocketFactory);
SchemeRegistry registry = new SchemeRegistry();
registry.register(scheme);
@@ -607,8 +610,9 @@ public class TestTSCCMWithServer extends
public void testAbortAfterSocketConnect() throws Exception {
final CountDownLatch connectLatch = new CountDownLatch(1);
- final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(connectLatch, WaitPolicy.AFTER_CONNECT, PlainSocketFactory.getSocketFactory());
- Scheme scheme = new Scheme("http", stallingSocketFactory, 80);
+ final StallingSocketFactory stallingSocketFactory = new StallingSocketFactory(
+ connectLatch, WaitPolicy.AFTER_CONNECT, PlainSocketFactory.getSocketFactory());
+ Scheme scheme = new Scheme("http", 80, stallingSocketFactory);
SchemeRegistry registry = new SchemeRegistry();
registry.register(scheme);
@@ -780,24 +784,27 @@ public class TestTSCCMWithServer extends
}
}
- private static class StallingSocketFactory extends LatchSupport implements SocketFactory {
- private final SocketFactory delegate;
+ private static class StallingSocketFactory extends LatchSupport implements SchemeSocketFactory {
+
+ private final SchemeSocketFactory delegate;
- public StallingSocketFactory(CountDownLatch continueLatch,
- WaitPolicy waitPolicy, SocketFactory delegate) {
+ public StallingSocketFactory(
+ final CountDownLatch continueLatch,
+ final WaitPolicy waitPolicy,
+ final SchemeSocketFactory delegate) {
super(continueLatch, waitPolicy);
this.delegate = delegate;
}
- public Socket connectSocket(Socket sock, String host, int port,
- InetAddress localAddress, int localPort, HttpParams params)
- throws IOException, UnknownHostException,
- ConnectTimeoutException {
+ public Socket connectSocket(
+ final Socket sock,
+ final InetSocketAddress remoteAddress,
+ final InetSocketAddress localAddress,
+ final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if(waitPolicy == WaitPolicy.BEFORE_CONNECT)
latch();
- Socket socket = delegate.connectSocket(sock, host, port, localAddress,
- localPort, params);
+ Socket socket = delegate.connectSocket(sock, remoteAddress, localAddress, params);
if(waitPolicy == WaitPolicy.AFTER_CONNECT)
latch();
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/impl/conn/tsccm/TestSpuriousWakeup.java Wed Apr 7 17:28:15 2010
@@ -42,7 +42,7 @@ import org.apache.http.conn.routing.Http
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.conn.params.ConnPerRoute;
import org.apache.http.impl.conn.GetConnThread;
@@ -130,8 +130,8 @@ public class TestSpuriousWakeup extends
public void testSpuriousWakeup() throws Exception {
SchemeRegistry schreg = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- schreg.register(new Scheme("http", sf, 80));
+ SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
+ schreg.register(new Scheme("http", 80, sf));
XTSCCM mgr = new XTSCCM(schreg);
try {
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/localserver/ServerTestBase.java Wed Apr 7 17:28:15 2010
@@ -27,6 +27,8 @@
package org.apache.http.localserver;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
import java.net.Socket;
import org.apache.http.HttpHost;
@@ -34,7 +36,7 @@ import org.apache.http.HttpVersion;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.impl.DefaultHttpClientConnection;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
@@ -116,8 +118,8 @@ public abstract class ServerTestBase ext
if (supportedSchemes == null) {
supportedSchemes = new SchemeRegistry();
- SocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", sf, 80));
+ SchemeSocketFactory sf = PlainSocketFactory.getSocketFactory();
+ supportedSchemes.register(new Scheme("http", 80, sf));
}
if (httpProcessor == null) {
@@ -179,8 +181,9 @@ public abstract class ServerTestBase ext
int port = schm.resolvePort(target.getPort());
DefaultHttpClientConnection conn = new DefaultHttpClientConnection();
- Socket sock = schm.getSocketFactory().connectSocket
- (null, target.getHostName(), port, null, 0, params);
+ InetSocketAddress address = new InetSocketAddress(
+ InetAddress.getByName(target.getHostName()), port);
+ Socket sock = schm.getSchemeSocketFactory().connectSocket(null, address, null, params);
conn.bind(sock, params);
return conn;
Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/mockup/SecureSocketFactoryMockup.java Wed Apr 7 17:28:15 2010
@@ -29,18 +29,16 @@ package org.apache.http.mockup;
import java.net.Socket;
-import org.apache.http.conn.scheme.LayeredSocketFactory;
+import org.apache.http.conn.scheme.LayeredSchemeSocketFactory;
/**
* {@link LayeredSocketFactory} mockup implementation.
*/
-public class SecureSocketFactoryMockup extends SocketFactoryMockup
- implements LayeredSocketFactory {
+public class SecureSocketFactoryMockup extends SocketFactoryMockup
+ implements LayeredSchemeSocketFactory {
/* A default instance of this mockup. */
- public final static LayeredSocketFactory INSTANCE =
- new SecureSocketFactoryMockup("INSTANCE");
-
+ public final static LayeredSchemeSocketFactory INSTANCE = new SecureSocketFactoryMockup("INSTANCE");
public SecureSocketFactoryMockup(String name) {
super(name);
@@ -54,8 +52,9 @@ public class SecureSocketFactoryMockup e
}
- public Socket createSocket(Socket socket, String host, int port,
+ public Socket createLayeredSocket(Socket socket, String host, int port,
boolean autoClose) {
throw new UnsupportedOperationException("I'm a mockup!");
}
+
}
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=931624&r1=931623&r2=931624&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 Wed Apr 7 17:28:15 2010
@@ -27,27 +27,26 @@
package org.apache.http.mockup;
+import java.io.IOException;
+import java.net.InetSocketAddress;
import java.net.Socket;
-import java.net.InetAddress;
+import java.net.UnknownHostException;
-import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
import org.apache.http.params.HttpParams;
-
-
/**
* {@link SocketFactory} mockup implementation.
*/
-public class SocketFactoryMockup implements SocketFactory {
+public class SocketFactoryMockup implements SchemeSocketFactory {
/* A default instance of this mockup. */
- public final static SocketFactory INSTANCE =
- new SocketFactoryMockup("INSTANCE");
+ public final static SchemeSocketFactory INSTANCE = new SocketFactoryMockup("INSTANCE");
/** The name of this mockup socket factory. */
protected final String mockup_name;
-
public SocketFactoryMockup(String name) {
mockup_name = (name != null) ? name : String.valueOf(hashCode());
}
@@ -59,14 +58,15 @@ public class SocketFactoryMockup impleme
return "SocketFactoryMockup." + mockup_name;
}
-
public Socket createSocket() {
throw new UnsupportedOperationException("I'm a mockup!");
}
- public Socket connectSocket(Socket sock, String host, int port,
- InetAddress localAddress, int localPort,
- HttpParams params) {
+ public Socket connectSocket(
+ Socket sock,
+ InetSocketAddress remoteAddress,
+ InetSocketAddress localAddress,
+ HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
throw new UnsupportedOperationException("I'm a mockup!");
}
@@ -74,4 +74,5 @@ public class SocketFactoryMockup impleme
// no way that the argument is from *this* factory...
throw new IllegalArgumentException("I'm a mockup!");
}
+
}
Modified: httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml?rev=931624&r1=931623&r2=931624&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml (original)
+++ httpcomponents/httpclient/trunk/src/docbkx/connmgmt.xml Wed Apr 7 17:28:15 2010
@@ -236,7 +236,7 @@
<title>Socket factories</title>
<para>HTTP connections make use of a <classname>java.net.Socket</classname> object
internally to handle transmission of data across the wire. They, however, rely on
- <interfacename>SocketFactory</interfacename> interface to create, initialize and
+ <interfacename>SchemeSocketFactory</interfacename> interface to create, initialize and
connect sockets. This enables the users of HttpClient to provide application specific
socket initialization code at runtime. <classname>PlainSocketFactory</classname> is the
default factory for creating and initializing plain (unencrypted) sockets.</para>
@@ -248,17 +248,19 @@ Socket socket = sf.createSocket();
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000L);
-sf.connectSocket(socket, "locahost", 8080, null, -1, params);
+InetSocketAddress address = new InetSocketAddress("locahost", 8080);
+sf.connectSocket(socket, address, null, params);
]]></programlisting>
<section>
<title>Secure socket layering</title>
- <para><interfacename>LayeredSocketFactory</interfacename> is an extension of
- <interfacename>SocketFactory</interfacename> interface. Layered socket factories
- are capable of creating sockets that are layered over an existing plain socket.
+ <para><interfacename>LayeredSchemeSocketFactory</interfacename> is an extension of
+ <interfacename>SchemeSocketFactory</interfacename> interface. Layered socket
+ factories are capable of creating sockets layered over an existing plain socket.
Socket layering is used primarily for creating secure sockets through proxies.
- HttpClient ships with SSLSocketFactory that implements SSL/TLS layering. Please note
- HttpClient does not use any custom encryption functionality. It is fully reliant on
- standard Java Cryptography (JCE) and Secure Sockets (JSEE) extensions.</para>
+ HttpClient ships with <classname>SSLSocketFactory</classname> that implements
+ SSL/TLS layering. Please note HttpClient does not use any custom encryption
+ functionality. It is fully reliant on standard Java Cryptography (JCE) and Secure
+ Sockets (JSEE) extensions.</para>
</section>
<section>
<title>SSL/TLS customization</title>
@@ -300,7 +302,8 @@ socket.setEnabledCipherSuites(new String
HttpParams params = new BasicHttpParams();
params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000L);
-sf.connectSocket(socket, "locahost", 443, null, -1, params);
+InetSocketAddress address = new InetSocketAddress("locahost", 443);
+sf.connectSocket(socket, address, null, params);
]]></programlisting>
<para>Customization of SSLSocketFactory implies a certain degree of familiarity with the
concepts of the SSL/TLS protocol, a detailed explanation of which is out of scope
@@ -357,8 +360,9 @@ sf.connectSocket(socket, "locahost", 443
implementation. One can specify a different hostname verifier implementation if
desired</para>
<programlisting><![CDATA[
-SSLSocketFactory sf = new SSLSocketFactory(SSLContext.getInstance("TLS"));
-sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
+SSLSocketFactory sf = new SSLSocketFactory(
+ SSLContext.getInstance("TLS"),
+ SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
]]></programlisting>
</section>
</section>
@@ -371,11 +375,12 @@ sf.setHostnameVerifier(SSLSocketFactory.
a set of <classname>Scheme</classname>s HttpClient can choose from when trying to
establish a connection by a request URI:</para>
<programlisting><![CDATA[
-Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
-SSLSocketFactory sf = new SSLSocketFactory(SSLContext.getInstance("TLS"));
-sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
-Scheme https = new Scheme("https", sf, 443);
+SSLSocketFactory sf = new SSLSocketFactory(
+ SSLContext.getInstance("TLS"),
+ SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
+Scheme https = new Scheme("https", 443, sf);
SchemeRegistry sr = new SchemeRegistry();
sr.register(http);
@@ -434,7 +439,7 @@ httpclient.setRoutePlanner(new HttpRoute
<interfacename>ClientConnectionOperator</interfacename> interface represents a
strategy for creating <interfacename>OperatedClientConnection</interfacename>
instances and updating the underlying socket of those objects. Implementations will
- most likely make use <interfacename>SocketFactory</interfacename>s to create
+ most likely make use <interfacename>SchemeSocketFactory</interfacename>s to create
<classname>java.net.Socket</classname> instances. The
<interfacename>ClientConnectionOperator</interfacename> interface enables the
users of HttpClient to provide a custom strategy for connection operators as well as
@@ -475,7 +480,7 @@ httpclient.setRoutePlanner(new HttpRoute
unintentionally.</para>
<para>This is an example of acquiring a connection from a connection manager:</para>
<programlisting><![CDATA[
-Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80);
+Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
SchemeRegistry sr = new SchemeRegistry();
sr.register(http);
ClientConnectionManager connMrg = new SingleClientConnManager(sr);
@@ -562,9 +567,9 @@ try {
<programlisting><![CDATA[
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
- new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
schemeRegistry.register(
- new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
+ new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));
ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry);
// Increase max total connection to 200
@@ -630,7 +635,7 @@ httpclient.getConnectionManager().shutdo
<programlisting><![CDATA[
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(
- new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
+ new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
ClientConnectionManager cm = new ThreadSafeClientConnManager(schemeRegistry);
HttpClient httpClient = new DefaultHttpClient(cm);