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

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

// ***************************************************************************************************************************
// * 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.io.*;
import java.lang.annotation.*;
import java.util.*;
import java.util.logging.*;

import jakarta.servlet.*;
import jakarta.servlet.http.*;

import org.apache.juneau.*;
import org.apache.juneau.config.*;
import org.apache.juneau.cp.*;
import org.apache.juneau.http.header.*;
import org.apache.juneau.http.response.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.guard.*;
import org.apache.juneau.rest.httppart.*;
import org.apache.juneau.rest.matcher.*;

/**
 * Identifies a method that gets called immediately before the @RestOp annotated method gets called.
 *
 * 

* At this point, the {@link RestRequest} object has been fully initialized, and all {@link RestGuard} and * {@link RestMatcher} objects have been called. * *

* The list of valid parameter types are as follows: *

    *
  • Servlet request/response objects: *
      *
    • {@link HttpServletRequest} *
    • {@link HttpServletResponse} *
    *
  • Extended request/response objects: *
      *
    • {@link RestRequest} *
    • {@link RestResponse} *
    *
  • Header objects: *
      *
    • {@link Accept} *
    • {@link AcceptCharset} *
    • {@link AcceptEncoding} *
    • {@link AcceptLanguage} *
    • {@link Authorization} *
    • {@link CacheControl} *
    • {@link Connection} *
    • {@link ContentLength} *
    • {@link ContentType} *
    • {@link org.apache.juneau.http.header.Date} *
    • {@link Expect} *
    • {@link From} *
    • {@link Host} *
    • {@link IfMatch} *
    • {@link IfModifiedSince} *
    • {@link IfNoneMatch} *
    • {@link IfRange} *
    • {@link IfUnmodifiedSince} *
    • {@link MaxForwards} *
    • {@link Pragma} *
    • {@link ProxyAuthorization} *
    • {@link Range} *
    • {@link Referer} *
    • {@link TE} *
    • {@link UserAgent} *
    • {@link Upgrade} *
    • {@link Via} *
    • {@link Warning} *
    • {@link TimeZone} *
    *
  • Other objects: *
      *
    • {@link ResourceBundle} *
    • {@link Messages} *
    • {@link InputStream} *
    • {@link ServletInputStream} *
    • {@link Reader} *
    • {@link OutputStream} *
    • {@link ServletOutputStream} *
    • {@link Writer} *
    • {@link RequestHeaders} *
    • {@link RequestQueryParams} *
    • {@link RequestFormParams} *
    • {@link RequestPathParams} *
    • {@link Logger} *
    • {@link RestContext} *
    • {@link org.apache.juneau.parser.Parser} *
    • {@link Locale} *
    • {@link Swagger} *
    • {@link RequestContent} *
    • {@link Config} *
    • {@link UriContext} *
    • {@link UriResolver} *
    *
* *
Example:
*

* @Rest(...) * public class MyResource extends BasicRestServlet { * * // Log the incoming request. * @RestPreCall * public void onPreCall(Accept accept, Logger logger) { * logger.fine("Accept {0} header found.", accept); * } * } *

* *
Notes:
    *
  • * The method should return void although if it does return any value, the value will be ignored. *
  • * The method should be public although other visibilities are valid if the security manager allows it. *
  • * Static methods can be used. *
  • * Multiple pre-call methods can be defined on a class. *
    Pre-call methods on parent classes are invoked before pre-call methods on child classes. *
    The order of pre-call method invocations within a class is alphabetical, then by parameter count, then by parameter types. *
  • * The method can throw any exception. *
    {@link BasicHttpException BasicHttpExceptions} can be thrown to cause a particular HTTP error status code. *
    All other exceptions cause an HTTP 500 error status code. *
  • * Note that if you override a parent method, you probably need to call super.parentMethod(...). *
    The method is still considered part of the parent class for ordering purposes even though it's * overridden by the child class. *
  • * It's advisable not to mess around with the HTTP content itself since you may end up consuming the content * before the actual REST method has a chance to use it. *
* *
See Also:
*/ @Target({METHOD,TYPE}) @Retention(RUNTIME) @Inherited @Repeatable(RestPreCallAnnotation.Array.class) public @interface RestPreCall { /** * Dynamically apply this annotation to the specified methods. * *
See Also:
* * @return The annotation value. */ String[] on() default {}; }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy