package de.juplo.demo;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.web.reactive.function.client.WebClient;
@SpringBootApplication
-public class DemoApplication {
+public class DemoApplication
+{
+ @Bean
+ public RemoteContentService service(@Value("${remote.host}")String remoteHost)
+ {
+ return new RemoteContentService(WebClient.create(remoteHost));
+ }
- public static void main(String[] args) {
- SpringApplication.run(DemoApplication.class, args);
- }
+ public static void main(String[] args)
+ {
+ SpringApplication.run(DemoApplication.class, args);
+ }
}
--- /dev/null
+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.
+ * <p>
+ * The <code>WebClient</code> has to be configured to us a given
+ * remote-server by default. This service will only add a path.
+ * @param webClient a <code>WebClient</code> 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<String> getRemoteText(String path)
+ {
+ return
+ webClient
+ .get()
+ .uri(path)
+ .retrieve()
+ .bodyToMono(String.class);
+ }
+}