org.apache.juneau.remoteable.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.remoteable;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.*;
import java.lang.annotation.*;
import org.apache.juneau.serializer.*;
import org.apache.juneau.urlencoding.*;
/**
* Annotation applied to Java method arguments of interface proxies to denote that they are FORM post parameters on the
* request.
*
* Example:
*
* @Remoteable (path="/myproxy" )
* public interface MyProxy {
*
* // Explicit names specified for form data parameters.
* // pojo will be converted to UON notation (unless plain-text parts enabled).
* @RemoteMethod (path="/mymethod1" )
* String myProxyMethod1(@FormData ("foo" ) String foo,
* @FormData ("bar" ) MyPojo pojo);
*
* // Multiple values pulled from a NameValuePairs object.
* // Same as @FormData("*").
* @RemoteMethod (path="/mymethod2" )
* String myProxyMethod2(@FormData NameValuePairs nameValuePairs);
*
* // Multiple values pulled from a Map.
* // Same as @FormData("*").
* @RemoteMethod (path="/mymethod3" )
* String myProxyMethod3(@FormData Map<String,Object> map);
*
* // Multiple values pulled from a bean.
* // Same as @FormData("*").
* @RemoteMethod (path="/mymethod4" )
* String myProxyMethod4(@FormData MyBean myBean);
*
* // An entire form-data HTTP body as a String.
* // Same as @FormData("*").
* @RemoteMethod (path="/mymethod5" )
* String myProxyMethod5(@FormData String string);
*
* // An entire form-data HTTP body as a Reader.
* // Same as @FormData("*").
* @RemoteMethod (path="/mymethod6" )
* String myProxyMethod6(@FormData Reader reader);
*
* }
*
*
*
* The annotation can also be applied to a bean property field or getter when the argument is annotated with
* {@link RequestBean @RequestBean}:
*
*
Example:
*
* @Remoteable (path="/myproxy" )
* public interface MyProxy {
*
* @RemoteMethod (path="/mymethod" )
* String myProxyMethod(@RequestBean MyRequestBean bean);
* }
*
* public interface MyRequestBean {
*
* // Name explicitly specified.
* @FormData ("foo" )
* String getX();
*
* // Name inherited from bean property.
* // Same as @FormData("bar")
* @FormData
* String getBar();
*
* // Name inherited from bean property.
* // Same as @FormData("baz")
* @FormData
* @BeanProperty ("baz" )
* String getY();
*
* // Multiple values pulled from NameValuePairs object.
* // Same as @FormData("*")
* @FormData
* NameValuePairs getNameValuePairs();
*
* // Multiple values pulled from Map.
* // Same as @FormData("*")
* @FormData
* Map<String,Object> getMap();
*
* // Multiple values pulled from bean.
* // Same as @FormData("*")
* @FormData
* MyBean getMyBean();
*
* // An entire form-data HTTP body as a Reader.
* // Same as @FormData("*")
* @FormData
* Reader getReader();
* }
*
*
*
* The {@link #name()} and {@link #value()} elements are synonyms for specifying the parameter name.
* Only one should be used.
*
The following annotations are fully equivalent:
*
* @FormData (name="foo" )
*
* @FormData ("foo" )
*
*
* Additional Information
*
*/
@Documented
@Target({PARAMETER,FIELD,METHOD})
@Retention(RUNTIME)
@Inherited
public @interface FormData {
/**
* The form post parameter name.
*
*
* Note that {@link #name()} and {@link #value()} are synonyms.
*
*
* The value should be either "*" to represent multiple name/value pairs, or a label that defines the
* form data parameter name.
*
*
* A blank value (the default) has the following behavior:
*
* -
* If the data type is
NameValuePairs
, Map
, or a bean,
* then it's the equivalent to "*" which will cause the value to be serialized as name/value pairs.
*
* Example:
*
* // When used on a remote method parameter
* @Remoteable (path="/myproxy" )
* public interface MyProxy {
*
* // Equivalent to @FormData("*")
* @RemoteMethod (path="/mymethod" )
* String myProxyMethod1(@FormData Map<String,Object> formData);
* }
*
* // When used on a request bean method
* public interface MyRequestBean {
*
* // Equivalent to @FormData("*")
* @FormData
* Map<String,Object> getFoo();
* }
*
*
* -
* If used on a request bean method, uses the bean property name.
*
*
Example:
*
* public interface MyRequestBean {
*
* // Equivalent to @FormData("foo")
* @FormData
* String getFoo();
* }
*
*
*
*/
String name() default "";
/**
* A synonym for {@link #name()}.
*
*
* Allows you to use shortened notation if you're only specifying the name.
*/
String value() default "";
/**
* Skips this value if it's an empty string or empty collection/array.
*
*
* Note that null values are already ignored.
*/
boolean skipIfEmpty() default false;
/**
* Specifies the {@link PartSerializer} class used for serializing values to strings.
*
*
* The default value defaults to the using the part serializer defined on the {@link RequestBean} annotation,
* then on the client which by default is {@link UrlEncodingSerializer}.
*
*
* This annotation is provided to allow values to be custom serialized.
*/
Class extends PartSerializer> serializer() default PartSerializer.class;
}