Skip to content

Commit 8bf46fa

Browse files
Add Proxy example
1 parent 1f70ac0 commit 8bf46fa

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
3737
* [Visual Recognition](visual-recognition)
3838
* [Reactive API call for v3.0.1](#introduce-reactive-api-call-for-v301)
3939
* [Breaking Changes for v3.0](#breaking-changes-for-v30)
40+
* [Using a Proxy](#using-a-proxy)
4041
* [Android](#android)
4142
* [Running in Bluemix](#running-in-bluemix)
4243
* [Default Headers](#default-headers)
@@ -193,16 +194,19 @@ The version 3.0 is a major release focused on simplicity and consistency. Severa
193194
### Synchronous vs. Asynchronous
194195

195196
Before 3.0 all the API calls were synchronous.
197+
196198
```java
197199
List<Dialog> dialogs = dialogService.getDialogs();
198200
System.out.println(dialogs);
199201
```
202+
200203
To do a synchronous call, you need to add `execute()`.
201204

202205
```java
203206
List<Dialog> dialogs = dialogService.getDialogs().execute();
204207
System.out.println(dialogs);
205208
```
209+
206210
To do an asynchronous call, you need to specify a callback.
207211

208212
```java
@@ -224,10 +228,12 @@ See the [CHANGELOG](CHANGELOG.md) for the release notes.
224228

225229
To migrate to 3.0 from a previous version, simply add `.execute()` to the old methods.
226230
For example if you previously had
231+
227232
```java
228233
List<Dialog> dialogs = dialogService.getDialogs();
229234
System.out.println(dialogs);
230235
```
236+
231237
Just add `execute()` on the end, and your code will work exactly the same as before.
232238

233239
```java
@@ -236,8 +242,32 @@ System.out.println(dialogs);
236242
```
237243

238244
## Android
245+
239246
The Android SDK utilizes the Java SDK while making some Android-specific additions. This repository can be found [here](https://github.com/watson-developer-cloud/android-sdk). It depends on [OkHttp][] and [gson][].
240247

248+
## Using a Proxy
249+
250+
Override the `configureHttpClient()` method and add the proxy using the `OkHttpClient.Builder` object.
251+
252+
For example:
253+
254+
```java
255+
ConversationService service = new ConversationService("2017-05-26") {
256+
@Override
257+
protected OkHttpClient configureHttpClient() {
258+
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("proxyHost", 8080));
259+
return super.configureHttpClient().newBuilder().proxy(proxy).build();
260+
}
261+
};
262+
263+
service.setUsernameAndPassword("<username>", "<password>");
264+
265+
WorkspaceCollectionResponse workspaces = service.listWorkspaces(null, null, null, null).execute();
266+
System.out.println(workspaces);
267+
```
268+
269+
For more information see: [OkHTTPClient Proxy authentication how to?](https://stackoverflow.com/a/35567936/456564)
270+
241271
## Running in Bluemix
242272

243273
When running in Bluemix, the library will automatically get the credentials from `VCAP_SERVICES`.
@@ -280,10 +310,9 @@ service.sentEndPoint("https://gateway-fra.watsonplatform.net/conversation/api")
280310
```
281311

282312
## 401 Unauthorized error
283-
Make sure you are using the service credentials and not your Bluemix account/password.
284-
285-
Check the API Endpoint, you may need to update the default using setEndPoint().
286313

314+
Make sure you are using the service credentials and not your Bluemix account/password.
315+
Check the API Endpoint, you may need to update the default using `setEndPoint()`.
287316

288317
## Debug
289318

0 commit comments

Comments
 (0)