Search in sources :

Example 91 with Builder

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();
}
Also used : Builder(okhttp3.OkHttpClient.Builder)

Example 92 with Builder

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();
}
Also used : Builder(okhttp3.OkHttpClient.Builder) OkHttpClient(okhttp3.OkHttpClient) ConnectionSpec(okhttp3.ConnectionSpec) Builder(okhttp3.OkHttpClient.Builder)

Example 93 with Builder

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);
}
Also used : Builder(okhttp3.Request.Builder) Request(okhttp3.Request)

Example 94 with Builder

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);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) GetTrainingExampleOptions(com.ibm.watson.developer_cloud.discovery.v1.model.GetTrainingExampleOptions) TrainingExample(com.ibm.watson.developer_cloud.discovery.v1.model.TrainingExample) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Example 95 with Builder

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());
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) QueryNoticesResponse(com.ibm.watson.developer_cloud.discovery.v1.model.QueryNoticesResponse) QueryNoticesOptions(com.ibm.watson.developer_cloud.discovery.v1.model.QueryNoticesOptions) FederatedQueryNoticesOptions(com.ibm.watson.developer_cloud.discovery.v1.model.FederatedQueryNoticesOptions) WatsonServiceUnitTest(com.ibm.watson.developer_cloud.WatsonServiceUnitTest) Test(org.junit.Test)

Aggregations

Request (okhttp3.Request)206 Response (okhttp3.Response)148 OkHttpClient (okhttp3.OkHttpClient)142 IOException (java.io.IOException)111 RequestBody (okhttp3.RequestBody)81 Test (org.junit.Test)75 HttpUrl (okhttp3.HttpUrl)47 File (java.io.File)42 MockResponse (okhttp3.mockwebserver.MockResponse)42 MultipartBody (okhttp3.MultipartBody)40 Map (java.util.Map)39 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)31 Call (okhttp3.Call)29 Interceptor (okhttp3.Interceptor)29 Retrofit (retrofit2.Retrofit)29 Builder (okhttp3.OkHttpClient.Builder)26 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)25 ResponseBody (okhttp3.ResponseBody)24 HashMap (java.util.HashMap)22 FormBody (okhttp3.FormBody)21