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: rm X-Git-Url: https://juplo.de/gitweb/?p=demos%2Ftesting;a=commitdiff_plain;h=refs%2Ftags%2Frm Implemented an example for a controller, that fetches remote-data --- diff --git a/src/main/java/de/juplo/integrationtest/RemoteContentController.java b/src/main/java/de/juplo/integrationtest/RemoteContentController.java new file mode 100644 index 0000000..59f342e --- /dev/null +++ b/src/main/java/de/juplo/integrationtest/RemoteContentController.java @@ -0,0 +1,42 @@ +package de.juplo.integrationtest; + + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +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 + */ +@Controller +public class RemoteContentController +{ + WebClient webClient; + + + public RemoteContentController(@Value("${remote.host}")String remoteHost) + { + webClient = WebClient.create(remoteHost); + } + + + @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

+ +