001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.annotation; 014 015import static java.lang.annotation.ElementType.*; 016import static java.lang.annotation.RetentionPolicy.*; 017 018import java.lang.annotation.*; 019 020import jakarta.servlet.http.*; 021 022import org.apache.juneau.http.response.*; 023 024/** 025 * Identifies a method that is called immediately after the <c>HttpServlet.service(HttpServletRequest, HttpServletResponse)</c> 026 * method is called. 027 * 028 * <p> 029 * Note that you only have access to the raw request and response objects at this point. 030 * 031 * <p> 032 * The list of valid parameter types are as follows: 033 * <ul> 034 * <li>Servlet request/response objects: 035 * <ul> 036 * <li>{@link HttpServletRequest} 037 * <li>{@link HttpServletResponse} 038 * </ul> 039 * </ul> 040 * 041 * <h5 class='figure'>Example:</h5> 042 * <p class='bjava'> 043 * <ja>@Rest</ja>(...) 044 * <jk>public class</jk> MyResource <jk>extends</jk> BasicRestServlet { 045 * 046 * <jc>// Add a request attribute to all incoming requests.</jc> 047 * <ja>@RestStartCall</ja> 048 * <jk>public void</jk> onStartCall(HttpServletRequest <jv>req</jv>) { 049 * <jv>req</jv>.setAttribute(<js>"foobar"</js>, <jk>new</jk> FooBar()); 050 * } 051 * } 052 * </p> 053 * 054 * <h5 class='section'>Notes:</h5><ul> 055 * <li class='note'> 056 * The method should return <jk>void</jk> although if it does return any value, the value will be ignored. 057 * <li class='note'> 058 * The method should be <jk>public</jk> although other visibilities are valid if the security manager allows it. 059 * <li class='note'> 060 * Static methods can be used. 061 * <li class='note'> 062 * Multiple start-call methods can be defined on a class. 063 * <br>Start call methods on parent classes are invoked before start-call methods on child classes. 064 * <br>The order of start-call method invocations within a class is alphabetical, then by parameter count, then by parameter types. 065 * <li class='note'> 066 * The method can throw any exception. 067 * <br>{@link BasicHttpException BasicHttpExceptions} can be thrown to cause a particular HTTP error status code. 068 * <br>All other exceptions cause an HTTP 500 error status code. 069 * <li class='note'> 070 * Note that if you override a parent method, you probably need to call <code><jk>super</jk>.parentMethod(...)</code>. 071 * <br>The method is still considered part of the parent class for ordering purposes even though it's 072 * overridden by the child class. 073 * </ul> 074 * 075 * <h5 class='section'>See Also:</h5><ul> 076 * <li class='link'><a class="doclink" href="../../../../../index.html#jrs.LifecycleHooks">Lifecycle Hooks</a> 077 * </ul> 078 */ 079@Target({METHOD,TYPE}) 080@Retention(RUNTIME) 081@Inherited 082@Repeatable(RestStartCallAnnotation.Array.class) 083public @interface RestStartCall { 084 085 /** 086 * Dynamically apply this annotation to the specified methods. 087 * 088 * <h5 class='section'>See Also:</h5><ul> 089 * <li class='link'><a class="doclink" href="../../../../../index.html#jm.DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 090 * </ul> 091 * 092 * @return The annotation value. 093 */ 094 String[] on() default {}; 095}