d26c8c58e36f1be0ba7f14a17b1e837c10544d75
[demos/testing] / src / main / java / de / juplo / demo / HtmlController.java
1 package de.juplo.demo;
2
3
4 import org.springframework.stereotype.Controller;
5 import org.springframework.ui.Model;
6 import org.springframework.web.bind.annotation.GetMapping;
7 import org.springframework.web.bind.annotation.RequestParam;
8 import reactor.core.publisher.Mono;
9
10
11 /**
12  * Fetches data from a remote-webserver and renders it as HTML.
13  * @author Kai Moritz
14  */
15 @Controller
16 public class HtmlController
17 {
18   RemoteContentService service;
19
20
21   public HtmlController(RemoteContentService service)
22   {
23     this.service = service;
24   }
25
26
27   @GetMapping("/")
28   public String fetch(Model model, @RequestParam String path)
29   {
30     model.addAttribute(
31         "text",
32         service
33             .getRemoteText(path)
34             .onErrorResume(t -> Mono.just(t.getMessage())));
35     return "home";
36   }
37 }