Implemented an example for a controller, that fetches remote-data
[demos/testing] / src / main / java / de / juplo / demo / RemoteContentController.java
1 package de.juplo.demo;
2
3
4 <<<<<<< HEAD:src/main/java/de/juplo/demo/RemoteContentController.java
5 =======
6 >>>>>>> f9152f7... WIP: Implemented...:src/main/java/de/juplo/integrationtest/RemoteContentController.java
7 import org.springframework.ui.Model;
8 import org.springframework.web.bind.annotation.GetMapping;
9 import org.springframework.web.bind.annotation.RequestParam;
10 import org.springframework.web.reactive.function.client.WebClient;
11
12
13 /**
14  * Fetches data from remote-webserver and renders them as HTML.
15  * @author Kai Moritz
16  */
17 public class RemoteContentController
18 {
19   WebClient webClient;
20
21
22   public RemoteContentController(WebClient webClient)
23   {
24     this.webClient = webClient;
25   }
26
27
28   @GetMapping("/")
29   public String renderRemoteText(Model model, @RequestParam String path)
30   {
31     model.addAttribute(
32         "text",
33         webClient
34             .get()
35             .uri(path)
36             .retrieve()
37             .bodyToMono(String.class).block());
38
39     return "layout";
40   }
41 }