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.annotation;
018
019import static java.lang.annotation.ElementType.*;
020import static java.lang.annotation.RetentionPolicy.*;
021
022import java.lang.annotation.*;
023
024import org.apache.juneau.http.response.*;
025
026import jakarta.servlet.http.*;
027
028/**
029 * Identifies a method that is called immediately after the <c>HttpServlet.service(HttpServletRequest, HttpServletResponse)</c>
030 * method is called.
031 *
032 * <p>
033 * Note that you only have access to the raw request and response objects at this point.
034 *
035 * <p>
036 * The list of valid parameter types are as follows:
037 * <ul>
038 *    <li>Servlet request/response objects:
039 *       <ul>
040 *          <li>{@link HttpServletRequest}
041 *          <li>{@link HttpServletResponse}
042 *       </ul>
043 * </ul>
044 *
045 * <h5 class='figure'>Example:</h5>
046 * <p class='bjava'>
047 *    <ja>@Rest</ja>(...)
048 *    <jk>public class</jk> MyResource <jk>extends</jk> BasicRestServlet {
049 *
050 *       <jc>// Add a request attribute to all incoming requests.</jc>
051 *       <ja>@RestStartCall</ja>
052 *       <jk>public void</jk> onStartCall(HttpServletRequest <jv>req</jv>) {
053 *          <jv>req</jv>.setAttribute(<js>"foobar"</js>, <jk>new</jk> FooBar());
054 *       }
055 *    }
056 * </p>
057 *
058 * <h5 class='section'>Notes:</h5><ul>
059 *    <li class='note'>
060 *       The method should return <jk>void</jk> although if it does return any value, the value will be ignored.
061 *    <li class='note'>
062 *       The method should be <jk>public</jk> although other visibilities are valid if the security manager allows it.
063 *    <li class='note'>
064 *       Static methods can be used.
065 *    <li class='note'>
066 *       Multiple start-call methods can be defined on a class.
067 *       <br>Start call methods on parent classes are invoked before start-call methods on child classes.
068 *       <br>The order of start-call method invocations within a class is alphabetical, then by parameter count, then by parameter types.
069 *    <li class='note'>
070 *       The method can throw any exception.
071 *       <br>{@link BasicHttpException BasicHttpExceptions} can be thrown to cause a particular HTTP error status code.
072 *       <br>All other exceptions cause an HTTP 500 error status code.
073 *    <li class='note'>
074 *       Note that if you override a parent method, you probably need to call <code><jk>super</jk>.parentMethod(...)</code>.
075 *       <br>The method is still considered part of the parent class for ordering purposes even though it's
076 *       overridden by the child class.
077 * </ul>
078 *
079 * <h5 class='section'>See Also:</h5><ul>
080 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/LifecycleHooks">Lifecycle Hooks</a>
081 * </ul>
082 */
083@Target({METHOD,TYPE})
084@Retention(RUNTIME)
085@Inherited
086@Repeatable(RestStartCallAnnotation.Array.class)
087public @interface RestStartCall {
088
089    /**
090     * Optional description for the exposed API.
091     *
092     * @return The annotation value.
093     * @since 9.2.0
094     */
095    String[] description() default {};
096
097    /**
098    * Dynamically apply this annotation to the specified methods.
099    *
100    * <h5 class='section'>See Also:</h5><ul>
101    *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a>
102    * </ul>
103    *
104    * @return The annotation value.
105    */
106   String[] on() default {};
107}