org.apache.juneau.remoteable.Query 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 QUERY parameters on the
* request.
*
* Example:
*
* @Remoteable (path="/myproxy" )
* public interface MyProxy {
*
* // Explicit names specified for query parameters.
* // pojo will be converted to UON notation (unless plain-text parts enabled).
* @RemoteMethod (path="/mymethod1" )
* String myProxyMethod1(@Query ("foo" ) String foo,
* @Query ("bar" ) MyPojo pojo);
*
* // Multiple values pulled from a NameValuePairs object.
* // Same as @Query("*").
* @RemoteMethod (path="/mymethod2" )
* String myProxyMethod2(@Query NameValuePairs nameValuePairs);
*
* // Multiple values pulled from a Map.
* // Same as @Query("*").
* @RemoteMethod (path="/mymethod3" )
* String myProxyMethod3(@Query Map<String,Object> map);
*
* // Multiple values pulled from a bean.
* // Same as @Query("*").
* @RemoteMethod (path="/mymethod4" )
* String myProxyMethod4(@Query MyBean myBean);
*
* // An entire query string as a String.
* // Same as @FQuery("*").
* @RemoteMethod (path="/mymethod5" )
* String myProxyMethod5(@Query String string);
*
* // An entire query string as a Reader.
* // Same as @Query("*").
* @RemoteMethod (path="/mymethod6" )
* String myProxyMethod6(@Query 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.
* @Query ("foo" )
* String getX();
*
* // Name inherited from bean property.
* // Same as @Query("bar")
* @Query
* String getBar();
*
* // Name inherited from bean property.
* // Same as @Query("baz")
* @Query
* @BeanProperty ("baz" )
* String getY();
*
* // Multiple values pulled from NameValuePairs object.
* // Same as @Query("*")
* @Query
* NameValuePairs getNameValuePairs();
*
* // Multiple values pulled from Map.
* // Same as @Query("*")
* @Query
* Map<String,Object> getMap();
*
* // Multiple values pulled from bean.
* // Same as @Query("*")
* @Query
* MyBean getMyBean();
*
* // An entire query string as a Reader.
* // Same as @Query("*")
* @Query
* 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:
*
* @Query (name="foo" )
*
* @Query ("foo" )
*
*
* Additional Information
*
*/
@Documented
@Target({PARAMETER,FIELD,METHOD})
@Retention(RUNTIME)
@Inherited
public @interface Query {
/**
* The query 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
* query 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 @Query("*")
* @RemoteMethod (path="/mymethod" )
* String myProxyMethod1(@Query Map<String,Object> formData);
* }
*
* // When used on a request bean method
* public interface MyRequestBean {
*
* // Equivalent to @Query("*")
* @Query
* Map<String,Object> getFoo();
* }
*
*
* -
* If used on a request bean method, uses the bean property name.
*
*
Example:
*
* public interface MyRequestBean {
*
* // Equivalent to @Query("foo")
* @Query
* 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;
}