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 @Override /* Overridden from BasicRestOperations */ 052 public void error() {} 053 054 @Override /* Overridden from BasicRestOperations */ 055 public HttpResource getFavIcon() { 056 String favIcon = getContext().getConfig().get("REST/favicon").orElse("images/juneau.png"); 057 return getHtdoc(favIcon, null); 058 } 059 060 @Override /* Overridden from BasicRestOperations */ 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 /* Overridden from BasicRestOperations */ 066 public RestContextStats getStats(RestRequest req) { 067 return req.getContext().getStats(); 068 } 069 070 @Override /* Overridden from BasicRestOperations */ 071 public Swagger getSwagger(RestRequest req) { 072 return req.getSwagger().orElseThrow(NotFound::new); 073 } 074}