Package org.restlet
Class Context
java.lang.Object
org.restlet.Context
- Direct Known Subclasses:
ChildContext,ComponentContext
Contextual data and services provided to a set of Restlets. The context is
the means by which a Restlet may access the software environment within the
framework. It is typically provided by the immediate parent Restlet
(Application is the most common case).
Concurrency note: attributes and parameters of a context are stored in concurrent collections that guarantee thread safe access and modification. If several threads concurrently access objects and modify these collections, they should synchronize on the lock of the Context instance.
Concurrency note: attributes and parameters of a context are stored in concurrent collections that guarantee thread safe access and modification. If several threads concurrently access objects and modify these collections, they should synchronize on the lock of the Context instance.
- Author:
- Jerome Louvel
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a protected child context.Returns a modifiable attributes map that can be used by developers to save information relative to the context.Returns a request dispatcher to available client connectors.static ContextReturns the context associated to the currentRestlet.static LoggerReturns the current context's logger.Returns an enroler that can add the user roles based on authenticated user principals.Returns a verifier that can check the validity of the credentials associated to a request.Returns the executor service.Returns the logger.Returns the modifiable series of parameters.Returns a request dispatcher to component's virtual hosts.voidsetAttributes(Map<String, Object> attributes) Sets the modifiable map of attributes.voidsetClientDispatcher(Restlet clientDispatcher) Sets the client dispatcher.static voidsetCurrent(Context context) Sets the context to associated with the current thread.voidsetDefaultEnroler(Enroler enroler) Sets an enroler that can add the user roles based on authenticated user principals.voidsetDefaultVerifier(Verifier verifier) Sets a local verifier that can check the validity of user/secret couples based on Restlet default authorization model.voidsetExecutorService(ScheduledExecutorService executorService) Sets the executor service.voidSets the logger.voidSets the logger.voidsetParameters(Series<Parameter> parameters) Sets the modifiable series of parameters.voidsetServerDispatcher(Restlet serverDispatcher) Sets the server dispatcher.
-
Constructor Details
-
Context
public Context()Constructor. Writes log messages to "org.restlet". -
Context
Constructor.- Parameters:
logger- The logger instance of use.
-
Context
Constructor.- Parameters:
loggerName- The name of the logger to use.
-
-
Method Details
-
getCurrent
Returns the context associated to the currentRestlet. The context can be the one of aComponent, anApplication, aFilteror any otherRestletsubclass.
Warning: this method should only be used under duress. You should by default prefer obtaining the current context using methods such asRestlet.getContext()orResource.getContext().
This variable is stored internally as a thread local variable and updated each time a request is handled by aRestletvia theRestlet.handle(org.restlet.Request, org.restlet.Response)method.- Returns:
- The current context.
-
getCurrentLogger
Returns the current context's logger.- Returns:
- The current context's logger.
-
setCurrent
Sets the context to associated with the current thread.- Parameters:
context- The thread's context.
-
createChildContext
Creates a protected child context. This is especially useful for new application attached to their parent component, to ensure their isolation from the other applications. By default it creates a new context instance with empty or null properties, except the client and server dispatchers that are wrapped for isolation purpose.- Returns:
- The child context.
-
getAttributes
Returns a modifiable attributes map that can be used by developers to save information relative to the context. This is a convenient means to provide common objects to all the Restlets and Resources composing an Application.
In addition, this map is a shared space between the developer and the Restlet implementation. For this purpose, all attribute names starting with "org.restlet" are reserved. Currently the following attributes are used:list of currently used attributes Attribute name Class name Description org.restlet.application org.restlet.Application The parent application providing this context, if any. - Returns:
- The modifiable attributes map.
-
getClientDispatcher
Returns a request dispatcher to available client connectors. When you ask the dispatcher to handle a request, it will automatically select the appropriate client connector for your request, based on the request.protocol property or on the resource URI's scheme. This call is blocking and will return an updated response object.- Returns:
- A request dispatcher to available client connectors.
-
getDefaultEnroler
Returns an enroler that can add the user roles based on authenticated user principals.- Returns:
- An enroler.
-
getDefaultVerifier
Returns a verifier that can check the validity of the credentials associated to a request.- Returns:
- A verifier.
-
getExecutorService
Returns the executor service.- Returns:
- The executor service.
-
getLogger
Returns the logger.- Returns:
- The logger.
-
getParameters
Returns the modifiable series of parameters. A parameter is a pair composed of a name and a value and is typically used for configuration purpose, like Java properties. Note that multiple parameters with the same name can be declared and accessed.- Returns:
- The modifiable series of parameters.
-
getServerDispatcher
Returns a request dispatcher to component's virtual hosts. This is useful for application that want to optimize calls to other applications hosted in the same component or to the application itself.
The processing is the same as what would have been done if the request came from one of the component's server connectors. It first must match one of the registered virtual hosts. Then it can be routed to one of the attached Restlets, typically an Application.
Note that the RIAP pseudo protocol isn't supported by this dispatcher, you should instead rely on thegetClientDispatcher()method.- Returns:
- A request dispatcher to the server connectors' router.
-
setAttributes
Sets the modifiable map of attributes. This method clears the current map and puts all entries in the parameter map.- Parameters:
attributes- A map of attributes.
-
setClientDispatcher
Sets the client dispatcher.- Parameters:
clientDispatcher- The new client dispatcher.
-
setDefaultEnroler
Sets an enroler that can add the user roles based on authenticated user principals.- Parameters:
enroler- An enroler.
-
setDefaultVerifier
Sets a local verifier that can check the validity of user/secret couples based on Restlet default authorization model.- Parameters:
verifier- A local verifier.
-
setExecutorService
Sets the executor service.- Parameters:
executorService- The executor service.
-
setLogger
Sets the logger.- Parameters:
logger- The logger.
-
setLogger
Sets the logger.- Parameters:
loggerName- The name of the logger to use.
-
setParameters
Sets the modifiable series of parameters. This method clears the current series and adds all entries in the parameter series.- Parameters:
parameters- A series of parameters.
-
setServerDispatcher
Sets the server dispatcher.- Parameters:
serverDispatcher- The new server dispatcher.
-