From: Kai Moritz Date: Fri, 10 Jan 2020 18:44:03 +0000 (+0100) Subject: Implemented an example for a controller, that fetches remote-data X-Git-Tag: old~1 X-Git-Url: https://juplo.de/gitweb/?p=demos%2Ftesting;a=commitdiff_plain;h=323e1b0a1df5f61e7b6f9ee6f923a186f70772de Implemented an example for a controller, that fetches remote-data --- diff --git a/src/main/java/de/juplo/demo/DemoApplication.java b/src/main/java/de/juplo/demo/DemoApplication.java index 76f6fe4..53303c5 100644 --- a/src/main/java/de/juplo/demo/DemoApplication.java +++ b/src/main/java/de/juplo/demo/DemoApplication.java @@ -1,12 +1,22 @@ 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; @SpringBootApplication public class DemoApplication { - public static void main(String[] args) { + @Bean + public RemoteContentController remoteContentController( + @Value("${remote.host}")String remoteHost) + { + return new RemoteContentController(remoteHost); + } + + + public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } diff --git a/src/main/java/de/juplo/demo/RemoteContentController.java b/src/main/java/de/juplo/demo/RemoteContentController.java new file mode 100644 index 0000000..fa0e49a --- /dev/null +++ b/src/main/java/de/juplo/demo/RemoteContentController.java @@ -0,0 +1,41 @@ +package de.juplo.demo; + + +<<<<<<< HEAD:src/main/java/de/juplo/demo/RemoteContentController.java +======= +>>>>>>> f9152f7... WIP: Implemented...:src/main/java/de/juplo/integrationtest/RemoteContentController.java +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.reactive.function.client.WebClient; + + +/** + * Fetches data from remote-webserver and renders them as HTML. + * @author Kai Moritz + */ +public class RemoteContentController +{ + WebClient webClient; + + + public RemoteContentController(WebClient webClient) + { + this.webClient = webClient; + } + + + @GetMapping("/") + public String renderRemoteText(Model model, @RequestParam String path) + { + model.addAttribute( + "text", + webClient + .get() + .uri(path) + .retrieve() + .bodyToMono(String.class).block()); + + return "layout"; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 8b13789..17c0d7b 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1 @@ - +remote.host=http://localhost/ diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html new file mode 100644 index 0000000..1087568 --- /dev/null +++ b/src/main/resources/templates/layout.html @@ -0,0 +1,11 @@ + + + + Shows Remote-Content + + + +

Remote-Content:

+

TEXT

+ +