@@ -107,41 +107,26 @@ public static ClientHttpConnector create(ClientOptions options, SslConfiguration
107107 }
108108 }
109109
110- private static void configureSsl (SslConfiguration sslConfiguration , SslContextBuilder sslContextBuilder ) {
111-
112- try {
113-
114- if (sslConfiguration .getTrustStoreConfiguration ().isPresent ()) {
115- sslContextBuilder
116- .trustManager (createTrustManagerFactory (sslConfiguration .getTrustStoreConfiguration ()));
117- }
118-
119- if (sslConfiguration .getKeyStoreConfiguration ().isPresent ()) {
120- sslContextBuilder .keyManager (createKeyManagerFactory (sslConfiguration .getKeyStoreConfiguration (),
121- sslConfiguration .getKeyConfiguration ()));
122- }
123-
124- if (!sslConfiguration .getEnabledProtocols ().isEmpty ()) {
125- sslContextBuilder .protocols (sslConfiguration .getEnabledProtocols ());
126- }
127-
128- if (!sslConfiguration .getEnabledCipherSuites ().isEmpty ()) {
129- sslContextBuilder .ciphers (sslConfiguration .getEnabledCipherSuites ());
130- }
131- }
132- catch (GeneralSecurityException | IOException e ) {
133- throw new IllegalStateException (e );
134- }
135- }
136-
137110 /**
138111 * {@link ClientHttpConnector} for Reactor Netty.
139112 *
140113 * @author Mark Paluch
141114 */
142- static class ReactorNetty {
115+ public static class ReactorNetty {
116+
117+ /**
118+ * Create a {@link ClientHttpConnector} using Reactor Netty.
119+ * @param options must not be {@literal null}
120+ * @param sslConfiguration must not be {@literal null}
121+ * @return a new and configured {@link ReactorClientHttpConnector} instance.
122+ */
123+ public static ReactorClientHttpConnector usingReactorNetty (ClientOptions options ,
124+ SslConfiguration sslConfiguration ) {
125+ return new ReactorClientHttpConnector (createClient (options , sslConfiguration ));
126+ }
127+
128+ public static HttpClient createClient (ClientOptions options , SslConfiguration sslConfiguration ) {
143129
144- static ClientHttpConnector usingReactorNetty (ClientOptions options , SslConfiguration sslConfiguration ) {
145130 HttpClient client = HttpClient .create ();
146131
147132 if (hasSslConfiguration (sslConfiguration )) {
@@ -155,20 +140,65 @@ static ClientHttpConnector usingReactorNetty(ClientOptions options, SslConfigura
155140 client = client .option (ChannelOption .CONNECT_TIMEOUT_MILLIS ,
156141 Math .toIntExact (options .getConnectionTimeout ().toMillis ())).proxyWithSystemProperties ();
157142
158- return new ReactorClientHttpConnector (client );
143+ return client ;
144+ }
145+
146+ private static void configureSsl (SslConfiguration sslConfiguration , SslContextBuilder sslContextBuilder ) {
147+
148+ try {
149+
150+ if (sslConfiguration .getTrustStoreConfiguration ().isPresent ()) {
151+ sslContextBuilder
152+ .trustManager (createTrustManagerFactory (sslConfiguration .getTrustStoreConfiguration ()));
153+ }
154+
155+ if (sslConfiguration .getKeyStoreConfiguration ().isPresent ()) {
156+ sslContextBuilder .keyManager (createKeyManagerFactory (sslConfiguration .getKeyStoreConfiguration (),
157+ sslConfiguration .getKeyConfiguration ()));
158+ }
159+
160+ if (!sslConfiguration .getEnabledProtocols ().isEmpty ()) {
161+ sslContextBuilder .protocols (sslConfiguration .getEnabledProtocols ());
162+ }
163+
164+ if (!sslConfiguration .getEnabledCipherSuites ().isEmpty ()) {
165+ sslContextBuilder .ciphers (sslConfiguration .getEnabledCipherSuites ());
166+ }
167+ }
168+ catch (GeneralSecurityException | IOException e ) {
169+ throw new IllegalStateException (e );
170+ }
159171 }
160172
161173 }
162174
163175 /**
164- * {@link ClientHttpRequestFactory} for Apache Http Components.
176+ * Utility methods to create {@link ClientHttpRequestFactory} using Apache Http
177+ * Components.
165178 *
166179 * @author Mark Paluch
167180 */
168- static class HttpComponents {
181+ public static class HttpComponents {
182+
183+ /**
184+ * Create a {@link ClientHttpConnector} using Apache Http Components.
185+ * @param options must not be {@literal null}
186+ * @param sslConfiguration must not be {@literal null}
187+ * @return a new and configured {@link HttpComponentsClientHttpConnector}
188+ * instance.
189+ * @throws GeneralSecurityException
190+ * @throws IOException
191+ */
192+ public static HttpComponentsClientHttpConnector usingHttpComponents (ClientOptions options ,
193+ SslConfiguration sslConfiguration ) throws GeneralSecurityException , IOException {
194+
195+ HttpAsyncClientBuilder httpClientBuilder = createHttpAsyncClientBuilder (options , sslConfiguration );
169196
170- static ClientHttpConnector usingHttpComponents (ClientOptions options , SslConfiguration sslConfiguration )
171- throws GeneralSecurityException , IOException {
197+ return new HttpComponentsClientHttpConnector (httpClientBuilder .build ());
198+ }
199+
200+ public static HttpAsyncClientBuilder createHttpAsyncClientBuilder (ClientOptions options ,
201+ SslConfiguration sslConfiguration ) throws GeneralSecurityException , IOException {
172202
173203 HttpAsyncClientBuilder httpClientBuilder = HttpAsyncClientBuilder .create ();
174204
@@ -177,7 +207,7 @@ static ClientHttpConnector usingHttpComponents(ClientOptions options, SslConfigu
177207
178208 if (hasSslConfiguration (sslConfiguration )) {
179209
180- SSLContext sslContext = getSSLContext (sslConfiguration , getTrustManagers ( sslConfiguration ) );
210+ SSLContext sslContext = getSSLContext (sslConfiguration );
181211
182212 String [] enabledProtocols = !sslConfiguration .getEnabledProtocols ().isEmpty ()
183213 ? sslConfiguration .getEnabledProtocols ().toArray (new String [0 ]) : null ;
@@ -210,24 +240,32 @@ static ClientHttpConnector usingHttpComponents(ClientOptions options, SslConfigu
210240
211241 httpClientBuilder .setDefaultRequestConfig (requestConfig );
212242
213- return new HttpComponentsClientHttpConnector ( httpClientBuilder . build ()) ;
243+ return httpClientBuilder ;
214244 }
215245
216246 }
217247
218- static class JettyClient {
219-
220- static ClientHttpConnector usingJetty (ClientOptions options , SslConfiguration sslConfiguration ) {
221-
222- try {
223- return new JettyClientHttpConnector (configureClient (getHttpClient (sslConfiguration ), options ));
224- }
225- catch (GeneralSecurityException | IOException e ) {
226- throw new IllegalStateException (e );
227- }
248+ /**
249+ * Utility methods to create {@link ClientHttpRequestFactory} using the Jetty Client.
250+ *
251+ * @author Mark Paluch
252+ */
253+ public static class JettyClient {
254+
255+ /**
256+ * Create a {@link ClientHttpConnector} using Jetty.
257+ * @param options must not be {@literal null}
258+ * @param sslConfiguration must not be {@literal null}
259+ * @return a new and configured {@link JettyClientHttpConnector} instance.
260+ * @throws GeneralSecurityException
261+ * @throws IOException
262+ */
263+ public static JettyClientHttpConnector usingJetty (ClientOptions options , SslConfiguration sslConfiguration )
264+ throws GeneralSecurityException , IOException {
265+ return new JettyClientHttpConnector (configureClient (getHttpClient (sslConfiguration ), options ));
228266 }
229267
230- private static org .eclipse .jetty .client .HttpClient configureClient (
268+ public static org .eclipse .jetty .client .HttpClient configureClient (
231269 org .eclipse .jetty .client .HttpClient httpClient , ClientOptions options ) {
232270
233271 httpClient .setConnectTimeout (options .getConnectionTimeout ().toMillis ());
@@ -236,7 +274,7 @@ private static org.eclipse.jetty.client.HttpClient configureClient(
236274 return httpClient ;
237275 }
238276
239- private static org .eclipse .jetty .client .HttpClient getHttpClient (SslConfiguration sslConfiguration )
277+ public static org .eclipse .jetty .client .HttpClient getHttpClient (SslConfiguration sslConfiguration )
240278 throws IOException , GeneralSecurityException {
241279
242280 if (hasSslConfiguration (sslConfiguration )) {
@@ -291,34 +329,39 @@ private static org.eclipse.jetty.client.HttpClient getHttpClient(SslConfiguratio
291329 *
292330 * @author Mark Paluch
293331 */
294- static class JdkHttpClient {
332+ public static class JdkHttpClient {
295333
296- static ClientHttpConnector usingJdkHttpClient (ClientOptions options , SslConfiguration sslConfiguration )
297- throws GeneralSecurityException , IOException {
334+ /**
335+ * Create a {@link JdkClientHttpConnector} using the JDK's HttpClient.
336+ * @param options must not be {@literal null}
337+ * @param sslConfiguration must not be {@literal null}
338+ * @return a new and configured {@link JdkClientHttpConnector} instance.
339+ * @throws GeneralSecurityException
340+ * @throws IOException
341+ */
342+ public static JdkClientHttpConnector usingJdkHttpClient (ClientOptions options ,
343+ SslConfiguration sslConfiguration ) throws GeneralSecurityException , IOException {
344+
345+ java .net .http .HttpClient .Builder builder = getBuilder (options , sslConfiguration );
346+
347+ return new JdkClientHttpConnector (builder .build ());
348+ }
349+
350+ public static java .net .http .HttpClient .Builder getBuilder (ClientOptions options ,
351+ SslConfiguration sslConfiguration ) throws GeneralSecurityException , IOException {
298352
299353 java .net .http .HttpClient .Builder builder = java .net .http .HttpClient .newBuilder ();
300354
301355 if (hasSslConfiguration (sslConfiguration )) {
302356
303- SSLContext sslContext = getSSLContext (sslConfiguration , getTrustManagers ( sslConfiguration ) );
357+ SSLContext sslContext = getSSLContext (sslConfiguration );
304358
305359 String [] enabledProtocols = !sslConfiguration .getEnabledProtocols ().isEmpty ()
306360 ? sslConfiguration .getEnabledProtocols ().toArray (new String [0 ]) : null ;
307361
308362 String [] enabledCipherSuites = !sslConfiguration .getEnabledCipherSuites ().isEmpty ()
309363 ? sslConfiguration .getEnabledCipherSuites ().toArray (new String [0 ]) : null ;
310364
311- BasicClientTlsStrategy tlsStrategy = new BasicClientTlsStrategy (sslContext , (endpoint , sslEngine ) -> {
312-
313- if (enabledProtocols != null ) {
314- sslEngine .setEnabledProtocols (enabledProtocols );
315- }
316-
317- if (enabledCipherSuites != null ) {
318- sslEngine .setEnabledCipherSuites (enabledCipherSuites );
319- }
320- }, null );
321-
322365 SSLParameters parameters = new SSLParameters ();
323366 parameters .setProtocols (enabledProtocols );
324367 parameters .setCipherSuites (enabledCipherSuites );
@@ -328,8 +371,7 @@ static ClientHttpConnector usingJdkHttpClient(ClientOptions options, SslConfigur
328371
329372 builder .proxy (ProxySelector .getDefault ()).followRedirects (java .net .http .HttpClient .Redirect .ALWAYS )
330373 .connectTimeout (options .getConnectionTimeout ());
331-
332- return new JdkClientHttpConnector (builder .build ());
374+ return builder ;
333375 }
334376
335377 }
0 commit comments