use of okhttp3.HttpUrl in project java-sdk by watson-developer-cloud.
the class WatsonService method getToken.
/**
* Gets an authorization token that can be use to authorize API calls.
*
* @return the token
*/
public ServiceCall<String> getToken() {
HttpUrl url = HttpUrl.parse(getEndPoint()).newBuilder().setPathSegment(0, AUTHORIZATION).addPathSegment(PATH_AUTHORIZATION_V1_TOKEN).build();
Request request = RequestBuilder.get(url).header(HttpHeaders.ACCEPT, HttpMediaType.TEXT_PLAIN).query(URL, getEndPoint()).build();
return createServiceCall(request, ResponseConverterUtils.getString());
}
use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.
the class EnqueueResourcesMockWebServerITest method multipleRequests.
@Test
public void multipleRequests() throws IOException {
OkHttpClient client = new OkHttpClient.Builder().build();
HttpUrl url = server.getServer().url("/");
Request request = new Request.Builder().get().url(url).build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
assertEquals("Hi", response.body().string());
response = client.newCall(request).execute();
assertEquals(500, response.code());
assertEquals("Fail", response.body().string());
}
use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.
the class EnqueueResourcesMockWebServerITest method singleRequest.
@Test
public void singleRequest() throws IOException {
OkHttpClient client = new OkHttpClient.Builder().build();
HttpUrl url = server.getServer().url("/");
Request request = new Request.Builder().get().url(url).build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
assertEquals("Hi", response.body().string());
}
use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.
the class EnqueueResourcesMockWebServerITest method enqueueRequestsRelative.
@Test
@EnqueueRequests("body-relative")
public void enqueueRequestsRelative() throws Exception {
OkHttpClient client = new OkHttpClient.Builder().build();
HttpUrl url = server.getServer().url("/");
Request request = new Request.Builder().get().url(url).build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
assertEquals("body-relative", response.body().string());
}
use of okhttp3.HttpUrl in project pivotal-cla by pivotalsoftware.
the class EnqueueResourcesMockWebServerITest method enqueueRequestsAbsolute.
@Test
@EnqueueRequests("/okhttp3/mockwebserver/EnqueueResourcesMockWebServerITest_resource/body-absolute")
public void enqueueRequestsAbsolute() throws Exception {
OkHttpClient client = new OkHttpClient.Builder().build();
HttpUrl url = server.getServer().url("/");
Request request = new Request.Builder().get().url(url).build();
Response response = client.newCall(request).execute();
assertEquals(200, response.code());
assertEquals("body-absolute", response.body().string());
}
Aggregations