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.view.jsp; 018 019import org.apache.juneau.rest.server.*; 020import org.apache.juneau.rest.server.view.*; 021 022/** 023 * Standalone servlet companion of the {@link JspMixin} mixin. 024 * 025 * <p> 026 * Mounts as a <b>sibling top-level servlet</b> at {@code /jsp/*} (a sibling of the host 027 * application's other servlets, e.g. {@code /rest/*}) and serves raw {@code .jsp} resources by 028 * delegating to a shared {@link JspDispatcher} worker — the same flavor-neutral 029 * {@link RawTemplateDispatcher} implementation the mixin and child flavors hold, so the forms cannot 030 * drift. 031 * 032 * <p> 033 * Whereas the {@link JspMixin} mixin pins its op at {@code /jsp/*} for composition into a 034 * host at {@code /}, this companion declares the mount at the class level 035 * ({@link Rest#paths() @Rest(paths="/jsp/*")}) and inherits the {@code /*} op from 036 * {@link ViewServlet} — eliminating the path-doubling that a mixin-shaped op would 037 * produce when the servlet itself is mounted at {@code /jsp/*}. 038 * 039 * <h5 class='figure'>Microservice registration:</h5> 040 * 041 * <p class='bjava'> 042 * <ja>@Bean</ja> Servlet jsp() { 043 * <jk>return new</jk> JspServlet(); <jc>// auto-mounted at /jsp/* by JettyServerComponent</jc> 044 * } 045 * </p> 046 * 047 * <p> 048 * The default mount {@code /jsp/*} can be relocated by overriding {@link #getPaths()} or via the 049 * programmatic {@code RestContext.Builder.paths(...)} rung; the underlying base path for resolving 050 * {@code .jsp} files is configured on the {@link JspDispatcher} worker. 051 * 052 * <h5 class='section'>See Also:</h5><ul> 053 * <li class='jc'>{@link JspMixin} 054 * <li class='jc'>{@link ViewServlet} 055 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JspViewSupport">JSP View Support</a> 056 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerComposition">REST Server — Mixins and Multi-Mount Paths</a> 057 * </ul> 058 * 059 * @serial exclude 060 * @since 10.0.0 061 */ 062@Rest( 063 paths="/jsp/*", 064 responseProcessors={JspViewRenderer.class} 065) 066public class JspServlet extends ViewServlet { 067 068 private static final long serialVersionUID = 1L; 069 070 private final transient JspDispatcher worker; 071 072 /** No-arg constructor — uses a default {@link JspDispatcher} worker. */ 073 public JspServlet() { 074 this(JspDispatcher.create().build()); 075 } 076 077 /** 078 * Worker constructor. 079 * 080 * @param worker The shared flavor-neutral JSP dispatcher this servlet delegates raw dispatch 081 * to. Must not be {@code null}. 082 */ 083 protected JspServlet(JspDispatcher worker) { 084 this.worker = worker; 085 } 086 087 @Override /* ViewServlet */ 088 protected RawTemplateDispatcher dispatcher() { 089 return worker; 090 } 091}