31
31
import java .util .List ;
32
32
import java .util .Map ;
33
33
import java .util .Optional ;
34
- import java .util .ServiceLoader ;
35
34
import java .util .Set ;
36
35
import java .util .concurrent .ExecutorService ;
37
36
import java .util .concurrent .Executors ;
59
58
import org .eclipse .microprofile .rest .client .ext .AsyncInvocationInterceptorFactory ;
60
59
import org .eclipse .microprofile .rest .client .ext .ResponseExceptionMapper ;
61
60
import org .eclipse .microprofile .rest .client .spi .RestClientListener ;
61
+ import org .glassfish .jersey .client .ClientConfig ;
62
62
import org .glassfish .jersey .client .Initializable ;
63
+ import org .glassfish .jersey .client .spi .ConnectorProvider ;
63
64
import org .glassfish .jersey .ext .cdi1x .internal .CdiUtil ;
65
+ import org .glassfish .jersey .internal .ServiceFinder ;
64
66
import org .glassfish .jersey .internal .inject .InjectionManager ;
65
67
import org .glassfish .jersey .internal .inject .InjectionManagerSupplier ;
66
68
import org .glassfish .jersey .internal .util .ReflectionHelper ;
@@ -92,6 +94,7 @@ class RestClientBuilderImpl implements RestClientBuilder {
92
94
private KeyStore sslTrustStore ;
93
95
private KeyStore sslKeyStore ;
94
96
private char [] sslKeyStorePassword ;
97
+ private ConnectorProvider connector ;
95
98
96
99
RestClientBuilderImpl () {
97
100
clientBuilder = ClientBuilder .newBuilder ();
@@ -142,15 +145,15 @@ public <T> T build(Class<T> interfaceClass) throws IllegalStateException, RestCl
142
145
throw new IllegalStateException ("Base uri/url cannot be null!" );
143
146
}
144
147
148
+ for (RestClientListener restClientListener : ServiceFinder .find (RestClientListener .class )) {
149
+ restClientListener .onNewClient (interfaceClass , this );
150
+ }
151
+
145
152
//Provider registration part
146
153
processProviders (interfaceClass );
147
154
InjectionManagerExposer injectionManagerExposer = new InjectionManagerExposer ();
148
155
register (injectionManagerExposer );
149
156
150
- for (RestClientListener restClientListener : ServiceLoader .load (RestClientListener .class )) {
151
- restClientListener .onNewClient (interfaceClass , this );
152
- }
153
-
154
157
//We need to check first if default exception mapper was not disabled by property on builder.
155
158
registerExceptionMapper ();
156
159
//sort all AsyncInvocationInterceptorFactory by priority
@@ -174,7 +177,16 @@ public <T> T build(Class<T> interfaceClass) throws IllegalStateException, RestCl
174
177
clientBuilder .keyStore (sslKeyStore , sslKeyStorePassword );
175
178
}
176
179
177
- Client client = clientBuilder .build ();
180
+ Client client ;
181
+ if (connector == null ) {
182
+ client = clientBuilder .build ();
183
+ } else {
184
+ ClientConfig config = new ClientConfig ();
185
+ config .loadFrom (getConfiguration ());
186
+ config .connectorProvider (connector );
187
+ client = ClientBuilder .newClient (config );
188
+ }
189
+
178
190
if (client instanceof Initializable ) {
179
191
((Initializable ) client ).preInitialize ();
180
192
}
@@ -377,7 +389,8 @@ public RestClientBuilder register(Object component, Map<Class<?>, Integer> contr
377
389
private boolean isSupportedCustomProvider (Class <?> providerClass ) {
378
390
return ResponseExceptionMapper .class .isAssignableFrom (providerClass )
379
391
|| ParamConverterProvider .class .isAssignableFrom (providerClass )
380
- || AsyncInvocationInterceptorFactory .class .isAssignableFrom (providerClass );
392
+ || AsyncInvocationInterceptorFactory .class .isAssignableFrom (providerClass )
393
+ || ConnectorProvider .class .isAssignableFrom (providerClass );
381
394
}
382
395
383
396
private void registerCustomProvider (Object instance , Integer priority ) {
@@ -399,6 +412,9 @@ private void registerCustomProvider(Object instance, Integer priority) {
399
412
.add (new AsyncInvocationInterceptorFactoryPriorityWrapper ((AsyncInvocationInterceptorFactory ) instance ,
400
413
priority ));
401
414
}
415
+ if (instance instanceof ConnectorProvider ) {
416
+ connector = (ConnectorProvider ) instance ;
417
+ }
402
418
}
403
419
404
420
private static class InjectionManagerExposer implements Feature {
0 commit comments