use of io.helidon.webclient.WebClient in project helidon by oracle.
the class OidcSupport method processCode.
private void processCode(String code, ServerRequest req, ServerResponse res) {
WebClient webClient = oidcConfig.appWebClient();
FormParams.Builder form = FormParams.builder().add("grant_type", "authorization_code").add("code", code).add("redirect_uri", redirectUri(req));
WebClientRequestBuilder post = webClient.post().uri(oidcConfig.tokenEndpointUri()).accept(io.helidon.common.http.MediaType.APPLICATION_JSON);
oidcConfig.updateRequest(OidcConfig.RequestType.CODE_TO_TOKEN, post, form);
OidcConfig.postJsonResponse(post, form.build(), json -> processJsonResponse(req, res, json), (status, errorEntity) -> processError(res, status, errorEntity), (t, message) -> processError(res, t, message)).ignoreElement();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class PrematureConnectionCutTest method cutConnectionBefore100Continue.
@Test
void cutConnectionBefore100Continue() {
List<Exception> exceptions = Collections.synchronizedList(new ArrayList<>());
TestAsyncRunner asyncRunner = null;
WebServer webServer = null;
try {
final TestAsyncRunner async = asyncRunner = new TestAsyncRunner(CALL_NUM);
webServer = WebServer.builder().host("localhost").port(0).routing(Routing.builder().post((req, res) -> req.content().as(InputStream.class).thenAccept(is -> async.run(() -> {
try {
// this is where thread could get blocked indefinitely
is.readAllBytes();
} catch (IOException e) {
exceptions.add(e);
} finally {
res.send();
}
})))).build().start().await(TIMEOUT);
WebClient webClient = WebClient.builder().baseUri("http://localhost:" + webServer.port()).build();
for (int i = 0; i < CALL_NUM; i++) {
// Sending request with fake content length, but not continuing after 100 code
incomplete100Call(webClient);
}
// Wait for all threads to finish
asyncRunner.await();
assertThat("All threads didn't finish in time, probably deadlocked.", asyncRunner.finishedThreads.get(), is(CALL_NUM));
assertThat("All exceptions were not delivered, when connection closed.", exceptions.size(), is(CALL_NUM));
exceptions.forEach(e -> {
assertThat(e.getCause(), anyOf(// ISE: Channel closed prematurely by other side! - on Linux
instanceOf(IllegalStateException.class), instanceOf(IOException.class)));
});
} finally {
Optional.ofNullable(webServer).ifPresent(ws -> ws.shutdown().await(TIMEOUT));
Optional.ofNullable(asyncRunner).ifPresent(TestAsyncRunner::shutdown);
}
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ResponseOrderingTest method testContentOrdering.
@Test
public void testContentOrdering() throws Exception {
WebClient webClient = WebClient.builder().baseUri("http://0.0.0.0:" + webServer.port() + "/stream").build();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 10000; i++) {
sb.append(i).append("\n");
}
webClient.post().contentType(MediaType.APPLICATION_OCTET_STREAM).submit(sb.toString().getBytes(), String.class).thenAccept(it -> assertThat(it, is(sb.toString())));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MainTest method routing.
@ParameterizedTest
@ValueSource(strings = { "se", "mp" })
void routing(String edition) throws Exception {
HelidonApplication application = startTheApplication(editionToJarPath(edition), Collections.emptyList());
WebClient webClient = WebClient.builder().baseUri(application.getBaseUrl()).addMediaSupport(JsonpSupport.create()).build();
webClient.get().accept(MediaType.APPLICATION_JSON).skipUriEncoding().path("/boo%6bs").request().thenAccept(it -> {
if ("se".equals(edition)) {
assertThat("Checking encode URL response SE", it.status(), is(Http.Status.OK_200));
} else {
// JAXRS does not decode URLs before matching
assertThat("Checking encode URL response MP", it.status(), is(Http.Status.NOT_FOUND_404));
}
}).toCompletableFuture().get();
webClient.get().accept(MediaType.APPLICATION_JSON).path("/badurl").request().thenAccept(it -> assertThat("Checking encode URL response", it.status(), is(Http.Status.NOT_FOUND_404))).toCompletableFuture().get();
application.stop();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MainTest method runJsonFunctionalTest.
/**
* Run some basic CRUD operations on the server. The server supports
* running with any of our three JSON libraries: jsonp, jsonb, jackson.
* So we set a system property to select the library to use before starting
* the server
*
* @param edition "mp", "se"
* @param jsonLibrary "jsonp", "jsonb" or "jackson"
* @throws Exception on test failure
*/
private void runJsonFunctionalTest(String edition, String jsonLibrary) throws Exception {
JsonObject json = getBookAsJsonObject();
int numberOfBooks = 1000;
List<String> systemPropertyArgs = new LinkedList<>();
systemPropertyArgs.add("-Dbookstore.size=" + numberOfBooks);
if (jsonLibrary != null && !jsonLibrary.isEmpty()) {
systemPropertyArgs.add("-Dapp.json-library=" + jsonLibrary);
}
HelidonApplication application = startTheApplication(editionToJarPath(edition), systemPropertyArgs);
WebClient webClient = WebClient.builder().baseUri(application.getBaseUrl()).addMediaSupport(JsonpSupport.create()).build();
webClient.get().path("/books").request(JsonArray.class).thenAccept(bookArray -> assertThat("Number of books", bookArray.size(), is(numberOfBooks))).toCompletableFuture().get();
webClient.post().path("/books").submit(json).thenAccept(it -> assertThat("HTTP response POST", it.status(), is(Http.Status.OK_200))).thenCompose(it -> webClient.get().path("/books/123456").request(JsonObject.class)).thenAccept(it -> assertThat("Checking if correct ISBN", it.getString("isbn"), is("123456"))).toCompletableFuture().get();
webClient.get().path("/books/0000").request().thenAccept(it -> assertThat("HTTP response GET bad ISBN", it.status(), is(Http.Status.NOT_FOUND_404))).toCompletableFuture().get();
webClient.get().path("/books").request().thenApply(it -> {
assertThat("HTTP response list books", it.status(), is(Http.Status.OK_200));
return it;
}).thenCompose(WebClientResponse::close).toCompletableFuture().get();
webClient.delete().path("/books/123456").request().thenAccept(it -> assertThat("HTTP response delete book", it.status(), is(Http.Status.OK_200))).toCompletableFuture().get();
application.stop();
}
Aggregations