From d9172ba2d35d55256ab14ed92815bba09a304f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20St=C3=A4ber?= Date: Sun, 11 Feb 2024 22:25:25 +0100 Subject: [PATCH] Java example: Redirect from root path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabian Stäber --- .../java/com/grafana/example/RollController.java | 1 + .../java/com/grafana/example/SpringBootApp.java | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/examples/java/src/main/java/com/grafana/example/RollController.java b/examples/java/src/main/java/com/grafana/example/RollController.java index e2132bc..f537a91 100644 --- a/examples/java/src/main/java/com/grafana/example/RollController.java +++ b/examples/java/src/main/java/com/grafana/example/RollController.java @@ -11,6 +11,7 @@ @RestController public class RollController { + private static final Logger logger = LoggerFactory.getLogger(RollController.class); @GetMapping("/rolldice") diff --git a/examples/java/src/main/java/com/grafana/example/SpringBootApp.java b/examples/java/src/main/java/com/grafana/example/SpringBootApp.java index 7a2139d..7501b5a 100644 --- a/examples/java/src/main/java/com/grafana/example/SpringBootApp.java +++ b/examples/java/src/main/java/com/grafana/example/SpringBootApp.java @@ -1,11 +1,24 @@ package com.grafana.example; +import jakarta.servlet.http.HttpServletResponse; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; @SpringBootApplication +@RestController public class SpringBootApp { + /** + * Redirect to {@link RollController} + */ + @GetMapping("/") + public void redirect(HttpServletResponse httpServletResponse) { + httpServletResponse.setHeader("Location", "/rolldice"); + httpServletResponse.setStatus(302); + } + public static void main(String[] args) { SpringApplication.run(SpringBootApp.class, args); }