001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.microservice.springboot.template; 018 019import static org.apache.juneau.commons.utils.Utils.*; 020 021import java.util.*; 022 023import org.apache.juneau.html.annotation.*; 024import org.apache.juneau.rest.annotation.*; 025import org.apache.juneau.rest.servlet.*; 026import org.springframework.beans.factory.annotation.*; 027 028/** 029 * Sample REST resource that prints out a simple "Hello world!" message. 030 * 031 * <h5 class='section'>See Also:</h5><ul> 032 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/MySpringBootMicroserviceBasics">My SpringBoot Microservice Basics</a> 033 034 * </ul> 035 */ 036@Rest(title = "Hello World", description = "An example of the simplest-possible resource", path = "/helloWorld") 037@HtmlDocConfig(aside = { "<div style='max-width:400px' class='text'>", " <p>This page shows a resource that simply response with a 'Hello world!' message</p>", 038 " <p>The POJO serialized is a simple String.</p>", "</div>" }) 039public class HelloWorldResource extends BasicRestObject { 040 041 private final String message; 042 043 /** 044 * Optional message provider that can be injected into this object. 045 */ 046 @Autowired 047 private Optional<HelloWorldMessageProvider> messageProvider; 048 049 /** 050 * Default constructor. 051 * <p> 052 * Used by default if bean cannot be found in the Spring application context. 053 */ 054 public HelloWorldResource() { 055 this("Hello world!"); 056 } 057 058 /** 059 * Constructor. 060 * 061 * @param message The message to display. 062 */ 063 public HelloWorldResource(String message) { 064 this.message = message; 065 } 066 067 /** 068 * GET request handler. 069 * 070 * @return A simple Hello-World message. 071 */ 072 @RestGet(path = "/*", summary = "Responds with \"Hello world!\"") 073 public String sayHello() { 074 var message = this.message; 075 if (nn(messageProvider) && messageProvider.isPresent()) 076 message = messageProvider.get().get(); 077 return message; 078 } 079}