org.apache.juneau.remoteable.Path 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 path variables on the request.
*
* Example:
*
* @Remoteable (path="/myproxy" )
* public interface MyProxy {
*
* // Explicit names specified for path parameters.
* // pojo will be converted to UON notation (unless plain-text parts enabled).
* @RemoteMethod (path="/mymethod1/{foo}/{bar}" )
* String myProxyMethod1(@Path ("foo" ) String foo, @Path ("bar" ) MyPojo pojo);
*
* // Multiple values pulled from a NameValuePairs object.
* // Same as @Path("*").
* @RemoteMethod (path="/mymethod2/{foo}/{bar}/{baz}" )
* String myProxyMethod2(@Path NameValuePairs nameValuePairs);
*
* // Multiple values pulled from a Map.
* // Same as @Path("*").
* @RemoteMethod (path="/mymethod3/{foo}/{bar}/{baz}" )
* String myProxyMethod3(@Path Map<String,Object> map);
*
* // Multiple values pulled from a bean.
* // Same as @Path("*").
* @RemoteMethod (path="/mymethod4/{foo}/{bar}/{baz}" )
* String myProxyMethod4(@Path MyBean myBean);
* }
*
*
*
* 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/{foo}/{bar}/{baz}" )
* String myProxyMethod(@RequestBean MyRequestBean bean);
* }
*
* public interface MyRequestBean {
*
* // Name explicitly specified.
* @Path ("foo" )
* String getX();
*
* // Name inherited from bean property.
* // Same as @Path("bar")
* @Path
* String getBar();
*
* // Name inherited from bean property.
* // Same as @Path("baz")
* @Path
* @BeanProperty ("baz" )
* String getY();
*
* // Multiple values pulled from NameValuePairs object.
* // Same as @Path("*")
* @Path
* NameValuePairs getNameValuePairs();
*
* // Multiple values pulled from Map.
* // Same as @Path("*")
* @Path
* Map<String,Object> getMap();
*
* // Multiple values pulled from bean.
* // Same as @Path("*")
* @Path
* MyBean getMyBean();
* }
*
*
*
* The {@link #name()} and {@link #value()} elements are synonyms for specifying the path variable name.
* Only one should be used.
*
The following annotations are fully equivalent:
*
* @Path (name="foo" )
*
* @Path ("foo" )
*
*
* Additional Information
*
*/
@Documented
@Target({PARAMETER,FIELD,METHOD})
@Retention(RUNTIME)
@Inherited
public @interface Path {
/**
* The path 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
* path variable 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 treated as name/value pairs.
*
* Example:
*
* // When used on a remote method parameter
* @Remoteable (path="/myproxy" )
* public interface MyProxy {
*
* // Equivalent to @Path("*")
* @RemoteMethod (path="/mymethod/{foo}/{bar}" )
* String myProxyMethod1(@FormData Map<String,Object> pathVars);
* }
*
* // When used on a request bean method
* public interface MyRequestBean {
*
* // Equivalent to @Path("*")
* @Path
* Map<String,Object> getPathVars();
* }
*
*
* -
* If used on a request bean method, uses the bean property name.
*
*
Example:
*
* public interface MyRequestBean {
*
* // Equivalent to @Path("foo")
* @Path
* 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 "";
/**
* 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;
}