52
52
import okhttp3 .Request .Builder ;
53
53
import okhttp3 .Response ;
54
54
55
+ import javax .net .ssl .SSLHandshakeException ;
56
+
55
57
/**
56
58
* Abstracts common functionality of various IBM Cloud services.
57
59
*/
@@ -62,6 +64,10 @@ public abstract class BaseService {
62
64
private static final Logger LOG = Logger .getLogger (BaseService .class .getName ());
63
65
64
66
private static final String ERRORMSG_NO_AUTHENTICATOR = "Authentication information was not properly configured." ;
67
+ private static final String ERRORMSG_SSL = "If you're trying to call a service on ICP or Cloud Pak for Data, you "
68
+ + "may not have a valid SSL certificate. If you need to access the service without setting that up, try using "
69
+ + "the disableSsl option in your authentication configuration and/or the disableSslVerification option in the "
70
+ + "HttpConfigOptions." ;
65
71
66
72
private String serviceUrl ;
67
73
private final String name ;
@@ -407,6 +413,9 @@ public com.ibm.cloud.sdk.core.http.Response<T> execute() {
407
413
T responseModel = processServiceCall (converter , response );
408
414
return new com .ibm .cloud .sdk .core .http .Response <>(responseModel , response );
409
415
} catch (IOException e ) {
416
+ if (e instanceof SSLHandshakeException ) {
417
+ LOG .warning (ERRORMSG_SSL );
418
+ }
410
419
throw new RuntimeException (e );
411
420
}
412
421
}
@@ -416,6 +425,9 @@ public void enqueue(final ServiceCallback<T> callback) {
416
425
call .enqueue (new Callback () {
417
426
@ Override
418
427
public void onFailure (Call call , IOException e ) {
428
+ if (e instanceof SSLHandshakeException ) {
429
+ LOG .warning (ERRORMSG_SSL );
430
+ }
419
431
callback .onFailure (e );
420
432
}
421
433
@@ -435,10 +447,17 @@ public void onResponse(Call call, Response response) {
435
447
public Single <com .ibm .cloud .sdk .core .http .Response <T >> reactiveRequest () {
436
448
return Single .fromCallable (new Callable <com .ibm .cloud .sdk .core .http .Response <T >>() {
437
449
@ Override
438
- public com .ibm .cloud .sdk .core .http .Response <T > call () throws Exception {
439
- Response response = call .execute ();
440
- T responseModel = processServiceCall (converter , response );
441
- return new com .ibm .cloud .sdk .core .http .Response <>(responseModel , response );
450
+ public com .ibm .cloud .sdk .core .http .Response <T > call () {
451
+ try {
452
+ Response response = call .execute ();
453
+ T responseModel = processServiceCall (converter , response );
454
+ return new com .ibm .cloud .sdk .core .http .Response <>(responseModel , response );
455
+ } catch (IOException e ) {
456
+ if (e instanceof SSLHandshakeException ) {
457
+ LOG .warning (ERRORMSG_SSL );
458
+ }
459
+ throw new RuntimeException (e );
460
+ }
442
461
}
443
462
});
444
463
}
0 commit comments