Skip to content

Commit 53ea7db

Browse files
authored
Merge pull request #1082 from watson-developer-cloud/v8-rc1
V8 rc1
2 parents 31a23f4 + b667b16 commit 53ea7db

File tree

660 files changed

+13875
-7608
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

660 files changed

+13875
-7608
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 7.4.0
2+
current_version = 8.0.0-rc1
33
commit = True
44
message = Update version numbers from {current_version} -> {new_version}
55

.travis.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ script:
5151
after_success:
5252
- bash <(curl -s https://codecov.io/bash)
5353
deploy:
54-
- provider: script
55-
skip_cleanup: true
56-
script: "semantic-release"
57-
on:
58-
branch: master
59-
jdk: openjdk7
54+
#- provider: script
55+
#skip_cleanup: true
56+
#script: "semantic-release"
57+
#on:
58+
#branch: master
59+
#jdk: openjdk7
6060
- provider: script
6161
script: ".utility/push-javadoc-to-gh-pages.sh"
6262
skip_cleanup: true

.utility/push-javadoc-to-gh-pages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" ]; then
1111
rm -rf docs/$TRAVIS_BRANCH
1212
mkdir -p docs/$TRAVIS_BRANCH
1313
cp -rf ../build/docs/all/* docs/$TRAVIS_BRANCH
14-
generate-index-html.sh > index.html
14+
./generate-index-html.sh > index.html
1515

1616
# update the latest/ symlink
1717
# on tagged builds, $TRAVIS_TAG is set to the tag, but it's blank on regular builds, unlike $TRAVIS_BRANCH

README.md

Lines changed: 84 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ Java client library to use the [Watson APIs][wdc].
2121
* [IAM](#iam)
2222
* [Username and password](#username-and-password)
2323
* [ICP](#icp)
24+
* [Cloud Pak for Data](#cloud-pak-for-data)
2425
* [Using the SDK](#using-the-sdk)
2526
* [Parsing responses](#parsing-responses)
2627
* [Configuring the HTTP client](#configuring-the-http-client)
2728
* [Making asynchronous API calls](#making-asynchronous-api-calls)
2829
* [Default headers](#default-headers)
2930
* [Sending request headers](#sending-request-headers)
31+
* [Canceling requests](#canceling-requests)
3032
* [FAQ](#faq)
3133
* IBM Watson Services
3234
* [Assistant](assistant)
@@ -62,7 +64,7 @@ All the services:
6264
<dependency>
6365
<groupId>com.ibm.watson</groupId>
6466
<artifactId>ibm-watson</artifactId>
65-
<version>7.4.0</version>
67+
<version>8.0.0-rc1</version>
6668
</dependency>
6769
```
6870

@@ -72,21 +74,21 @@ Only Discovery:
7274
<dependency>
7375
<groupId>com.ibm.watson</groupId>
7476
<artifactId>discovery</artifactId>
75-
<version>7.4.0</version>
77+
<version>8.0.0-rc1</version>
7678
</dependency>
7779
```
7880

7981
##### Gradle
8082
All the services:
8183

8284
```gradle
83-
'com.ibm.watson:ibm-watson:7.4.0'
85+
'com.ibm.watson:ibm-watson:8.0.0-rc1'
8486
```
8587

8688
Only Assistant:
8789

8890
```gradle
89-
'com.ibm.watson:assistant:7.4.0'
91+
'com.ibm.watson:assistant:8.0.0-rc1'
9092
```
9193

9294
##### JAR
@@ -114,7 +116,7 @@ Watson services are migrating to token-based Identity and Access Management (IAM
114116

115117
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
116118
- 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).
118120

119121
### Getting credentials
120122

@@ -170,68 +172,70 @@ Some services use token-based Identity and Access Management (IAM) authenticatio
170172
You supply either an IAM service **API key** or an **access token**:
171173

172174
- 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).
174176

175177

176178
Supplying the IAM API key:
177179

178180
```java
179181
// letting the SDK manage the IAM token
180-
IamOptions options = new IamOptions.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 = new Discovery("2017-11-07", options);
182+
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
183+
Discovery service = new Discovery("2017-11-07", authenticator);
185184
```
186185

187186
Supplying the access token:
188187

189188
```java
190189
// assuming control of managing IAM token
191-
IamOptions options = new IamOptions.Builder()
192-
.accessToken("<access_token>")
193-
.build();
194-
Discovery service = new Discovery("2017-11-07", options);
190+
Authenticator authenticator = new BearerTokenAuthenticator("<access_token>");
191+
Discovery service = new Discovery("2017-11-07", authenticator);
195192
```
196193

197194
#### Username and password
198195

199196
```java
200-
// in the constructor
201-
BasicAuthConfig config = new BasicAuthConfig.Builder()
202-
.username("<username>")
203-
.password("<password")
204-
.build();
205-
Discovery service = new Discovery("2017-11-07", config);
197+
Authenticator authenticator = new BasicAuthenticator("<username>", "<password>");
198+
Discovery service = new Discovery("2017-11-07", authenticator);
206199
```
207200

208201
#### 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.
203+
204+
```java
205+
Authenticator authenticator = new BasicAuthenticator("<username>", "<password>");
206+
Discovery service = new Discovery("2017-11-07", authenticator);
207+
208+
HttpConfigOptions options = new HttpConfigOptions.Builder()
209+
.disableSslVerification(true)
210+
.build();
211+
212+
service.configureClient(options);
213+
```
214+
215+
#### Cloud Pak for Data
209216
Like IAM, you can pass in credentials to let the SDK manage an access token for you or directly supply an access token to do it yourself.
210217

211218
```java
212219
// letting the SDK manage the token
213-
ICP4DConfig config = new ICP4DConfig.Builder()
214-
.url("<ICP token exchange base URL>")
215-
.username("<username>")
216-
.password("<password>")
217-
.disableSSLVerification(true)
218-
.build();
219-
Discovery service = new Discovery("2017-11-07", config);
220-
service.setEndPoint("<service ICP URL>");
220+
Authenticator authenticator = new CloudPakForDataAuthenticator(
221+
"<CP4D token exchange base URL>",
222+
"<username>",
223+
"<password>",
224+
true, // disabling SSL verification
225+
null,
226+
);
227+
Discovery service = new Discovery("2017-11-07", authenticator);
228+
service.setEndPoint("<service CP4D URL>");
221229
```
222230

223231
```java
224232
// assuming control of managing the access token
225-
ICP4DConfig config = new ICP4DConfig.Builder()
226-
.url("<ICP token exchange base URL>")
227-
.userManagedAccessToken("<access token>")
228-
.disableSSLVerification(true)
229-
.build();
230-
Discovery service = new Discovery("2017-11-07", config);
231-
service.setEndPoint("<service ICP URL>");
233+
Authenticator authenticator = new BearerTokenAuthenticator("<access_token>");
234+
Discovery service = new Discovery("2017-11-07", authenticator);
235+
service.setEndPoint("<service CP4D URL>");
232236
```
233237

234-
Be sure to both disable SSL verification when authenticating and set the endpoint explicitly to the URL given in ICP.
238+
Be sure to both disable SSL verification when authenticating and set the endpoint explicitly to the URL given in Cloud Pak for Data.
235239

236240
## Using the SDK
237241

@@ -259,8 +263,9 @@ System.out.println("Response header names: " + responseHeaders.names());
259263
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:
260264
- Disabling SSL verification (only do this if you really mean to!) ⚠️
261265
- Using a proxy (more info here: [OkHTTPClient Proxy authentication how to?](https://stackoverflow.com/a/35567936/456564))
266+
- Setting HTTP logging verbosity
262267

263-
Here's an example of setting both of the above:
268+
Here's an example of setting the above:
264269

265270
```java
266271
Discovery service = new Discovery("2017-11-07");
@@ -269,6 +274,7 @@ Discovery service = new Discovery("2017-11-07");
269274
HttpConfigOptions options = new HttpConfigOptions.Builder()
270275
.disableSslVerification(true)
271276
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", 8080)))
277+
.loggingLevel(HttpConfigOptions.LoggingLevel.BASIC)
272278
.build();
273279

274280
service.configureClient(options);
@@ -329,7 +335,7 @@ Default headers can be specified at any time by using the `setDefaultHeaders(Map
329335
The example below sends the `X-Watson-Learning-Opt-Out` header in every request preventing Watson from using the payload to improve the service.
330336

331337
```java
332-
PersonalityInsights service = new PersonalityInsights("2016-10-19");
338+
PersonalityInsights service = new PersonalityInsights("2016-10-19", new NoAuthAuthenticator());
333339

334340
Map<String, String> headers = new HashMap<String, String>();
335341
headers.put(WatsonHttpHeaders.X_WATSON_LEARNING_OPT_OUT, "true");
@@ -349,6 +355,44 @@ Response<WorkspaceCollection> workspaces = service.listWorkspaces()
349355
.execute();
350356
```
351357

358+
### Canceling requests
359+
360+
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
367+
ServiceCall<WorkspaceCollection> call = service.listWorkspaces();
368+
369+
long startTime = System.currentTimeMillis();
370+
call.enqueue(new ServiceCallback<WorkspaceCollection>() {
371+
@Override
372+
public void onResponse(Response<WorkspaceCollection> response) {
373+
// store the result somewhere
374+
fakeDb.store("my-key", response.getResult());
375+
}
376+
377+
@Override
378+
public void onFailure(Exception e) {
379+
System.out.println("The request failed :(");
380+
}
381+
});
382+
383+
// 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+
352396
## FAQ
353397

354398
### Does this SDK play well with Android?
@@ -407,7 +451,7 @@ We do :sunglasses: http://ibm.github.io/
407451
## Featured projects
408452
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.
409453

410-
[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-7.4.0/ibm-watson-7.4.0-jar-with-dependencies.jar
454+
[jar]: https://github.com/watson-developer-cloud/java-sdk/releases/download/java-sdk-8.0.0-rc1/ibm-watson-8.0.0-rc1-jar-with-dependencies.jar
411455

412456
## Contributors ✨
413457

assistant/README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
<dependency>
88
<groupId>com.ibm.watson</groupId>
99
<artifactId>assistant</artifactId>
10-
<version>7.4.0</version>
10+
<version>8.0.0-rc1</version>
1111
</dependency>
1212
```
1313

1414
##### Gradle
1515
```gradle
16-
'com.ibm.watson:assistant:7.4.0'
16+
'com.ibm.watson:assistant:8.0.0-rc1'
1717
```
1818

1919
## Usage
@@ -24,11 +24,8 @@ Use the [Assistant][assistant] service to identify intents, entities, and conduc
2424
// make sure to use the Assistant v1 import!
2525
import com.ibm.watson.assistant.v1.Assistant;
2626

27-
Assistant service = new Assistant("2018-02-16");
28-
IamOptions options = new IamOptions.Builder()
29-
.apiKey("<iam_api_key>")
30-
.build();
31-
service.setIamCredentials(options);
27+
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
28+
Assistant service = new Assistant("2018-02-16", authenticator);
3229

3330
MessageInput input = new MessageInput();
3431
input.setText("Hi");
@@ -78,11 +75,8 @@ System.out.println(response);
7875
// make sure to use the Assistant v2 import!
7976
import com.ibm.watson.assistant.v2.Assistant;
8077

81-
Assistant service = new Assistant("2018-09-20");
82-
IamOptions options = new IamOptions.Builder()
83-
.apiKey("<iam_api_key>")
84-
.build();
85-
service.setIamCredentials(options);
78+
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
79+
Assistant service = new Assistant("2018-09-20", authenticator);
8680

8781
MessageInput input = new MessageInput.Builder()
8882
.text("Hi")

assistant/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ checkstyle {
6060
dependencies {
6161
compile project(':common')
6262
testCompile project(':common').sourceSets.test.output
63-
compile 'com.ibm.cloud:sdk-core:4.5.0'
63+
compile 'com.ibm.cloud:sdk-core:7.0.0-rc1'
6464
signature 'org.codehaus.mojo.signature:java17:1.0@signature'
6565
}
6666

0 commit comments

Comments
 (0)