All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juneau.rest.annotation.RestHook Maven / Gradle / Ivy

There is a newer version: 9.0.1
Show newest version
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
// * with the License.  You may obtain a copy of the License at                                                              *
// *                                                                                                                         *
// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
// *                                                                                                                         *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
// * specific language governing permissions and limitations under the License.                                              *
// ***************************************************************************************************************************
package org.apache.juneau.rest.annotation;

import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;

import java.lang.annotation.*;

/**
 * Identifies Java methods on a resource/servlet class that get invoked during particular lifecycle events of
 * the servlet or REST call.
 *
 * 

* For example, if you want to add an initialization method to your resource: *

* @RestResource(...) * public class MyResource { * * // Our database. * private Map<Integer,Object> myDatabase; * * @RestHook(INIT) * public void initMyDatabase(RestContextBuilder builder) throws Exception { * myDatabase = new LinkedHashMap<>(); * } * } *

* *

* Or if you want to intercept REST calls: *

* @RestResource(...) * public class MyResource { * * // Add a request attribute to all incoming requests. * @RestHook(PRE_CALL) * public void onPreCall(RestRequest req) { * req.setAttribute("foo", "bar"); * } * } *

* *

* The hook events can be broken down into two categories: *

    *
  • Resource lifecycle events: *
      *
    • {@link HookEvent#INIT INIT} - Right before initialization. *
    • {@link HookEvent#POST_INIT POST_INIT} - Right after initialization. *
    • {@link HookEvent#POST_INIT_CHILD_FIRST POST_INIT_CHILD_FIRST} - Right after initialization, but run child methods first. *
    • {@link HookEvent#DESTROY DESTROY} - Right before servlet destroy. *
    *
  • REST call lifecycle events: *
      *
    • {@link HookEvent#START_CALL START_CALL} - At the beginning of a REST call. *
    • {@link HookEvent#PRE_CALL PRE_CALL} - Right before the @RestMethod method is invoked. *
    • {@link HookEvent#POST_CALL POST_CALL} - Right after the @RestMethod method is invoked. *
    • {@link HookEvent#END_CALL END_CALL} - At the end of the REST call after the response has been flushed. *
    *
* *
See Also:
*
    *
*/ @Documented @Target(METHOD) @Retention(RUNTIME) @Inherited public @interface RestHook { /** * The lifecycle event. */ HookEvent value(); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy