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 java.io.*;
020
021import org.apache.juneau.rest.server.*;
022import org.apache.juneau.rest.server.servlet.*;
023
024/**
025 * Child-resource flavor of the {@link VersionMixin} version/build-metadata capability.
026 *
027 * <p>
028 * Mounts as a <b>routed child</b> via {@link Rest#children() @Rest(children=VersionResource.class)}
029 * under a parent at the subtree {@code /version} and serves the same deployment-introspection JSON map
030 * as the mixin by delegating to a shared flavor-neutral {@link VersionProvider} worker bean &mdash; so the forms
031 * cannot drift.
032 *
033 * <p>
034 * Whereas the {@link VersionMixin} mixin pins its op at {@code /version} for composition into a host at
035 * {@code /}, this child declares the subtree at the class level
036 * ({@link Rest#path() @Rest(path="/version")}) and pins the op at {@code /*}.
037 *
038 * <h5 class='section'>See Also:</h5><ul>
039 *    <li class='jc'>{@link VersionMixin}
040 *    <li class='jc'>{@link VersionServlet}
041 *    <li class='jc'>{@link VersionProvider}
042 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerComposition">REST Server — Mixins and Multi-Mount Paths</a>
043 * </ul>
044 *
045 * @since 10.0.0
046 */
047// @formatter:off
048@Rest(path="/version")
049public class VersionResource extends RestResource {
050
051   private final VersionProvider worker;
052
053   /** No-arg constructor &mdash; uses a default {@link VersionProvider} worker. */
054   public VersionResource() {
055      this(new VersionProvider());
056   }
057
058   /**
059    * Worker constructor.
060    *
061    * @param worker The shared flavor-neutral version worker this child delegates to. Must not be
062    *    {@code null}.
063    */
064   protected VersionResource(VersionProvider worker) {
065      this.worker = worker;
066   }
067
068   /**
069    * [GET /*] &mdash; emit the assembled metadata as a JSON map.
070    *
071    * @param res The current REST response.
072    * @throws IOException If an I/O error occurs while writing the response.
073    */
074   @RestGet(
075      path="/*",
076      summary="Version / build metadata",
077      description="Deployment-introspection metadata (name, version, git, build).",
078      swagger=@OpSwagger(ignore=true)
079   )
080   public void getInfo(RestResponse res) throws IOException {
081      worker.serve(res);
082   }
083}