org.apache.juneau.rest.annotation.FormData 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.lang.annotation.*;
import org.apache.juneau.rest.*;
/**
* Annotation that can be applied to a parameter of a {@link RestMethod} annotated method to identify it as a form post
* entry converted to a POJO.
*
* Example:
*
* @RestMethod (name=POST )
* public void doPost(RestRequest req, RestResponse res,
* @FormData ("p1" ) int p1, @FormData ("p2" ) String p2, @FormData ("p3" ) UUID p3) {
* ...
* }
*
*
*
* This is functionally equivalent to the following code...
*
* @RestMethod (name=POST )
* public void doPost(RestRequest req, RestResponse res) {
* int p1 = req.getFormData(int .class , "p1" , 0);
* String p2 = req.getFormData(String.class , "p2" );
* UUID p3 = req.getFormData(UUID.class , "p3" );
* ...
* }
*
*
* Important note concerning FORM posts
*
* This annotation should not be combined with the {@link Body @Body} annotation or {@link RestRequest#getBody()} method
* for application/x-www-form-urlencoded POST
posts, since it will trigger the underlying servlet
* API to parse the body content as key-value pairs resulting in empty content.
*
*
* The {@link Query @Query} annotation can be used to retrieve a URL parameter in the URL string without triggering the
* servlet to drain the body content.
*/
@Documented
@Target(PARAMETER)
@Retention(RUNTIME)
@Inherited
public @interface FormData {
/**
* FORM parameter name.
*/
String name() default "";
/**
* A synonym for {@link #name()}.
*
*
* Allows you to use shortened notation if you're only specifying the name.
*/
String value() default "";
/**
* Specify true if using multi-part parameters to represent collections and arrays.
*
*
* Normally, we expect single parameters to be specified in UON notation for representing collections of values
* (e.g. "key=(1,2,3)" .
* This annotation allows the use of multi-part parameters to represent collections (e.g.
* "key=1&key=2&key=3" .
*
*
* This setting should only be applied to Java parameters of type array or Collection.
*/
boolean multipart() default false;
/**
* The expected format of the request parameter.
*
*
* Possible values:
*
* -
*
"UON" - URL-Encoded Object Notation.
*
This notation allows for request parameters to contain arbitrarily complex POJOs.
* -
*
"PLAIN" - Plain text.
*
This treats request parameters as plain text.
*
Only POJOs directly convertible from Strings can be represented in parameters when using this mode.
* -
*
"INHERIT" (default) - Inherit from the {@link RestResource#paramFormat()} property on the
* servlet method or class.
*
*
*
* Note that the parameter value "(foo)" is interpreted as "(foo)" when using plain mode, but
* "foo" when using UON mode.
*/
String format() default "INHERIT";
/**
* The default value for this form-data parameter if it's not present in the request.
*/
String def() default "";
}