use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ClientMain method main.
/**
* Executes WebClient examples.
*
* If no argument provided it will take server port from configuration server.port.
*
* User can override port from configuration by main method parameter with the specific port.
*
* @param args main method
*/
public static void main(String[] args) {
Config config = Config.create();
String url;
if (args.length == 0) {
ConfigValue<Integer> port = config.get("server.port").asInt();
if (!port.isPresent() || port.get() == -1) {
throw new IllegalStateException("Unknown port! Please specify port as a main method parameter " + "or directly to config server.port");
}
url = "http://localhost:" + port.get() + "/greet";
} else {
url = "http://localhost:" + Integer.parseInt(args[0]) + "/greet";
}
WebClient webClient = WebClient.builder().baseUri(url).config(config.get("client")).addMediaSupport(JsonpSupport.create()).build();
performPutMethod(webClient).flatMapSingle(it -> performGetMethod(webClient)).flatMapSingle(it -> followRedirects(webClient)).flatMapSingle(it -> getResponseAsAnJsonObject(webClient)).flatMapSingle(it -> saveResponseToFile(webClient)).flatMapSingle(it -> clientMetricsExample(url, config)).await();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ClientMainTest method createWebClient.
private void createWebClient(int port, WebClientService... services) {
Config config = Config.create();
WebClient.Builder builder = WebClient.builder().baseUri("http://localhost:" + port + "/greet").config(config.get("client")).addMediaSupport(JsonpSupport.create());
for (WebClientService service : services) {
builder.addService(service);
}
webClient = builder.build();
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MutualTlsExampleTest method testBuilderAccessSuccessful.
@Test
public void testBuilderAccessSuccessful() {
webServer = ServerBuilderMain.startServer(-1, -1).await();
WebClient webClient = ClientBuilderMain.createWebClient();
assertThat(ClientBuilderMain.callUnsecured(webClient, webServer.port()), is("Hello world unsecured!"));
assertThat(ClientBuilderMain.callSecured(webClient, webServer.port("secured")), is("Hello Helidon-client!"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class LoadBalancedCoordinatorTest method waitForRecovery.
private void waitForRecovery(URI lraId) {
URI coordinatorPath = coordinatorPath(lraId);
for (int i = 0; i < 10; i++) {
WebClient client = WebClient.builder().baseUri(coordinatorPath).build();
WebClientResponse response = client.get().path("recovery").submit().await(TIMEOUT_SEC, TimeUnit.SECONDS);
String recoveringLras = response.content().as(String.class).await(TIMEOUT_SEC, TimeUnit.SECONDS);
response.close();
if (!recoveringLras.contains(lraId.toASCIIString())) {
LOGGER.fine("LRA is no longer among those recovering " + lraId.toASCIIString());
// intended LRA is not longer among those recovering
break;
}
LOGGER.fine("Waiting for recovery attempt #" + i + " LRA is still waiting: " + recoveringLras);
}
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MainTest method runMetricsAndHealthTest.
/**
* Run some basic metrics and health 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"
* @param useModules true to use modulepath, false to use classpath
* @throws Exception on test failure
*/
private void runMetricsAndHealthTest(String edition, String jsonLibrary, boolean useModules) throws Exception {
List<String> systemPropertyArgs = new LinkedList<>();
if (jsonLibrary != null && !jsonLibrary.isEmpty()) {
systemPropertyArgs.add("-Dapp.json-library=" + jsonLibrary);
}
HelidonApplication application;
if (useModules) {
application = startTheApplicationModule(editionToJarPath(edition), systemPropertyArgs, editionToModuleName(edition));
} else {
application = startTheApplication(editionToJarPath(edition), systemPropertyArgs);
}
WebClient webClient = WebClient.builder().baseUri(application.getBaseUrl()).addMediaSupport(JsonpSupport.create()).build();
// Get Prometheus style metrics
webClient.get().accept(MediaType.WILDCARD).path("/metrics").request(String.class).thenAccept(it -> assertThat("Making sure we got Prometheus format", it, startsWith("# TYPE"))).toCompletableFuture().get();
// Get JSON encoded metrics
webClient.get().accept(MediaType.APPLICATION_JSON).path("/metrics").request(JsonObject.class).thenAccept(it -> assertThat("Checking request count", it.getJsonObject("vendor").getInt("requests.count"), greaterThan(0))).toCompletableFuture().get();
// Get JSON encoded metrics/base
webClient.get().accept(MediaType.APPLICATION_JSON).path("/metrics/base").request(JsonObject.class).thenAccept(it -> assertThat("Checking request count", it.getInt("thread.count"), greaterThan(0))).toCompletableFuture().get();
// Get JSON encoded health check
webClient.get().accept(MediaType.APPLICATION_JSON).path("/health").request(JsonObject.class).thenAccept(it -> {
assertThat("Checking health status", it.getString("status"), is("UP"));
// 'microprofile-config.properties' setting in bookstore application
if (edition.equals("mp")) {
assertThat("Checking built-in health checks disabled", it.getJsonArray("checks").size(), is(0));
}
}).toCompletableFuture().get();
application.stop();
}
Aggregations