HttpDriver implements Closeable { @Override public void close() throws IOException { if (client != null) { try { this.client.close(); LOGGER.info("Successfully closed httpclient."); } catch (IOException ignored) { } } if (connManager != null) { connManager.close(); LOGGER.info("Successfully closed httpclient connection manager."); } } HttpDriver(Builder builder); void setHttpClient(CloseableHttpClient httpClient); static SSLContext createSSLContext(String trustorePath, char[] trustorePassword, String certPath,
                                          String keyPath); @Override void close(); String doGet(final String url); String doPost(HttpPost httpPost); String doPost(final String url, final List<NameValuePair> fields);  }
@Test public void testDriverInit() throws IOException { String caCertFile = classLoader.getResource("driver.truststore.jks").getFile(); String certFile = classLoader.getResource("driver.cert.pem").getFile(); String keyFile = classLoader.getResource("unit_test_driver.key.pem").getFile(); HttpDriver httpDriver = new HttpDriver.Builder("", caCertFile, "123456".toCharArray(), certFile, keyFile) .maxPoolPerRoute(20) .maxPoolTotal(30) .clientRetryIntervalMs(5000) .clientMaxRetries(2) .clientConnectTimeoutMs(5000) .clientReadTimeoutMs(5000) .build(); httpDriver.close(); }
@Test public void testClose() throws IOException { CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class); HttpDriver httpDriver = new HttpDriver.Builder("", null, "asdf".toCharArray(), null, null) .build(); httpDriver.setHttpClient(httpClient); httpDriver.close(); httpDriver.setHttpClient(null); httpDriver.close(); }