90 .build(); |
90 .build(); |
91 try { |
91 try { |
92 HttpResponse<Void> response = client.send(request, discarding()); |
92 HttpResponse<Void> response = client.send(request, discarding()); |
93 String msg = String.format("UNEXPECTED response=%s%n", response); |
93 String msg = String.format("UNEXPECTED response=%s%n", response); |
94 throw new RuntimeException(msg); |
94 throw new RuntimeException(msg); |
95 } catch (SSLHandshakeException expected) { |
95 } catch (IOException expected) { |
96 out.printf("Client: caught expected exception: %s%n", expected); |
96 out.printf("Client: caught expected exception: %s%n", expected); |
|
97 checkExceptionOrCause(SSLHandshakeException.class, expected); |
97 } |
98 } |
98 } |
99 } |
99 } |
100 } |
100 |
101 |
101 void testSyncDiffClient(URI uri, Version version) throws Exception { |
102 void testSyncDiffClient(URI uri, Version version) throws Exception { |
109 .build(); |
110 .build(); |
110 try { |
111 try { |
111 HttpResponse<Void> response = client.send(request, discarding()); |
112 HttpResponse<Void> response = client.send(request, discarding()); |
112 String msg = String.format("UNEXPECTED response=%s%n", response); |
113 String msg = String.format("UNEXPECTED response=%s%n", response); |
113 throw new RuntimeException(msg); |
114 throw new RuntimeException(msg); |
114 } catch (SSLHandshakeException expected) { |
115 } catch (IOException expected) { |
115 out.printf("Client: caught expected exception: %s%n", expected); |
116 out.printf("Client: caught expected exception: %s%n", expected); |
|
117 checkExceptionOrCause(SSLHandshakeException.class, expected); |
116 } |
118 } |
117 } |
119 } |
118 } |
120 } |
119 |
121 |
120 void testAsyncSameClient(URI uri, Version version) throws Exception { |
122 void testAsyncSameClient(URI uri, Version version) throws Exception { |
130 try { |
132 try { |
131 response.join(); |
133 response.join(); |
132 String msg = String.format("UNEXPECTED response=%s%n", response); |
134 String msg = String.format("UNEXPECTED response=%s%n", response); |
133 throw new RuntimeException(msg); |
135 throw new RuntimeException(msg); |
134 } catch (CompletionException ce) { |
136 } catch (CompletionException ce) { |
135 if (ce.getCause() instanceof SSLHandshakeException) { |
137 Throwable expected = ce.getCause(); |
136 out.printf("Client: caught expected exception: %s%n", ce.getCause()); |
138 out.printf("Client: caught expected exception: %s%n", expected); |
137 } else { |
139 checkExceptionOrCause(SSLHandshakeException.class, expected); |
138 out.printf("Client: caught UNEXPECTED exception: %s%n", ce.getCause()); |
|
139 throw ce; |
|
140 } |
|
141 } |
140 } |
142 } |
141 } |
143 } |
142 } |
144 |
143 |
145 void testAsyncDiffClient(URI uri, Version version) throws Exception { |
144 void testAsyncDiffClient(URI uri, Version version) throws Exception { |
156 try { |
155 try { |
157 response.join(); |
156 response.join(); |
158 String msg = String.format("UNEXPECTED response=%s%n", response); |
157 String msg = String.format("UNEXPECTED response=%s%n", response); |
159 throw new RuntimeException(msg); |
158 throw new RuntimeException(msg); |
160 } catch (CompletionException ce) { |
159 } catch (CompletionException ce) { |
161 if (ce.getCause() instanceof SSLHandshakeException) { |
160 ce.printStackTrace(out); |
162 out.printf("Client: caught expected exception: %s%n", ce.getCause()); |
161 Throwable expected = ce.getCause(); |
163 } else { |
162 out.printf("Client: caught expected exception: %s%n", expected); |
164 out.printf("Client: caught UNEXPECTED exception: %s%n", ce.getCause()); |
163 checkExceptionOrCause(SSLHandshakeException.class, expected); |
165 throw ce; |
164 } |
166 } |
165 } |
167 } |
166 } |
168 } |
167 |
|
168 static void checkExceptionOrCause(Class<? extends Throwable> clazz, Throwable t) { |
|
169 do { |
|
170 if (clazz.isInstance(t)) { |
|
171 System.out.println("Found expected exception/cause: " + t); |
|
172 return; // found |
|
173 } |
|
174 } while ((t = t.getCause()) != null); |
|
175 t.printStackTrace(System.out); |
|
176 throw new RuntimeException("Expected " + clazz + "in " + t); |
169 } |
177 } |
170 |
178 |
171 /** Common supertype for PlainServer and SSLServer. */ |
179 /** Common supertype for PlainServer and SSLServer. */ |
172 static abstract class AbstractServer extends Thread implements AutoCloseable { |
180 static abstract class AbstractServer extends Thread implements AutoCloseable { |
173 protected final ServerSocket ss; |
181 protected final ServerSocket ss; |