use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class HttpClientSingleton method createHttpClient.
/**
* Creates an {@link OkHttpClient} instance with a new {@link WatsonCookieJar}.
*
* @return the client
*/
public OkHttpClient createHttpClient() {
Builder builder = okHttpClient.newBuilder();
addCookieJar(builder);
return builder.build();
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class HttpClientSingleton method configureHttpClient.
/**
* Configures the HTTP client.
*
* @return the HTTP client
*/
private OkHttpClient configureHttpClient() {
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
addCookieJar(builder);
builder.connectTimeout(60, TimeUnit.SECONDS);
builder.writeTimeout(60, TimeUnit.SECONDS);
builder.readTimeout(90, TimeUnit.SECONDS);
builder.addNetworkInterceptor(HttpLogging.getLoggingInterceptor());
ConnectionSpec spec = new ConnectionSpec.Builder(ConnectionSpec.MODERN_TLS).allEnabledCipherSuites().build();
builder.connectionSpecs(Arrays.asList(spec, ConnectionSpec.CLEARTEXT));
setupTLSProtocol(builder);
return builder.build();
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class WatsonService method createCall.
/**
* Execute the HTTP request. Okhttp3 compliant.
*
* @param request the HTTP request
*
* @return the HTTP response
*/
private Call createCall(final Request request) {
final Request.Builder builder = request.newBuilder();
setDefaultHeaders(builder);
setAuthentication(builder);
final Request newRequest = builder.build();
return client.newCall(newRequest);
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method getTrainingExampleIsSuccessful.
@Test
public void getTrainingExampleIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(getTrainingExampleResp));
GetTrainingExampleOptions.Builder builder = new GetTrainingExampleOptions.Builder(environmentId, collectionId, queryId, documentId);
TrainingExample response = discoveryService.getTrainingExample(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(TRAINING4_PATH, request.getPath());
assertEquals(GET, request.getMethod());
assertEquals(getTrainingExampleResp, response);
}
use of okhttp3.HttpUrl.Builder in project java-sdk by watson-developer-cloud.
the class DiscoveryServiceTest method queryNoticesIsSuccessful.
@Test
public void queryNoticesIsSuccessful() throws InterruptedException {
server.enqueue(jsonResponse(queryNoticesResp));
QueryNoticesOptions.Builder builder = new QueryNoticesOptions.Builder(environmentId, collectionId);
QueryNoticesResponse response = discoveryService.queryNotices(builder.build()).execute();
RecordedRequest request = server.takeRequest();
assertEquals(Q5_PATH, request.getPath());
assertEquals(GET, request.getMethod());
}
Aggregations