use of org.apache.http.conn.ssl.SSLContextBuilder in project jetty-bootstrap by teknux-org.
the class AbstractJettyBootstrapTest method get.
protected SimpleResponse get(String url) throws IllegalStateException, IOException, JettyBootstrapException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
SimpleResponse simpleResponse = new SimpleResponse();
CloseableHttpClient httpClient;
HttpGet httpGet;
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIMEOUT).build();
if (ssl) {
SSLContextBuilder sSLContextBuilder = new SSLContextBuilder();
sSLContextBuilder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sSLConnectionSocketFactory = new SSLConnectionSocketFactory(sSLContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
httpClient = HttpClients.custom().setSSLSocketFactory(sSLConnectionSocketFactory).build();
httpGet = new HttpGet("https://" + HOST + ":" + getPort() + url);
} else {
httpClient = HttpClients.createDefault();
httpGet = new HttpGet("http://" + HOST + ":" + getPort() + url);
}
httpGet.setConfig(requestConfig);
CloseableHttpResponse response = null;
try {
response = httpClient.execute(httpGet);
simpleResponse.setStatusCode(response.getStatusLine().getStatusCode());
simpleResponse.setContent(IOUtils.toString(response.getEntity().getContent()));
} finally {
if (response != null) {
response.close();
}
httpClient.close();
}
return simpleResponse;
}
Aggregations