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.rest.springboot; 018 019import java.util.*; 020 021import org.apache.juneau.bean.swagger.Swagger; 022import org.apache.juneau.http.annotation.*; 023import org.apache.juneau.http.resource.*; 024import org.apache.juneau.http.response.*; 025import org.apache.juneau.rest.*; 026import org.apache.juneau.rest.annotation.*; 027import org.apache.juneau.rest.config.*; 028import org.apache.juneau.rest.servlet.*; 029import org.apache.juneau.rest.stats.*; 030 031/** 032 * Subclass of {@link SpringRestServlet} with default settings and standard methods defined. 033 * 034 * <p> 035 * Meant as base class for top-level REST resources in Spring Boot environments. 036 * 037 * <p> 038 * Provides support for JSON, XML, HTML, URL-Encoding, UON, XML, OpenAPI, and MessagePack. See {@link BasicUniversalConfig} 039 * for details. 040 * 041 * <p> 042 * Implements the basic REST endpoints defined in {@link BasicRestOperations}. 043 * 044 * <h5 class='section'>See Also:</h5><ul> 045 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestServerSpringbootBasics">juneau-rest-server-springboot Basics</a> 046 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestAnnotatedClassBasics">@Rest-Annotated Class Basics</a> 047 * </ul> 048 * 049 * @serial exclude 050 */ 051@Rest 052public abstract class BasicSpringRestServlet extends SpringRestServlet implements BasicRestOperations, BasicUniversalConfig { 053 private static final long serialVersionUID = 1L; 054 055 //----------------------------------------------------------------------------------------------------------------- 056 // BasicRestConfig methods 057 //----------------------------------------------------------------------------------------------------------------- 058 059 @Override /* BasicRestConfig */ 060 public Swagger getSwagger(RestRequest req) { 061 return req.getSwagger().orElseThrow(NotFound::new); 062 } 063 064 @Override /* BasicRestConfig */ 065 public HttpResource getHtdoc(@Path("/*") String path, Locale locale) throws NotFound { 066 return getContext().getStaticFiles().resolve(path, locale).orElseThrow(NotFound::new); 067 } 068 069 @Override /* BasicRestConfig */ 070 public HttpResource getFavIcon() { 071 String favIcon = getContext().getConfig().get("REST/favicon").orElse("images/juneau.png"); 072 return getHtdoc(favIcon, null); 073 } 074 075 @Override /* BasicRestConfig */ 076 public void error() {} 077 078 @Override /* BasicRestConfig */ 079 public RestContextStats getStats(RestRequest req) { 080 return req.getContext().getStats(); 081 } 082}