// Construct a new Jest client according to configuration via factory
final JestClientFactory factory1 = new JestClientFactory();
factory1.setHttpClientConfig(clientConfig1);
final JestHttpClient c = (JestHttpClient) factory1.getObject();
final HttpClientBuilder hcb = HttpClients.custom();
if (serverUri.startsWith("https")) {
log.info("Configure Jest with SSL");
final KeyStore myTrustStore = KeyStore.getInstance("PKCS12");
myTrustStore
.load(new FileInputStream(
SecurityUtil
.getAbsoluteFilePathFromClassPath("localhost_tc.p12")),
"changeit".toCharArray());
final KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(
new FileInputStream(
SecurityUtil
.getAbsoluteFilePathFromClassPath("hnelsonclient.p12")),
"changeit".toCharArray());
final SSLContext sslContext = SSLContexts.custom().useTLS()
.loadKeyMaterial(keyStore, "changeit".toCharArray())
.loadTrustMaterial(myTrustStore)
.build();
final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslContext);
hcb.setSSLSocketFactory(sslsf);
}
if (username != null) {
final GSSContext context = initGSS(new URL(serverUri), "spnego-client", username,password);
final byte[] data = context.initSecContext(new byte[0], 0, 0);
final List<Header> dh = new ArrayList<Header>();
dh.add(new BasicHeader("Authorization","Negotiate "
+ org.apache.tomcat.util.codec.binary.Base64
.encodeBase64String(data)));
hcb.setDefaultHeaders(dh);
}
c.setHttpClient(hcb.build());
return c;