20
20
*/
21
21
22
22
import org .apache .commons .httpclient .protocol .ProtocolSocketFactory ;
23
- import org .apache .http .conn .ConnectTimeoutException ;
24
- import org .apache .http .params .HttpConnectionParams ;
25
- import org .apache .http .params .HttpParams ;
26
23
27
24
import java .io .IOException ;
28
25
import java .net .InetAddress ;
29
- import java .net .InetSocketAddress ;
30
26
import java .net .Socket ;
31
- import java .net .UnknownHostException ;
32
27
33
28
import javax .net .ssl .SSLContext ;
34
- import javax .net .ssl .SSLSocket ;
35
29
import javax .net .ssl .TrustManager ;
36
30
37
31
/**
38
- * This socket factory will create ssl socket that accepts self signed
39
- * certificate
32
+ * This socket factory will create ssl socket that accepts self signed certificate
40
33
*
41
34
* @author olamy
42
35
* @version $Id: EasySSLSocketFactory.java 765355 2009-04-15 20:59:07Z evenisse
@@ -50,8 +43,7 @@ public class EasySSLSocketFactory implements ProtocolSocketFactory {
50
43
private static SSLContext createEasySSLContext () throws IOException {
51
44
try {
52
45
SSLContext context = SSLContext .getInstance ("TLS" );
53
- context .init (null , new TrustManager []{new EasyX509TrustManager (
54
- null )}, null );
46
+ context .init (null , new TrustManager []{new EasyX509TrustManager (null )}, null );
55
47
return context ;
56
48
} catch (Throwable e ) {
57
49
throw new IOException (e .getMessage ());
@@ -65,92 +57,33 @@ private SSLContext getSSLContext() throws IOException {
65
57
return this .sslcontext ;
66
58
}
67
59
68
- /**
69
- * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(Socket,
70
- * String, int, InetAddress, int,
71
- * HttpParams)
72
- */
73
- public Socket connectSocket (Socket sock , String host , int port ,
74
- InetAddress localAddress , int localPort , HttpParams params )
75
- throws IOException , UnknownHostException , ConnectTimeoutException {
76
- int connTimeout = HttpConnectionParams .getConnectionTimeout (params );
77
- int soTimeout = HttpConnectionParams .getSoTimeout (params );
78
-
79
- InetSocketAddress remoteAddress = new InetSocketAddress (host , port );
80
- SSLSocket sslsock = (SSLSocket ) ((sock != null ) ? sock : createSocket ());
81
-
82
- if ((localAddress != null ) || (localPort > 0 )) {
83
- // we need to bind explicitly
84
- if (localPort < 0 ) {
85
- localPort = 0 ; // indicates "any"
86
- }
87
- InetSocketAddress isa = new InetSocketAddress (localAddress ,
88
- localPort );
89
- sslsock .bind (isa );
90
- }
91
-
92
- sslsock .connect (remoteAddress , connTimeout );
93
- sslsock .setSoTimeout (soTimeout );
94
- return sslsock ;
95
-
96
- }
97
-
98
- /**
99
- * @see org.apache.http.conn.scheme.SocketFactory#createSocket()
100
- */
101
- public Socket createSocket () throws IOException {
102
- return getSSLContext ().getSocketFactory ().createSocket ();
103
- }
104
-
105
- /**
106
- * @see org.apache.http.conn.scheme.SocketFactory#isSecure(Socket)
107
- */
108
- public boolean isSecure (Socket socket ) throws IllegalArgumentException {
109
- return true ;
110
- }
111
-
112
- /**
113
- * @see org.apache.http.conn.scheme.LayeredSocketFactory#createSocket(Socket,
114
- * String, int, boolean)
115
- */
116
- public Socket createSocket (Socket socket , String host , int port ,
117
- boolean autoClose ) throws IOException , UnknownHostException {
118
- return getSSLContext ().getSocketFactory ().createSocket (socket , host , port , autoClose );
119
- }
120
-
121
60
// -------------------------------------------------------------------
122
61
// javadoc in org.apache.http.conn.scheme.SocketFactory says :
123
62
// Both Object.equals() and Object.hashCode() must be overridden
124
63
// for the correct operation of some connection managers
125
64
// -------------------------------------------------------------------
126
65
127
66
public boolean equals (Object obj ) {
128
- return ((obj != null ) && obj .getClass ().equals (
129
- EasySSLSocketFactory .class ));
67
+ return ((obj != null ) && obj .getClass ().equals (EasySSLSocketFactory .class ));
130
68
}
131
69
132
70
public int hashCode () {
133
71
return EasySSLSocketFactory .class .hashCode ();
134
72
}
135
73
136
74
@ Override
137
- public Socket createSocket (String arg0 , int arg1 ) throws IOException ,
138
- UnknownHostException {
75
+ public Socket createSocket (String arg0 , int arg1 ) throws IOException {
139
76
return getSSLContext ().getSocketFactory ().createSocket (arg0 , arg1 );
140
77
}
141
78
142
79
@ Override
143
- public Socket createSocket (String arg0 , int arg1 , InetAddress arg2 ,
144
- int arg3 ) throws IOException , UnknownHostException {
80
+ public Socket createSocket (String arg0 , int arg1 , InetAddress arg2 , int arg3 ) throws IOException {
145
81
return getSSLContext ().getSocketFactory ().createSocket (arg0 , arg1 , arg2 , arg3 );
146
82
}
147
83
148
84
@ Override
149
- public Socket createSocket (String arg0 , int arg1 , InetAddress arg2 ,
150
- int arg3 ,
151
- org .apache .commons .httpclient .params .HttpConnectionParams arg4 )
152
- throws IOException , UnknownHostException ,
153
- org .apache .commons .httpclient .ConnectTimeoutException {
85
+ public Socket createSocket (String arg0 , int arg1 , InetAddress arg2 , int arg3 , org .apache .commons .httpclient .params .HttpConnectionParams arg4 )
86
+ throws IOException {
154
87
return getSSLContext ().getSocketFactory ().createSocket (arg0 , arg1 , arg2 , arg3 );
155
88
}
156
89
}
0 commit comments