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