Class RestOpContext.Builder
- Enclosing class:
RestOpContext
-
Method Summary
Modifier and TypeMethodDescriptionannotations
(Annotation... values) Defines annotations to apply to specific classes and methods.apply
(AnnotationWorkList work) Applies a set of applied to this builder.applyAnnotations
(Class<?>... fromClasses) Applies any of the various@XConfig annotations on the specified class to this context.applyAnnotations
(Method... fromMethods) Applies any of the various@XConfig annotations on the specified method to this context.Returns the bean context sub-builder.Returns access to the bean store being used by this builder.Adds a bean to the bean store of this operation.Adds a bean to the bean store of this operation.protected RestOpContext.Builder
Specifies aBeanStore
to use when resolving constructor arguments.build()
Build the object.Specifies a cache to use for hashkey-based caching.clientVersion
(String value) Client version pattern matcher.Supported content media types.Returns the response converter list sub-builder.final RestOpContext.Builder
converters
(Class<? extends RestConverter>... value) Adds one or more converters to use to convert response objects for this operation.converters
(RestConverter... value) Adds one or more converters to this operation.copy()
Copy creator.protected BeanContext.Builder
createBeanContext
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the bean context sub-builder.protected RestConverterList.Builder
createConverters
(BeanStore beanStore, Supplier<?> resource) Instantiates the response converter list sub-builder.protected NamedAttributeMap
createDefaultRequestAttributes
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request attributes sub-builder.protected PartList
createDefaultRequestFormData
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request form data.protected HeaderList
createDefaultRequestHeaders
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request headers.protected PartList
createDefaultRequestQueryData
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request query data.protected HeaderList
createDefaultResponseHeaders
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default response headers.protected EncoderSet.Builder
createEncoders
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the encoder group sub-builder.protected RestGuardList.Builder
createGuards
(BeanStore beanStore, Supplier<?> resource) Instantiates the guard list sub-builder.protected JsonSchemaGenerator.Builder
createJsonSchemaGenerator
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the JSON schema generator sub-builder.protected RestMatcherList.Builder
createMatchers
(BeanStore beanStore, Supplier<?> resource) Instantiates the matcher list sub-builder.protected ParserSet.Builder
createParsers
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the parser group sub-builder.protected HttpPartParser.Creator
createPartParser
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the part parser sub-builder.protected HttpPartSerializer.Creator
createPartSerializer
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the part serializer sub-builder.protected SerializerSet.Builder
createSerializers
(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the serializer group sub-builder.debug()
Context configuration property: Debug mode.debug
(boolean value) Same asContext.Builder.debug()
but allows you to explicitly specify the value.debug
(Enablement value) Debug mode.defaultCharset
(Charset value) Default character encoding.Returns the default classes list.Returns the default request attributes sub-builder.defaultRequestAttributes
(NamedAttribute... value) Adds one or more default request attributes to this operation.Returns the default request form data.defaultRequestFormData
(NameValuePair... value) Adds one or more default request form data to this operation.Returns the default request headers.defaultRequestHeaders
(Header... value) Adds one or more default request headers to this operation.Returns the default request query data.defaultRequestQueryData
(NameValuePair... value) Adds one or more default request query data to this operation.Returns the default response headers.defaultResponseHeaders
(Header... value) Adds one or more default response headers to this operation.dotAll()
When enabled, append"/*" to path patterns if not already present.encoders()
Returns the encoder group sub-builder.final RestOpContext.Builder
Adds one or more encoders to this operation.Adds one or more encoders to this operation.protected Class<? extends RestOpContext>
Specifies the default implementation class if not specified viatype(Class)
.protected UrlPathMatcherList
Instantiates the path matchers for this method.guards()
Returns the guard list sub-builder.final RestOpContext.Builder
Adds one or more guards to this operation.Adds one or more guards to this operation.httpMethod
(String value) HTTP method name.Specifies a pre-instantiated bean for theContext.Builder.build()
method to return.Returns the JSON schema generator sub-builder.jsonSchemaGenerator
(Class<? extends JsonSchemaGenerator> value) Specifies the JSON schema generator for this operation.Specifies the JSON schema generator for this operation.matchers()
Returns the matcher list sub-builder.final RestOpContext.Builder
matchers
(Class<? extends RestMatcher>... value) Adds one or more matchers to this operation.matchers
(RestMatcher... value) Adds one or more matchers to this operation.The maximum allowed input size (in bytes) on HTTP requests.parsers()
Returns the parser group sub-builder.final RestOpContext.Builder
Adds one or more parsers to this operation.Adds one or more parsers to this operation.Returns the part parser sub-builder.partParser
(Class<? extends HttpPartParser> value) Specifies the part parser to use for parsing HTTP parts for this operation.partParser
(HttpPartParser value) Specifies the part parser to use for parsing HTTP parts for this operation.Returns the part serializer sub-builder.partSerializer
(Class<? extends HttpPartSerializer> value) Specifies the part serializer to use for serializing HTTP parts for this operation.partSerializer
(HttpPartSerializer value) Specifies the part serializer to use for serializing HTTP parts for this operation.Resource method paths.protected void
Handles processing of any annotations on parameters.Supported accept media types.Supplier<?>
resource()
Returns the REST servlet/bean instance that this context is defined against.Role guard.rolesDeclared
(String... values) Declared roles.Returns the serializer group sub-builder.final RestOpContext.Builder
serializers
(Class<? extends Serializer>... value) Adds one or more serializers to this operation.serializers
(Serializer... value) Adds one or more serializers to this operation.Associates a context class with this builder.Methods inherited from class org.apache.juneau.Context.Builder
apply, build, canApply, env, env, getApplied, getType, hashKey, isDebug, registerBuilders
-
Method Details
-
copy
Description copied from class:Context.Builder
Copy creator.- Specified by:
copy
in classContext.Builder
- Returns:
- A new mutable copy of this builder.
-
build
Description copied from class:Context.Builder
Build the object.- Overrides:
build
in classContext.Builder
- Returns:
- The built object.
-
getDefaultImplClass
Specifies the default implementation class if not specified viatype(Class)
.- Returns:
- The default implementation class if not specified via
type(Class)
.
-
resource
Returns the REST servlet/bean instance that this context is defined against.- Returns:
- The REST servlet/bean instance that this context is defined against.
-
defaultClasses
Returns the default classes list.This defines the implementation classes for a variety of bean types.
Default classes are inherited from the parent REST object. Typically used on the top-level
RestContext.Builder
to affect class types for that REST object and all children.Modifying the default class list on this builder does not affect the default class list on the parent builder, but changes made here are inherited by child builders.
- Returns:
- The default classes list for this builder.
-
beanStore
Returns access to the bean store being used by this builder.Can be used to add more beans to the bean store.
- Returns:
- The bean store being used by this builder.
-
beanStore
Specifies aBeanStore
to use when resolving constructor arguments.- Parameters:
beanStore
- The bean store to use for resolving constructor arguments.- Returns:
- This object.
-
beanStore
Adds a bean to the bean store of this operation.Equivalent to calling:
builder .beanStore().add(beanType ,bean );- Type Parameters:
T
- The class to associate this bean with.- Parameters:
beanType
- The class to associate this bean with.bean
- The bean. Can benull .- Returns:
- This object.
-
beanStore
Adds a bean to the bean store of this operation.Equivalent to calling:
builder .beanStore().add(beanType ,bean ,name );- Type Parameters:
T
- The class to associate this bean with.- Parameters:
beanType
- The class to associate this bean with.bean
- The bean. Can benull .name
- The bean name if this is a named bean. Can benull .- Returns:
- This object.
-
beanContext
Returns the bean context sub-builder.- Returns:
- The bean context sub-builder.
-
createBeanContext
protected BeanContext.Builder createBeanContext(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the bean context sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new bean context sub-builder.
-
encoders
Returns the encoder group sub-builder.- Returns:
- The encoder group sub-builder.
-
encoders
Adds one or more encoders to this operation.Equivalent to calling:
builder .encoders().add(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
encoders
Adds one or more encoders to this operation.Equivalent to calling:
builder .encoders().add(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createEncoders
protected EncoderSet.Builder createEncoders(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the encoder group sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new encoder group sub-builder.
-
serializers
Returns the serializer group sub-builder.- Returns:
- The serializer group sub-builder.
-
serializers
Adds one or more serializers to this operation.Equivalent to calling:
builder .serializers().add(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
serializers
Adds one or more serializers to this operation.Equivalent to calling:
builder .serializers().add(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createSerializers
protected SerializerSet.Builder createSerializers(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the serializer group sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new serializer group sub-builder.
-
parsers
Returns the parser group sub-builder.- Returns:
- The parser group sub-builder.
-
parsers
Adds one or more parsers to this operation.Equivalent to calling:
builder .parsers().add(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
parsers
Adds one or more parsers to this operation.Equivalent to calling:
builder .parsers().add(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createParsers
protected ParserSet.Builder createParsers(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the parser group sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new parser group sub-builder.
-
partSerializer
Returns the part serializer sub-builder.- Returns:
- The part serializer sub-builder.
-
partSerializer
Specifies the part serializer to use for serializing HTTP parts for this operation.Equivalent to calling:
builder .partSerializer().type(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
partSerializer
Specifies the part serializer to use for serializing HTTP parts for this operation.Equivalent to calling:
builder .partSerializer().impl(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
createPartSerializer
protected HttpPartSerializer.Creator createPartSerializer(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the part serializer sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new part serializer sub-builder.
-
partParser
Returns the part parser sub-builder.- Returns:
- The part parser sub-builder.
-
partParser
Specifies the part parser to use for parsing HTTP parts for this operation.Equivalent to calling:
builder .partParser().type(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
partParser
Specifies the part parser to use for parsing HTTP parts for this operation.Equivalent to calling:
builder .partParser().impl(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
createPartParser
protected HttpPartParser.Creator createPartParser(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the part parser sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new part parser sub-builder.
-
jsonSchemaGenerator
Returns the JSON schema generator sub-builder.- Returns:
- The JSON schema generator sub-builder.
-
jsonSchemaGenerator
Specifies the JSON schema generator for this operation.Equivalent to calling:
builder .jsonSchemaGenerator().type(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
jsonSchemaGenerator
Specifies the JSON schema generator for this operation.Equivalent to calling:
builder .jsonSchemaGenerator().impl(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
createJsonSchemaGenerator
protected JsonSchemaGenerator.Builder createJsonSchemaGenerator(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the JSON schema generator sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new JSON schema generator sub-builder.
-
converters
Returns the response converter list sub-builder.- Returns:
- The response converter list sub-builder.
-
converters
Adds one or more converters to use to convert response objects for this operation.Equivalent to calling:
builder .converters().append(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
converters
Adds one or more converters to this operation.Equivalent to calling:
builder .converters().append(value );- Parameters:
value
- The new value.- Returns:
- This object.
-
createConverters
Instantiates the response converter list sub-builder.Associates one or more
converters
with a resource class.
These converters get called immediately after execution of the REST method in the same order specified in the annotation.
The object passed into this converter is the object returned from the Java method or passed into theRestResponse.setContent(Object)
method.Can be used for performing post-processing on the response object before serialization.
When multiple converters are specified, they're executed in the order they're specified in the annotation (e.g. first the results will be traversed, then the resulting node will be searched/sorted).
Example:
// Our converter. public class MyConverterimplements RestConverter {@Override public Object convert(RestRequestreq , Objectobject ) {// Do something with object and return another object. // Or just return the same object for a no-op. } }// Option #1 - Registered via annotation resolving to a config file setting with default value. @Rest (converters={MyConverter.class })public class MyResource {// Option #2 - Registered via builder passed in through resource constructor. public MyResource(RestContext.Builderbuilder )throws Exception {// Using method on builder. builder .converters(MyConverter.class );// Pass in an instance instead. builder .converters(new MyConverter()); }// Option #3 - Registered via builder passed in through init method. @RestInit public void init(RestContext.Builderbuilder )throws Exception {builder .converters(MyConverter.class ); } }Notes:
-
When defined as a class, the implementation must have one of the following constructors:
public T(BeanContext)public T()public static Tcreate (RestContext)public static Tcreate ()
- Inner classes of the REST resource class are allowed.
See Also:
Traversable
- Allows URL additional path info to address individual elements in a POJO tree.Queryable
- Allows query/view/sort functions to be performed on POJOs.Introspectable
- Allows Java public methods to be invoked on the returned POJOs.Rest.converters()
- Converters
- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new response converter list sub-builder.
-
When defined as a class, the implementation must have one of the following constructors:
-
guards
Returns the guard list sub-builder.- Returns:
- The guard list sub-builder.
-
guards
Adds one or more guards to this operation.Equivalent to calling:
builder .guards().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
guards
Adds one or more guards to this operation.Equivalent to calling:
builder .guards().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createGuards
Instantiates the guard list sub-builder.Instantiates based on the following logic:
- Looks for guards set via any of the following:
- Looks for a static or non-static
createGuards() method that returns on the resource class with any of the following arguments:RestGuard
[]Method
- The Java method this context belongs to.RestContext
BeanStore
- Any injected beans.
- Resolves it via the bean store registered in this context.
- Instantiates a
RestGuard[0] .
- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new guard list sub-builder.
-
matchers
Returns the matcher list sub-builder.- Returns:
- The matcher list sub-builder.
-
matchers
Adds one or more matchers to this operation.Equivalent to calling:
builder .matchers().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
matchers
Adds one or more matchers to this operation.Equivalent to calling:
builder .matchers().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createMatchers
Instantiates the matcher list sub-builder.Associates one or more
RestMatchers
with the specified method.If multiple matchers are specified, ONE matcher must pass.
Note that this is different than guards where ALL guards needs to pass.Notes:
-
When defined as a class, the implementation must have one of the following constructors:
public T(RestContext)public T()public static Tcreate (RestContext)public static Tcreate ()
- Inner classes of the REST resource class are allowed.
See Also:
Instantiates based on the following logic:
- Looks for matchers set via any of the following:
- Looks for a static or non-static
createMatchers() method that returns on the resource class with any of the following arguments:RestMatcher
[]Method
- The Java method this context belongs to.RestContext
BeanStore
- Any injected beans.
- Resolves it via the bean store registered in this context.
- Instantiates a
RestMatcher[0] .
- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new matcher list sub-builder.
-
When defined as a class, the implementation must have one of the following constructors:
-
getPathMatchers
Instantiates the path matchers for this method.- Returns:
- The path matchers for this method.
-
dotAll
When enabled, append"/*" to path patterns if not already present.- Returns:
- This object.
-
defaultRequestHeaders
Returns the default request headers.- Returns:
- The default request headers.
-
defaultRequestHeaders
Adds one or more default request headers to this operation.Equivalent to calling:
builder .defaultRequestHeaders().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createDefaultRequestHeaders
protected HeaderList createDefaultRequestHeaders(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request headers.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new default request headers sub-builder.
-
defaultResponseHeaders
Returns the default response headers.- Returns:
- The default response headers.
-
defaultResponseHeaders
Adds one or more default response headers to this operation.Equivalent to calling:
builder .defaultResponseHeaders().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createDefaultResponseHeaders
protected HeaderList createDefaultResponseHeaders(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default response headers.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new default response headers sub-builder.
-
defaultRequestAttributes
Returns the default request attributes sub-builder.- Returns:
- The default request attributes sub-builder.
-
defaultRequestAttributes
Adds one or more default request attributes to this operation.Equivalent to calling:
builder .defaultRequestAttributes().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createDefaultRequestAttributes
protected NamedAttributeMap createDefaultRequestAttributes(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request attributes sub-builder.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new default request attributes sub-builder.
-
defaultRequestQueryData
Returns the default request query data.- Returns:
- The default request query data.
-
defaultRequestQueryData
Adds one or more default request query data to this operation.Equivalent to calling:
builder .defaultRequestQueryData().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createDefaultRequestQueryData
protected PartList createDefaultRequestQueryData(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request query data.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new default request query data sub-builder.
-
defaultRequestFormData
Returns the default request form data.- Returns:
- The default request form data.
-
defaultRequestFormData
Adds one or more default request form data to this operation.Equivalent to calling:
builder .defaultRequestFormData().append(value );- Parameters:
value
- The values to add.- Returns:
- This object.
-
createDefaultRequestFormData
protected PartList createDefaultRequestFormData(BeanStore beanStore, RestContext.Builder parent, Supplier<?> resource) Instantiates the default request form data.- Parameters:
beanStore
- The factory used for creating beans and retrieving injected beans.parent
- The builder for the REST resource class.resource
- The REST servlet/bean instance that this context is defined against.- Returns:
- A new default request form data sub-builder.
-
processParameterAnnotations
-
clientVersion
Client version pattern matcher.Specifies whether this method can be called based on the client version.
The client version is identified via the HTTP request header identified by
@Rest(clientVersionHeader)
which by default is"Client-Version" .This is a specialized kind of
RestMatcher
that allows you to invoke different Java methods for the same method/path based on the client version.The format of the client version range is similar to that of OSGi versions.
In the following example, the Java methods are mapped to the same HTTP method and URL
"/foobar" .// Call this method if Client-Version is at least 2.0. // Note that this also matches 2.0.1. @RestGet (path="/foobar" , clientVersion="2.0" )public Object method1() {...}// Call this method if Client-Version is at least 1.1, but less than 2.0. @RestGet (path="/foobar" , clientVersion="[1.1,2.0)" )public Object method2() {...}// Call this method if Client-Version is less than 1.1. @RestGet (path="/foobar" , clientVersion="[0,1.1)" )public Object method3() {...}It's common to combine the client version with transforms that will convert new POJOs into older POJOs for backwards compatibility.
// Call this method if Client-Version is at least 2.0. @RestGet (path="/foobar" , clientVersion="2.0" )public NewPojo newMethod() {...}// Call this method if Client-Version is at least 1.1, but less than 2.0. @RestGet (path="/foobar" , clientVersion="[1.1,2.0)" )@BeanConfig(swaps=NewToOldSwap. class )public NewPojo oldMethod() {return newMethod(); }Note that in the previous example, we're returning the exact same POJO, but using a transform to convert it into an older form. The old method could also just return back a completely different object. The range can be any of the following:
"[0,1.0)" = Less than 1.0. 1.0 and 1.0.0 does not match."[0,1.0]" = Less than or equal to 1.0. Note that 1.0.1 will match."1.0" = At least 1.0. 1.0 and 2.0 will match.
See Also:
- Parameters:
value
- The new value for this setting.- Returns:
- This object.
-
debug
Debug mode.Enables the following:
- HTTP request/response bodies are cached in memory for logging purposes.
If not sppecified, the debug enablement is inherited from the class context.
- Parameters:
value
- The new value for this setting.- Returns:
- This object.
-
defaultCharset
Default character encoding.The default character encoding for the request and response if not specified on the request.
This overrides the value defined on the
RestContext
.See Also:
- Parameters:
value
- The new value for this setting.
The default is the first value found:- System property
"RestContext.defaultCharset" - Environment variable
"RESTCONTEXT_defaultCharset" "utf-8" - Environment variable
- System property
- Returns:
- This object.
-
httpMethod
HTTP method name.Typically
"GET" ,"PUT" ,"POST" ,"DELETE" , or"OPTIONS" .Method names are case-insensitive (always folded to upper-case).
Note that you can use
HttpMethod
for constant values.Besides the standard HTTP method names, the following can also be specified:
-
"*" - Denotes any method.
Use this if you want to capture any HTTP methods in a single Java method.
The@Method
annotation and/orRestRequest.getMethod()
method can be used to distinguish the actual HTTP method name. -
"" - Auto-detect.
The method name is determined based on the Java method name.
For example, if the method isdoPost(...) , then the method name is automatically detected as"POST" .
Otherwise, defaults to"GET" . -
"RRPC" - Remote-proxy interface.
This denotes a Java method that returns an object (usually an interface, often annotated with the@Remote
annotation) to be used as a remote proxy usingRestClient.getRemoteInterface(Class<T> interfaceClass, String url) .
This allows you to construct client-side interface proxies using REST as a transport medium.
Conceptually, this is simply a fancyPOST against the url"/{path}/{javaMethodName}" where the arguments are marshalled from the client to the server as an HTTP content containing an array of objects, passed to the method as arguments, and then the resulting object is marshalled back to the client. -
Anything else
- Overloaded non-HTTP-standard names that are passed in through a
&method=methodName URL parameter.
See Also:
- Parameters:
value
- The new value for this setting.- Returns:
- This object.
-
-
maxInput
The maximum allowed input size (in bytes) on HTTP requests.Useful for alleviating DoS attacks by throwing an exception when too much input is received instead of resulting in out-of-memory errors which could affect system stability.
Example:
// Option #1 - Defined via annotation resolving to a config file setting with default value. @Rest (maxInput="$C{REST/maxInput,10M}" )public class MyResource {// Option #2 - Defined via builder passed in through resource constructor. public MyResource(RestContext.Builderbuilder )throws Exception {// Using method on builder. builder .maxInput("10M" ); }// Option #3 - Defined via builder passed in through init method. @RestInit public void init(RestContext.Builderbuilder )throws Exception {builder .maxInput("10M" ); }// Override at the method level. @RestPost (maxInput="10M" )public Object myMethod() {...} }Notes:
-
String value that gets resolved to a
long . -
Can be suffixed with any of the following representing kilobytes, megabytes, and gigabytes:
'K' ,'M' ,'G' . -
A value of
"-1" can be used to represent no limit.
See Also:
- Parameters:
value
- The new value for this setting.
The default is the first value found:- System property
"RestContext.maxInput" - Environment variable
"RESTCONTEXT_MAXINPUT" "100M" - Environment variable
The default is"100M" .- System property
- Returns:
- This object.
-
String value that gets resolved to a
-
path
Resource method paths.Identifies the URL subpath relative to the servlet class.
Notes:
- This method is only applicable for Java methods.
-
Slashes are trimmed from the path ends.
As a convention, you may want to start your path with'/' simple because it make it easier to read.
- Parameters:
values
- The new values for this setting.- Returns:
- This object.
-
produces
Supported accept media types.Overrides the media types inferred from the serializers that identify what media types can be produced by the resource.
An example where this might be useful if you have serializers registered that handle media types that you don't want exposed in the Swagger documentation.This affects the returned values from the following:
RestContext.getProduces()
SwaggerProvider.getSwagger(RestContext,Locale)
- Affects produces field.
See Also:
- Parameters:
values
- The values to add to this setting.- Returns:
- This object.
-
rolesDeclared
Declared roles.A comma-delimited list of all possible user roles.
Used in conjunction with
roleGuard(String)
is used with patterns.Example:
@Rest ( rolesDeclared="ROLE_ADMIN,ROLE_READ_WRITE,ROLE_READ_ONLY,ROLE_SPECIAL" , roleGuard="ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)" )public class MyResourceextends BasicRestServlet { ... }See Also:
- Parameters:
values
- The values to add to this setting.- Returns:
- This object.
-
roleGuard
Role guard.An expression defining if a user with the specified roles are allowed to access methods on this class.
Example:
@Rest ( path="/foo" , roleGuard="ROLE_ADMIN || (ROLE_READ_WRITE && ROLE_SPECIAL)" )public class MyResourceextends BasicRestServlet { ... }Notes:
-
Supports any of the following expression constructs:
"foo" - Single arguments."foo,bar,baz" - Multiple OR'ed arguments."foo | bar | bqz" - Multiple OR'ed arguments, pipe syntax."foo || bar || bqz" - Multiple OR'ed arguments, Java-OR syntax."fo*" - Patterns including'*' and'?' ."fo* & *oo" - Multiple AND'ed arguments, ampersand syntax."fo* && *oo" - Multiple AND'ed arguments, Java-AND syntax."fo* || (*oo || bar)" - Parenthesis.
- AND operations take precedence over OR operations (as expected).
- Whitespace is ignored.
-
null or empty expressions always match asfalse . -
If patterns are used, you must specify the list of declared roles using
Rest.rolesDeclared()
orrolesDeclared(String...)
. -
Supports SVL Variables
(e.g.
"$L{my.localized.variable}" ).
- Parameters:
value
- The values to add to this setting.- Returns:
- This object.
-
Supports any of the following expression constructs:
-
consumes
Supported content media types.Overrides the media types inferred from the parsers that identify what media types can be consumed by the resource.
An example where this might be useful if you have parsers registered that handle media types that you don't want exposed in the Swagger documentation.This affects the returned values from the following:
See Also:
- Parameters:
values
- The values to add to this setting.- Returns:
- This object.
-
annotations
Description copied from class:Context.Builder
Defines annotations to apply to specific classes and methods.Allows you to dynamically apply Juneau annotations typically applied directly to classes and methods. Useful in cases where you want to use the functionality of the annotation on beans and bean properties but do not have access to the code to do so.
As a rule, any Juneau annotation with an
on() method can be used with this setting.The following example shows the equivalent methods for applying the
@Bean
annotation:// Class with explicit annotation. @Bean (properties="street,city,state" )public class A {...}// Class with annotation applied via @BeanConfig public class B {...}// Java REST method with @BeanConfig annotation. @RestGet (...)@Bean (on="B" , properties="street,city,state" )public void doFoo() {...}In general, the underlying framework uses this method when it finds dynamically applied annotations on config annotations. However, concrete implementations of annotations are also provided that can be passed directly into builder classes like so:
// Create a concrete @Bean annotation. Bean annotation = BeanAnnotation.create (B.class ).properties("street,city,state" ).build();// Apply it to a serializer. WriterSerializerserializer = JsonSerializer.create ().annotations(annotation ).build();// Serialize a bean with the dynamically applied annotation. Stringjson =serializer .serialize(new B());The following is the list of annotations builders provided that can be constructed and passed into the builder class:
BeanAnnotation
BeancAnnotation
BeanIgnoreAnnotation
BeanpAnnotation
ExampleAnnotation
NamePropertyAnnotation
ParentPropertyAnnotation
SwapAnnotation
UriAnnotation
CsvAnnotation
HtmlAnnotation
JsonAnnotation
SchemaAnnotation
MsgPackAnnotation
OpenApiAnnotation
PlainTextAnnotation
SoapXmlAnnotation
UonAnnotation
UrlEncodingAnnotation
XmlAnnotation
The syntax for the
on() pattern match parameter depends on whether it applies to a class, method, field, or constructor. The valid pattern matches are:- Classes:
- Fully qualified:
"com.foo.MyClass"
- Fully qualified inner class:
"com.foo.MyClass$Inner1$Inner2"
- Simple:
"MyClass"
- Simple inner:
"MyClass$Inner1$Inner2" "Inner1$Inner2" "Inner2"
- Fully qualified:
- Methods:
- Fully qualified with args:
"com.foo.MyClass.myMethod(String,int)" "com.foo.MyClass.myMethod(java.lang.String,int)" "com.foo.MyClass.myMethod()"
- Fully qualified:
"com.foo.MyClass.myMethod"
- Simple with args:
"MyClass.myMethod(String,int)" "MyClass.myMethod(java.lang.String,int)" "MyClass.myMethod()"
- Simple:
"MyClass.myMethod"
- Simple inner class:
"MyClass$Inner1$Inner2.myMethod" "Inner1$Inner2.myMethod" "Inner2.myMethod"
- Fully qualified with args:
- Fields:
- Fully qualified:
"com.foo.MyClass.myField"
- Simple:
"MyClass.myField"
- Simple inner class:
"MyClass$Inner1$Inner2.myField" "Inner1$Inner2.myField" "Inner2.myField"
- Fully qualified:
- Constructors:
- Fully qualified with args:
"com.foo.MyClass(String,int)" "com.foo.MyClass(java.lang.String,int)" "com.foo.MyClass()"
- Simple with args:
"MyClass(String,int)" "MyClass(java.lang.String,int)" "MyClass()"
- Simple inner class:
"MyClass$Inner1$Inner2()" "Inner1$Inner2()" "Inner2()"
- Fully qualified with args:
- A comma-delimited list of anything on this list.
See Also:
- Overrides:
annotations
in classContext.Builder
- Parameters:
values
- The annotations to register with the context.- Returns:
- This object.
-
apply
Description copied from class:Context.Builder
Applies a set of applied to this builder.An
AnnotationWork
consists of a single pair ofAnnotationInfo
that represents an annotation instance, andAnnotationApplier
which represents the code used to apply the values in that annotation to a specific builder.Example:
// A class annotated with a config annotation. @BeanConfig (sortProperties="$S{sortProperties,false}" )public class MyClass {...}// Find all annotations that themselves are annotated with @ContextPropertiesApply. AnnotationListannotations = ClassInfo.of (MyClass.class ).getAnnotationList(CONTEXT_APPLY_FILTER ); VarResolverSessionvrs = VarResolver.DEFAULT .createSession(); AnnotationWorkListwork = AnnotationWorkList.of(vrs ,annotations );// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .apply(work ) .build();- Overrides:
apply
in classContext.Builder
- Parameters:
work
- The list of annotations and appliers to apply to this builder.- Returns:
- This object.
-
applyAnnotations
Description copied from class:Context.Builder
Applies any of the various@XConfig annotations on the specified class to this context.Any annotations found that themselves are annotated with
ContextApply
will be resolved and applied as properties to this builder. These annotations include:BeanConfig
CsvConfig
HtmlConfig
HtmlDocConfig
JsonConfig
JsonSchemaConfig
MsgPackConfig
OpenApiConfig
ParserConfig
PlainTextConfig
SerializerConfig
SoapXmlConfig
UonConfig
UrlEncodingConfig
XmlConfig
RdfConfig
Annotations on classes are appended in the following order:
- On the package of this class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On this class.
The default var resolver
VarResolver.DEFAULT
is used to resolve any variables in annotation field values.Example:
// A class annotated with a config annotation. @BeanConfig (sortProperties="$S{sortProperties,false}" )public class MyClass {...}// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .applyAnnotations(MyClass.class ) .build();- Overrides:
applyAnnotations
in classContext.Builder
- Parameters:
fromClasses
- The classes on which the annotations are defined.- Returns:
- This object.
-
applyAnnotations
Description copied from class:Context.Builder
Applies any of the various@XConfig annotations on the specified method to this context.Any annotations found that themselves are annotated with
ContextApply
will be resolved and applied as properties to this builder. These annotations include:BeanConfig
CsvConfig
HtmlConfig
HtmlDocConfig
JsonConfig
JsonSchemaConfig
MsgPackConfig
OpenApiConfig
ParserConfig
PlainTextConfig
SerializerConfig
SoapXmlConfig
UonConfig
UrlEncodingConfig
XmlConfig
RdfConfig
Annotations on methods are appended in the following order:
- On the package of the method class.
- On interfaces ordered parent-to-child.
- On parent classes ordered parent-to-child.
- On the method class.
- On this method and matching methods ordered parent-to-child.
The default var resolver
VarResolver.DEFAULT
is used to resolve any variables in annotation field values.Example:
// A method annotated with a config annotation. public class MyClass {@BeanConfig (sortProperties="$S{sortProperties,false}" )public void myMethod() {...} }// Apply any settings found on the annotations. WriterSerializerserializer = JsonSerializer .create () .applyAnnotations(MyClass.class .getMethod("myMethod" )) .build();- Overrides:
applyAnnotations
in classContext.Builder
- Parameters:
fromMethods
- The methods on which the annotations are defined.- Returns:
- This object.
-
cache
Description copied from class:Context.Builder
Specifies a cache to use for hashkey-based caching.- Overrides:
cache
in classContext.Builder
- Parameters:
value
- The cache.- Returns:
- This object.
-
debug
Description copied from class:Context.Builder
Context configuration property: Debug mode.Enables the following additional information during serialization:
- When bean getters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
-
Enables
BeanTraverseContext.Builder.detectRecursions()
.
Enables the following additional information during parsing:
- When bean setters throws exceptions, the exception includes the object stack information in order to determine how that method was invoked.
Example:
// Create a serializer with debug enabled. WriterSerializerserializer = JsonSerializer .create () .debug() .build();// Create a POJO model with a recursive loop. public class MyBean {public Objectf ; } MyBeanbean =new MyBean();bean .f =bean ;// Throws a SerializeException and not a StackOverflowError Stringjson =serializer .serialize(bean );See Also:
- Overrides:
debug
in classContext.Builder
- Returns:
- This object.
-
debug
Description copied from class:Context.Builder
Same asContext.Builder.debug()
but allows you to explicitly specify the value.- Overrides:
debug
in classContext.Builder
- Parameters:
value
- The value for this setting.- Returns:
- This object.
-
impl
Description copied from class:Context.Builder
Specifies a pre-instantiated bean for theContext.Builder.build()
method to return.- Overrides:
impl
in classContext.Builder
- Parameters:
value
- The value for this setting.- Returns:
- This object.
-
type
Description copied from class:Context.Builder
Associates a context class with this builder.This is the type of object that this builder creates when the
Context.Builder.build()
method is called.By default, it's the outer class of where the builder class is defined.
- Overrides:
type
in classContext.Builder
- Parameters:
value
- The context class that this builder should create.- Returns:
- This object.
-