package org.simantics.scl.rest;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.X509Certificate;
import java.util.concurrent.Future;
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSession;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.X509TrustManager;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Invocation;
public static Client buildClient(ClientBuilder clientBuilder) {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.register(MultiPartFeature.class);
- return ClientBuilder.newBuilder().withConfig((Configuration) clientConfig).build();
+ return clientBuilder.withConfig((Configuration) clientConfig).build();
}
public static String statusMessageOf(Response response) {
}
});
}
+
+ public static ClientBuilder trustAllClientBuilder() throws NoSuchAlgorithmException, KeyManagementException {
+ TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+ public void checkClientTrusted(X509Certificate[] certs, String authType) {
+ }
+ public void checkServerTrusted(X509Certificate[] certs, String authType) {
+ }
+ }
+ };
+
+ SSLContext sc = SSLContext.getInstance("SSL");
+ sc.init(null, trustAllCerts, new java.security.SecureRandom());
+
+ return ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier(new HostnameVerifier() {
+ @Override
+ public boolean verify(String hostname, SSLSession session) {
+ return true;
+ }
+ });
+ }
}