001// ***************************************************************************************************************************
002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
003// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
005// * with the License.  You may obtain a copy of the License at                                                              *
006// *                                                                                                                         *
007// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
008// *                                                                                                                         *
009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
011// * specific language governing permissions and limitations under the License.                                              *
012// ***************************************************************************************************************************
013package org.apache.juneau.rest.springboot;
014
015import java.util.*;
016
017import org.apache.juneau.dto.swagger.Swagger;
018import org.apache.juneau.http.annotation.*;
019import org.apache.juneau.http.resource.*;
020import org.apache.juneau.http.response.*;
021import org.apache.juneau.rest.*;
022import org.apache.juneau.rest.annotation.*;
023import org.apache.juneau.rest.config.*;
024import org.apache.juneau.rest.servlet.*;
025import org.apache.juneau.rest.stats.*;
026
027/**
028 * Subclass of {@link SpringRestServlet} with default settings and standard methods defined.
029 *
030 * <p>
031 * Meant as base class for top-level REST resources in Spring Boot environments.
032 *
033 * <p>
034 * Provides support for JSON, XML, HTML, URL-Encoding, UON, XML, OpenAPI, and MessagePack.  See {@link BasicUniversalConfig}
035 * for details.
036 *
037 * <p>
038 * Implements the basic REST endpoints defined in {@link BasicRestOperations}.
039 *
040 * <h5 class='section'>See Also:</h5><ul>
041 *    <li class='link'><a class="doclink" href="../../../../../index.html#juneau-rest-server-springboot">juneau-rest-server-springboot</a>
042 *    <li class='link'><a class="doclink" href="../../../../../index.html#jrs.AnnotatedClasses">@Rest-Annotated Classes</a>
043 * </ul>
044 *
045 * @serial exclude
046 */
047@Rest
048public abstract class BasicSpringRestServlet extends SpringRestServlet implements BasicRestOperations, BasicUniversalConfig {
049   private static final long serialVersionUID = 1L;
050
051   //-----------------------------------------------------------------------------------------------------------------
052   // BasicRestConfig methods
053   //-----------------------------------------------------------------------------------------------------------------
054
055   @Override /* BasicRestConfig */
056   public Swagger getSwagger(RestRequest req) {
057      return req.getSwagger().orElseThrow(NotFound::new);
058   }
059
060   @Override /* BasicRestConfig */
061   public HttpResource getHtdoc(@Path("/*") String path, Locale locale) throws NotFound {
062      return getContext().getStaticFiles().resolve(path, locale).orElseThrow(NotFound::new);
063   }
064
065   @Override /* BasicRestConfig */
066   public HttpResource getFavIcon() {
067      String favIcon = getContext().getConfig().get("REST/favicon").orElse("images/juneau.png");
068      return getHtdoc(favIcon, null);
069   }
070
071   @Override /* BasicRestConfig */
072   public void error() {}
073
074   @Override /* BasicRestConfig */
075   public RestContextStats getStats(RestRequest req) {
076      return req.getContext().getStats();
077   }
078}