You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -114,7 +116,7 @@ Watson services are migrating to token-based Identity and Access Management (IAM
114
116
115
117
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
116
118
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
117
-
- If you're using a Watson service on ICP, you'll need to authenticate in a [specific way](#icp).
119
+
- If you're using a Watson service on Cloud Pak for Data, you'll need to authenticate in a [specific way](#cloud-pak-for-data).
118
120
119
121
### Getting credentials
120
122
@@ -170,68 +172,70 @@ Some services use token-based Identity and Access Management (IAM) authenticatio
170
172
You supply either an IAM service **API key** or an **access token**:
171
173
172
174
- Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
173
-
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://cloud.ibm.com/docs/services/watson/getting-started-iam.html). If you want to switch to API key, override your stored IAM credentials with an IAM API key. Then call the `setIamCredentials()` method again.
175
+
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://cloud.ibm.com/docs/services/watson/getting-started-iam.html).
174
176
175
177
176
178
Supplying the IAM API key:
177
179
178
180
```java
179
181
// letting the SDK manage the IAM token
180
-
IamOptions options =newIamOptions.Builder()
181
-
.apiKey("<iam_api_key>")
182
-
.url("<iam_url>") // optional - the default value is https://iam.cloud.ibm.com/identity/token
183
-
.build();
184
-
Discovery service =newDiscovery("2017-11-07", options);
Discovery service =newDiscovery("2017-11-07", authenticator);
206
199
```
207
200
208
201
#### ICP
202
+
Authenticating with ICP is similar to the basic username and password method, except that you need to make sure to disable SSL verification to authenticate properly. See [here](#configuring-the-http-client) for more information.
The HTTP client can be configured by using the `configureClient()` method on your service object, passing in an `HttpConfigOptions` object. Currently, the following options are supported:
260
264
- Disabling SSL verification (only do this if you really mean to!) ⚠️
261
265
- Using a proxy (more info here: [OkHTTPClient Proxy authentication how to?](https://stackoverflow.com/a/35567936/456564))
266
+
- Setting HTTP logging verbosity
262
267
263
-
Here's an example of setting both of the above:
268
+
Here's an example of setting the above:
264
269
265
270
```java
266
271
Discovery service =newDiscovery("2017-11-07");
@@ -269,6 +274,7 @@ Discovery service = new Discovery("2017-11-07");
It's possible that you may want to cancel a request you make to a service. For example, you may set some timeout threshold and just want to cancel an asynchronous if it doesn't respond in time. You can do that by calling the `cancel()` method on your `ServiceCall` object. For example:
361
+
362
+
```java
363
+
// time to consider timeout (in ms)
364
+
long timeoutThreshold =3000;
365
+
366
+
// storing ServiceCall object we'll use to list our Assistant v1 workspaces
// keep waiting for the call to complete while we're within the timeout bounds
384
+
while ((fakeDb.retrieve("my-key") ==null) && (System.currentTimeMillis() - startTime < timeoutThreshold)) {
385
+
Thread.sleep(500);
386
+
}
387
+
388
+
// if we timed out and it's STILL not complete, we'll just cancel the call
389
+
if (fakeDb.retrieve("my-key") ==null) {
390
+
call.cancel();
391
+
}
392
+
```
393
+
394
+
Doing so will call your `onFailure()` implementation.
395
+
352
396
## FAQ
353
397
354
398
### Does this SDK play well with Android?
@@ -407,7 +451,7 @@ We do :sunglasses: http://ibm.github.io/
407
451
## Featured projects
408
452
We'd love to highlight cool open-source projects that use this SDK! If you'd like to get your project added to the list, feel free to make an issue linking us to it.
0 commit comments