4 import org.springframework.http.HttpStatus;
5 import org.springframework.http.MediaType;
6 import org.springframework.web.bind.annotation.GetMapping;
7 import org.springframework.web.bind.annotation.RequestParam;
8 import org.springframework.web.reactive.function.client.WebClientResponseException;
9 import org.springframework.web.reactive.function.client.WebClientResponseException.NotFound;
10 import org.springframework.web.server.ResponseStatusException;
11 import reactor.core.publisher.Mono;
15 * Fetches and returns data from a remote-webserver.
18 @org.springframework.web.bind.annotation.RestController
19 public class RestController
21 RemoteContentService service;
24 public RestController(RemoteContentService service)
26 this.service = service;
30 @GetMapping(path = { "", "/" }, produces = MediaType.TEXT_PLAIN_VALUE)
31 public Mono<String> fetch(@RequestParam String path)
38 if(t.getClass().equals(NotFound.class))
39 return Mono.error(new ResponseStatusException(HttpStatus.NOT_FOUND, "Cause: " + t.getMessage(), t));
40 if(!(t instanceof WebClientResponseException))
43 new ResponseStatusException(
44 HttpStatus.INTERNAL_SERVER_ERROR,
45 "Cause: " + t.getMessage(),
50 new ResponseStatusException(
51 HttpStatus.SERVICE_UNAVAILABLE,
52 "Cause: " + t.getMessage(),