Package org.forgerock.json.resource
Class Resources
java.lang.Object
org.forgerock.json.resource.Resources
This class contains methods for creating and manipulating connection
factories and connections.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final JsonPointer
JsonPointer used in fields to denote "all fields", i.e., no filtering. -
Method Summary
Modifier and TypeMethodDescriptionstatic RequestHandler
asRequestHandler
(SynchronousRequestHandler syncHandler) Adapts the providedSynchronousRequestHandler
as aRequestHandler
.static JsonValue
filterResource
(JsonValue resource, Collection<JsonPointer> fields) Returns a JSON object containing only the specified fields from the provided JSON value.static ResourceResponse
filterResource
(ResourceResponse resource, Collection<JsonPointer> fields) Returns a JSON object containing only the specified fields from the provided resource.static RequestHandler
newAnnotatedRequestHandler
(Object provider) Deprecated.static RequestHandler
newCollection
(Object provider) Deprecated.UsenewHandler(Object)
instead.static RequestHandler
newHandler
(Object provider) Creates a newRequestHandler
backed by the supplied provider.static Connection
newInternalConnection
(RequestHandler handler) Creates a new connection to aRequestHandler
.static ConnectionFactory
Creates a new connection factory which binds internal client connections toRequestHandler
s.static RequestHandler
newSingleton
(Object provider) Deprecated.UsenewHandler(Object)
instead.static Connection
uncloseable
(Connection connection) Returns an uncloseable view of the provided connection.static ConnectionFactory
uncloseable
(ConnectionFactory factory) Returns an uncloseable view of the provided connection factory.
-
Field Details
-
FIELD_VALUE_ALL_PTR
JsonPointer used in fields to denote "all fields", i.e., no filtering.
-
-
Method Details
-
asRequestHandler
Adapts the providedSynchronousRequestHandler
as aRequestHandler
.- Parameters:
syncHandler
- The synchronous request handler to be adapted.- Returns:
- The adapted synchronous request handler.
-
filterResource
Returns a JSON object containing only the specified fields from the provided JSON value. If the list of fields is empty then the value is returned unchanged.NOTE: this method only performs a shallow copy of extracted fields, so changes to the filtered JSON value may impact the original JSON value, and vice-versa.
- Parameters:
resource
- The JSON value whose fields are to be filtered.fields
- The list of fields to be extracted.- Returns:
- The filtered JSON value.
-
filterResource
public static ResourceResponse filterResource(ResourceResponse resource, Collection<JsonPointer> fields) Returns a JSON object containing only the specified fields from the provided resource. If the list of fields is empty then the resource is returned unchanged.NOTE: this method only performs a shallow copy of extracted fields, so changes to the filtered resource may impact the original resource, and vice-versa.
- Parameters:
resource
- The resource whose fields are to be filtered.fields
- The list of fields to be extracted.- Returns:
- The filtered resource.
-
newInternalConnection
Creates a new connection to aRequestHandler
.- Parameters:
handler
- The request handler to which client requests should be forwarded.- Returns:
- The new internal connection.
- Throws:
NullPointerException
- Ifhandler
wasnull
.
-
newInternalConnectionFactory
Creates a new connection factory which binds internal client connections toRequestHandler
s.- Parameters:
handler
- The request handler to which client requests should be forwarded.- Returns:
- The new internal connection factory.
- Throws:
NullPointerException
- Ifhandler
wasnull
.
-
newHandler
Creates a newRequestHandler
backed by the supplied provider. The provider can be an instance of an interface resource handler, and annotated resource handler or an annotated request handler. The type of the provider will be determined from theorg.forgerock.api.annotations.RequestHandler#variant
annotation property, or from the type of interface implemented.Sub-paths that are declared using the
org.forgerock.api.annotations.Path
annotation will also be routed through the returned handler.This method uses the same logic as
newCollection(Object)
,newSingleton(Object)
andnewAnnotatedRequestHandler(Object)
to create the underlyingRequestHandler
s.- Parameters:
provider
- The provider instance.- Returns:
- The constructed handler.
-
newCollection
Deprecated.UsenewHandler(Object)
instead.Returns a new request handler which will forward requests on to the provided collection resource provider. Incoming requests which are not appropriate for a resource collection or resource instance will result in a bad request error being returned to the client.- Parameters:
provider
- The collection resource provider. Either an implementation ofCollectionResourceProvider
or a POJO annotated with annotations fromorg.forgerock.api.annotations
.- Returns:
- A new request handler which will forward requests on to the provided collection resource provider.
-
newSingleton
Deprecated.UsenewHandler(Object)
instead.Returns a new request handler which will forward requests on to the provided singleton resource provider. Incoming requests which are not appropriate for a singleton resource (e.g. query) will result in a bad request error being returned to the client.- Parameters:
provider
- The singleton resource provider. Either an implementation ofSingletonResourceProvider
or a POJO annotated with annotations fromorg.forgerock.api.annotations
.- Returns:
- A new request handler which will forward requests on to the provided singleton resource provider.
-
newAnnotatedRequestHandler
Deprecated.UsenewHandler(Object)
instead.Returns a new request handler which will forward requests on to the provided annotated request handler.- Parameters:
provider
- The POJO annotated with annotations fromorg.forgerock.api.annotations
.- Returns:
- A new request handler which will forward requests on to the provided annotated POJO.
-
uncloseable
Returns an uncloseable view of the provided connection. Attempts to callConnection.close()
will be ignored.- Parameters:
connection
- The connection whoseclose
method is to be disabled.- Returns:
- An uncloseable view of the provided connection.
-
uncloseable
Returns an uncloseable view of the provided connection factory. Attempts to callConnectionFactory.close()
will be ignored.- Parameters:
factory
- The connection factory whoseclose
method is to be disabled.- Returns:
- An uncloseable view of the provided connection factory.
-
newHandler(Object)
instead.