use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ClientMain method saveResponseToFile.
static Single<Void> saveResponseToFile(WebClient webClient) {
// We have to create file subscriber first. This subscriber will save the content of the response to the file.
Path file = Paths.get("test.txt");
try {
Files.deleteIfExists(file);
Files.createFile(file);
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Downloading server response to file: " + file);
return webClient.get().request().map(WebClientResponse::content).flatMapSingle(content -> content.map(DataChunk::data).flatMapIterable(Arrays::asList).to(IoMulti.writeToFile(file).build())).peek(path -> System.out.println("Download complete!"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ClientMain method clientMetricsExample.
static Single<String> clientMetricsExample(String url, Config config) {
// This part here is only for verification purposes, it is not needed to be done for actual usage.
String counterName = "example.metric.GET.localhost";
Counter counter = METRIC_REGISTRY.counter(counterName);
System.out.println(counterName + ": " + counter.getCount());
// Creates new metric which will count all GET requests and has format of example.metric.GET.<host-name>
WebClientService clientService = WebClientMetrics.counter().methods(Http.Method.GET).nameFormat("example.metric.%1$s.%2$s").build();
// This newly created metric now needs to be registered to WebClient.
WebClient webClient = WebClient.builder().baseUri(url).config(config).addService(clientService).build();
// Perform any GET request using this newly created WebClient instance.
return performGetMethod(webClient).peek(s -> System.out.println(counterName + ": " + counter.getCount()));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class MutualTlsExampleTest method testConfigAccessSuccessful.
@Test
public void testConfigAccessSuccessful() {
Config config = Config.just(() -> ConfigSources.classpath("application-test.yaml").build());
webServer = ServerConfigMain.startServer(config.get("server")).await();
WebClient webClient = WebClient.create(config.get("client"));
assertThat(ClientConfigMain.callUnsecured(webClient, webServer.port()), is("Hello world unsecured!"));
assertThat(ClientConfigMain.callSecured(webClient, webServer.port("secured")), is("Hello Helidon-client!"));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ClientBuilderMain method main.
/**
* Start the example.
* This example executes two requests by Helidon {@link WebClient} which are configured
* by the {@link WebClient.Builder}.
*
* You have to execute either {@link ServerBuilderMain} or {@link ServerConfigMain} for this to work.
*
* If any of the ports has been changed, you have to update ports in this main method also.
*
* @param args start arguments are ignored
*/
public static void main(String[] args) {
WebClient webClient = createWebClient();
System.out.println("Contacting unsecured endpoint!");
System.out.println("Response: " + callUnsecured(webClient, 8080));
System.out.println("Contacting secured endpoint!");
System.out.println("Response: " + callSecured(webClient, 443));
}
use of io.helidon.webclient.WebClient in project helidon by oracle.
the class ClientConfigMain method main.
/**
* Start the example.
* This example executes two requests by Helidon {@link WebClient} which are configured
* by the configuration.
*
* You have to execute either {@link ServerBuilderMain} or {@link ServerConfigMain} for this to work.
*
* If any of the ports has been changed, you have to update ports in this main method also.
*
* @param args start arguments are ignored
*/
public static void main(String[] args) {
Config config = Config.create();
WebClient webClient = WebClient.create(config.get("client"));
System.out.println("Contacting unsecured endpoint!");
System.out.println("Response: " + callUnsecured(webClient, 8080));
System.out.println("Contacting secured endpoint!");
System.out.println("Response: " + callSecured(webClient, 443));
}
Aggregations