+ * Once the first GET request is completed, + * all subsequent requests work without error. + *
+ * BUG 5749
+ */
+public class ConcurrentHttpsUrlConnectionTest {
+ private static int THREAD_NUMBER = 5;
+
+ private static volatile int responseCounter = 0;
+
+ private static SSLContext createContext() throws Exception {
+ URL url = ConcurrentHttpsUrlConnectionTest.class.getResource("keystore.jks");
+ KeyStore keyStore = KeyStore.getInstance("JKS");
+ try (InputStream is = url.openStream()) {
+ keyStore.load(is, "password".toCharArray());
+ }
+ KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
+ kmf.init(keyStore, "password".toCharArray());
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
+ tmf.init(keyStore);
+ SSLContext context = SSLContext.getInstance("TLS");
+ context.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
+ return context;
+ }
+
+ @Test
+ public void testSSLConnections() throws Exception {
+ if (THREAD_NUMBER == 1) {
+ System.out.println("\nThis is the working case (THREAD_NUMBER==1). Set THREAD_NUMBER > 1 to reproduce the error! \n");
+ }
+
+ final HttpsServer server = new HttpsServer(createContext());
+ Executors.newFixedThreadPool(1).submit(server);
+
+ // set THREAD_NUMBER > 1 to reproduce an issue
+ ExecutorService executorService2clients = Executors.newFixedThreadPool(THREAD_NUMBER);
+
+ final ClientBuilder builder = ClientBuilder.newBuilder().sslContext(createContext())
+ .hostnameVerifier(new HostnameVerifier() {
+ public boolean verify(String arg0, SSLSession arg1) {
+ return true;
+ }
+ });
+
+ AtomicInteger counter = new AtomicInteger(0);
+
+ for (int i = 0; i < THREAD_NUMBER; i++) {
+ executorService2clients.submit(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ Client client = builder.build();
+ String ret = client.target("https://127.0.0.1:" + server.getPort() + "/" + new Random().nextInt())
+ .request(MediaType.TEXT_HTML)
+ .get(new GenericType