From 3307282979e539dd44bbfb860bcdeb37b32e6c6e Mon Sep 17 00:00:00 2001 From: "Michael J. Simons" Date: Fri, 22 Jul 2016 22:19:52 +0200 Subject: [PATCH] Add BannerController --- .../ac/simons/doag2016/BannerController.java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/main/java/ac/simons/doag2016/BannerController.java diff --git a/src/main/java/ac/simons/doag2016/BannerController.java b/src/main/java/ac/simons/doag2016/BannerController.java new file mode 100644 index 0000000..8e9a26b --- /dev/null +++ b/src/main/java/ac/simons/doag2016/BannerController.java @@ -0,0 +1,50 @@ +/* + * Copyright 2016 michael-simons.eu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ac.simons.doag2016; + +import java.io.IOException; +import java.io.PrintStream; +import javax.servlet.http.HttpServletResponse; +import org.springframework.boot.Banner; +import org.springframework.core.env.Environment; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Michael J. Simons, 2016-04-15 + */ +@Controller +@RequestMapping("/api/banner") +class BannerController { + + private final Banner banner; + + private final Environment environment; + + BannerController(final Banner banner, final Environment environment) { + this.banner = banner; + this.environment = environment; + } + + @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) + public void get(final HttpServletResponse response) throws IOException { + try (PrintStream printStream = new PrintStream(response.getOutputStream())) { + banner.printBanner(environment, BannerController.class, printStream); + } + } +}