Implemented an example for a controller, that fetches remote-data
authorKai Moritz <kai@juplo.de>
Fri, 10 Jan 2020 18:44:03 +0000 (19:44 +0100)
committerKai Moritz <kai@juplo.de>
Sat, 11 Jan 2020 08:29:17 +0000 (09:29 +0100)
src/main/java/de/juplo/demo/DemoApplication.java
src/main/java/de/juplo/demo/RemoteContentController.java [new file with mode: 0644]
src/main/resources/application.properties
src/main/resources/templates/layout.html [new file with mode: 0644]

index 76f6fe4..53303c5 100644 (file)
@@ -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 (file)
index 0000000..fa0e49a
--- /dev/null
@@ -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/templates/layout.html b/src/main/resources/templates/layout.html
new file mode 100644 (file)
index 0000000..1087568
--- /dev/null
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML>
+<html xmlns:th="http://www.thymeleaf.org">
+<head>
+  <title>Shows Remote-Content</title>
+  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+</head>
+<body>
+  <h1>Remote-Content:</h1>
+  <p th:text="${text}">TEXT</p>
+</body>
+</html>