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.servlet;
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.stats.*;
029
030import jakarta.servlet.http.*;
031
032/**
033 * Identical to {@link BasicRestServlet} but doesn't extend from {@link HttpServlet}.
034 *
035 * <p>
036 * Meant as a base class for child REST resources in servlet containers and Spring Boot environments.
037 *
038 * <p>
039 * Provides support for JSON, XML, HTML, URL-Encoding, UON, XML, OpenAPI, and MessagePack.  See {@link BasicUniversalConfig}
040 * for details.
041 *
042 * <p>
043 * Implements the basic REST endpoints defined in {@link BasicRestOperations}.
044 *
045 * <h5 class='section'>See Also:</h5><ul>
046 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestAnnotatedClassBasics">@Rest-Annotated Class Basics</a>
047 * </ul>
048 */
049@Rest
050public abstract class BasicRestObject extends RestObject implements BasicRestOperations, BasicUniversalConfig {
051
052   //-----------------------------------------------------------------------------------------------------------------
053   // BasicRestConfig methods
054   //-----------------------------------------------------------------------------------------------------------------
055
056   @Override /* BasicRestOperations */
057   public Swagger getSwagger(RestRequest req) {
058      return req.getSwagger().orElseThrow(NotFound::new);
059   }
060
061   @Override /* BasicRestOperations */
062   public HttpResource getHtdoc(@Path("/*") String path, Locale locale) throws NotFound {
063      return getContext().getStaticFiles().resolve(path, locale).orElseThrow(NotFound::new);
064   }
065
066   @Override /* BasicRestOperations */
067   public HttpResource getFavIcon() {
068      String favIcon = getContext().getConfig().get("REST/favicon").orElse("images/juneau.png");
069      return getHtdoc(favIcon, null);
070   }
071
072   @Override /* BasicRestOperations */
073   public void error() {}
074
075   @Override /* BasicRestOperations */
076   public RestContextStats getStats(RestRequest req) {
077      return req.getContext().getStats();
078   }
079}