use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpCallResponseBuilderImpl method readString.
@Override
public Promise<HttpResponse<String>, HttpException> readString() {
connection.addRequestHeader(new HttpHeaderImpl(ACCEPT_CHARSET_HEADER, CHARSET));
final ResponseContentConverter<String> converter = b -> new String(b, CHARSET);
return createExecutor(converter);
}
use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testSimpleGetWithStringContent.
@Test
public void testSimpleGetWithStringContent() throws Exception {
// given:
final HttpClient client = PlatformClient.getService(HttpClient.class);
final AtomicBoolean actionCalled = new AtomicBoolean(false);
final AtomicBoolean doneCalled = new AtomicBoolean(false);
final AtomicBoolean errorCalled = new AtomicBoolean(false);
// when:
final CompletableFuture<HttpResponse<String>> future = client.get("http://localhost:" + freePort).withoutContent().readString().onDone(response -> {
actionCalled.set(true);
doneCalled.set(true);
}).onError(e -> {
actionCalled.set(true);
errorCalled.set(true);
}).execute();
// then:
final HttpResponse<String> response = future.get(1_000, TimeUnit.MILLISECONDS);
assertThat("response not defined", response, notNullValue());
assertThat("Wrong response code", response.getStatusCode(), is(200));
assertThat("Content should not be null", response.getRawContent(), notNullValue());
final String content = response.getContent();
assertThat("String content does not match", content, is("Spark Server for HTTP client integration tests"));
assertThatDoneCalledAndErrorNotCalled(actionCalled, doneCalled, errorCalled);
}
use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testPostWithContent.
@Test
public void testPostWithContent() throws Exception {
// given:
final HttpClient client = PlatformClient.getService(HttpClient.class);
final AtomicBoolean actionCalled = new AtomicBoolean(false);
final AtomicBoolean doneCalled = new AtomicBoolean(false);
final AtomicBoolean errorCalled = new AtomicBoolean(false);
// when:
final CompletableFuture<HttpResponse<String>> future = client.post("http://localhost:" + freePort).withContent("String").readString().onDone(response -> {
actionCalled.set(true);
doneCalled.set(true);
}).onError(e -> {
actionCalled.set(true);
errorCalled.set(true);
}).execute();
// then:
final HttpResponse<String> response = future.get(10_000, TimeUnit.MILLISECONDS);
assertThat("response not defined", response, notNullValue());
assertThat("Wrong response code", response.getStatusCode(), is(200));
assertThat("Content should not be null", response.getRawContent(), notNullValue());
final String content = response.getContent();
assertThat("String content does not match", content, is("CHECK"));
assertThatDoneCalledAndErrorNotCalled(actionCalled, doneCalled, errorCalled);
}
use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testBadResponse.
@Test
public void testBadResponse() throws Exception {
// given:
final HttpClient client = PlatformClient.getService(HttpClient.class);
final AtomicBoolean actionCalled = new AtomicBoolean(false);
final AtomicBoolean doneCalled = new AtomicBoolean(false);
final AtomicBoolean errorCalled = new AtomicBoolean(false);
// when:
final CompletableFuture<HttpResponse<Void>> future = client.get("http://localhost:" + freePort + "/error").withoutContent().withoutResult().onDone(response -> {
actionCalled.set(true);
doneCalled.set(true);
}).onError(e -> {
actionCalled.set(true);
errorCalled.set(true);
}).execute();
// then:
assertThatBadResponseException(doneCalled, errorCalled, future, SC_HTTP_UNAUTHORIZED);
assertThatErrorCalledAndDoneNotCalled(actionCalled, doneCalled, errorCalled);
}
use of com.canoo.platform.core.http.HttpResponse in project dolphin-platform by canoo.
the class HttpClientTests method testSimpleGetWithPromise.
@Test
public void testSimpleGetWithPromise() throws Exception {
// given:
final HttpClient client = PlatformClient.getService(HttpClient.class);
final AtomicBoolean actionCalled = new AtomicBoolean(false);
final AtomicBoolean doneCalled = new AtomicBoolean(false);
final AtomicBoolean errorCalled = new AtomicBoolean(false);
// when:
final CompletableFuture<HttpResponse<Void>> future = getHttpResponseCompletableFuture(client, actionCalled, doneCalled, errorCalled);
// then:
final HttpResponse<Void> response = future.get(1_000, TimeUnit.MILLISECONDS);
assertThat("response not defined", response, notNullValue());
assertThat("Wrong response code", response.getStatusCode(), is(200));
assertThat("Content should not be null", response.getRawContent(), notNullValue());
assertThatDoneCalledAndErrorNotCalled(actionCalled, doneCalled, errorCalled);
}
Aggregations