![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.juneau.http.annotation.StatusCode 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.http.annotation;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
import org.apache.juneau.*;
import org.apache.juneau.annotation.*;
/**
* REST response status annotation.
*
*
* Annotation used to denote an HTTP response status code.
*
*
* Can be used in the following locations:
*
* - Arguments of server-side
@RestOp -annotated methods.
* - Methods and return types of server-side and client-side
@Response -annotated interfaces.
*
*
* Arguments of server-side @RestOp -annotated methods
*
*
* On server-side REST, this annotation can be applied to method parameters to identify them as an HTTP response value.
*
*
Example:
*
* @RestPost
* public void addPet(@Content Pet pet , @StatusCode Value<Integer> status ) {
* addPet (pet );
* status .set(200);
* }
*
*
*
* The parameter type must be {@link Value} with a parameterized type of {@link Integer}.
*
*
Public methods of @Response -annotated types
*
*
* On {@link Response @Response}-annotated classes, this method can be used to denote an HTTP status code on a response.
*
*
Example:
*
* @RestPost
* public Success addPet(Pet pet ) {
* addPet (pet );
* return new Success();
* }
*
*
*
* @Response
* public class Success {
*
* @StatusCode
* public int getStatus() {
* return 201;
* }
*
* @Override
* public String toString() {
* return "Pet was successfully added" ;
* }
* }
*
*
*
* The method being annotated must be public and return a numeric value.
*
*
*
See Also:
* - Swagger
*
*
* Methods and return types of server-side and client-side @Response-annotated interfaces
*
* See Also:
* - @Response
*
*
*
*
See Also:
*
*/
@Documented
@Target({PARAMETER,METHOD,TYPE})
@Retention(RUNTIME)
@Inherited
@Repeatable(StatusCodeAnnotation.Array.class)
@ContextApply(StatusCodeAnnotation.Applier.class)
public @interface StatusCode {
/**
* Dynamically apply this annotation to the specified classes.
*
* See Also:
*
* @return The annotation value.
*/
String[] on() default {};
/**
* Dynamically apply this annotation to the specified classes.
*
*
* Identical to {@link #on()} except allows you to specify class objects instead of a strings.
*
*
See Also:
*
* @return The annotation value.
*/
Class>[] onClass() default {};
/**
* The HTTP response codes.
*
* The default value is 500 for exceptions and 200 for return types.
*
* @return The annotation value.
*/
int[] value() default {};
}