X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fdemo%2FRemoteContentService.java;fp=src%2Fmain%2Fjava%2Fde%2Fjuplo%2Fdemo%2FRemoteContentService.java;h=c62225e931ae41e856e39fc063c2b5ac6e69019e;hb=760ff5d820afdeb2bf50b98c89519c384c56bf4b;hp=0000000000000000000000000000000000000000;hpb=b258d1b8645ce0411387f54fa2d097443277bf9b;p=demos%2Ftesting diff --git a/src/main/java/de/juplo/demo/RemoteContentService.java b/src/main/java/de/juplo/demo/RemoteContentService.java new file mode 100644 index 0000000..c62225e --- /dev/null +++ b/src/main/java/de/juplo/demo/RemoteContentService.java @@ -0,0 +1,43 @@ +package de.juplo.demo; + +import org.springframework.web.reactive.function.client.WebClient; +import reactor.core.publisher.Mono; + + +/** + * Fetches data from remote-webserver. + * @author Kai Moritz + */ +public class RemoteContentService +{ + WebClient webClient; + + + /** + * The {@link WebClient}, that is used to fetch the data. + *

+ * The WebClient has to be configured to us a given + * remote-server by default. This service will only add a path. + * @param webClient a WebClient instance with configured host + */ + public RemoteContentService(WebClient webClient) + { + this.webClient = webClient; + } + + + /** + * Fetches the given path from the configured remote-server. + * @param path the path to fetch from the configured remote-server + * @return a {@link Mono}, that represents the fetched data + */ + public Mono getRemoteText(String path) + { + return + webClient + .get() + .uri(path) + .retrieve() + .bodyToMono(String.class); + } +}