Revision 58d848ab
Added by Andreas Kohlbecker almost 9 years ago
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/UriUtils.java | ||
---|---|---|
21 | 21 |
import java.net.URISyntaxException; |
22 | 22 |
import java.net.URL; |
23 | 23 |
import java.net.UnknownHostException; |
24 |
import java.security.KeyManagementException; |
|
25 |
import java.security.NoSuchAlgorithmException; |
|
26 |
import java.security.cert.X509Certificate; |
|
24 | 27 |
import java.util.ArrayList; |
25 | 28 |
import java.util.HashMap; |
26 | 29 |
import java.util.List; |
27 | 30 |
import java.util.Map; |
28 | 31 |
import java.util.Map.Entry; |
29 | 32 |
|
33 |
import javax.net.ssl.SSLContext; |
|
34 |
import javax.net.ssl.TrustManager; |
|
35 |
import javax.net.ssl.X509TrustManager; |
|
36 |
|
|
30 | 37 |
import org.apache.http.Header; |
31 | 38 |
import org.apache.http.HttpEntity; |
32 | 39 |
import org.apache.http.HttpException; |
... | ... | |
42 | 49 |
import org.apache.http.client.methods.HttpUriRequest; |
43 | 50 |
import org.apache.http.client.utils.URIBuilder; |
44 | 51 |
import org.apache.http.client.utils.URLEncodedUtils; |
52 |
import org.apache.http.conn.scheme.Scheme; |
|
53 |
import org.apache.http.conn.ssl.SSLSocketFactory; |
|
45 | 54 |
import org.apache.http.impl.client.DefaultHttpClient; |
46 | 55 |
import org.apache.http.params.HttpConnectionParams; |
47 | 56 |
import org.apache.log4j.Logger; |
... | ... | |
219 | 228 |
// Create an instance of HttpClient. |
220 | 229 |
HttpClient client = new DefaultHttpClient(); |
221 | 230 |
|
231 |
try { |
|
232 |
SSLContext sc = SSLContext.getInstance("SSL"); |
|
233 |
sc.init(null, getTrustingManager(), new java.security.SecureRandom()); |
|
234 |
SSLSocketFactory socketFactory = new SSLSocketFactory(sc); |
|
235 |
Scheme sch = new Scheme("https", 443, socketFactory); |
|
236 |
client.getConnectionManager().getSchemeRegistry().register(sch); |
|
237 |
} catch (KeyManagementException e1) { |
|
238 |
throw new RuntimeException("Registration of ssl support failed", e1); |
|
239 |
} catch (NoSuchAlgorithmException e2) { |
|
240 |
throw new RuntimeException("Registration of ssl support failed", e2); |
|
241 |
} |
|
242 |
|
|
243 |
|
|
222 | 244 |
HttpUriRequest method; |
223 | 245 |
switch (httpMethod) { |
224 | 246 |
case GET: |
... | ... | |
454 | 476 |
} |
455 | 477 |
return success; |
456 | 478 |
} |
479 |
|
|
480 |
private static TrustManager[] getTrustingManager() { |
|
481 |
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { |
|
482 |
@Override |
|
483 |
public java.security.cert.X509Certificate[] getAcceptedIssuers() { |
|
484 |
return null; |
|
485 |
} |
|
486 |
|
|
487 |
@Override |
|
488 |
public void checkClientTrusted(X509Certificate[] certs, String authType) { |
|
489 |
// Do nothing |
|
490 |
} |
|
491 |
|
|
492 |
@Override |
|
493 |
public void checkServerTrusted(X509Certificate[] certs, String authType) { |
|
494 |
// Do nothing |
|
495 |
} |
|
496 |
|
|
497 |
} }; |
|
498 |
return trustAllCerts; |
|
499 |
} |
|
457 | 500 |
} |
Also available in: Unified diff
adding support for https in UriUtils