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.server.convention;
018
019import org.apache.juneau.http.*;
020import org.apache.juneau.rest.server.*;
021import org.apache.juneau.rest.server.servlet.*;
022
023/**
024 * Child-resource flavor of the {@link FaviconMixin} mixin.
025 *
026 * <p>
027 * Mounts as a <b>routed child</b> via {@link Rest#children() @Rest(children=FaviconResource.class)}
028 * under a parent at the subtree {@code /favicon.ico} and serves the configured favicon bytes by
029 * delegating to a shared flavor-neutral {@link FaviconProvider} worker bean &mdash; so the forms cannot drift.
030 *
031 * <h5 class='section'>See Also:</h5><ul>
032 *    <li class='jc'>{@link FaviconMixin}
033 *    <li class='jc'>{@link FaviconServlet}
034 *    <li class='jc'>{@link FaviconProvider}
035 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerComposition">REST Server — Mixins and Multi-Mount Paths</a>
036 * </ul>
037 *
038 * @since 10.0.0
039 */
040// @formatter:off
041@Rest(path="/favicon.ico")
042public class FaviconResource extends RestResource {
043
044   private final FaviconProvider worker;
045
046   /** No-arg constructor &mdash; uses a default {@link FaviconProvider} worker. */
047   public FaviconResource() {
048      this(new FaviconProvider());
049   }
050
051   /**
052    * Worker constructor.
053    *
054    * @param worker The shared flavor-neutral favicon worker this child delegates to. Must not be
055    *    {@code null}.
056    */
057   protected FaviconResource(FaviconProvider worker) {
058      this.worker = worker;
059   }
060
061   /**
062    * [GET /*] &mdash; serve the configured favicon bytes.
063    *
064    * @return The favicon as an {@link HttpResource} with proper headers.
065    */
066   @RestGet(
067      path="/*",
068      summary="Favorites icon",
069      description="Browser favorites icon (favicon.ico).",
070      swagger=@OpSwagger(ignore=true)
071   )
072   public HttpResource getFavicon() {
073      return worker.serve();
074   }
075}