Package org.restlet
Class Application
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.Application
-
- All Implemented Interfaces:
Uniform
public class Application extends Restlet
Restlet managing a coherent set of resources and services. Applications are guaranteed to receive calls with their base reference set relatively to theVirtualHost
that served them. This class is both a descriptor able to create the root Restlet and the actual Restlet that can be attached to one or more VirtualHost instances.
Applications also have many useful services associated. Most are enabled by default and are available as properties that can be eventually overridden:- "connectorService" to declare necessary client and server connectors.
- "converterService" to convert between regular objects and representations.
- "decoderService" to automatically decode or uncompress received entities.
- "encoderService" to automatically encode or compress sent entities (disabled by default).
- "metadataService" to provide access to metadata and their associated extension names.
- "rangeService" to automatically exposes ranges of response entities.
- "statusService" to provide common representations for exception status.
- "taskService" to run tasks asynchronously (disabled by default).
- "tunnelService" to tunnel method names or client preferences via query parameters.
- Author:
- Jerome Louvel
-
-
Constructor Summary
Constructors Constructor Description Application()
Constructor.Application(Context context)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Restlet
createInboundRoot()
Creates a inbound root Restlet that will receive all incoming calls.Restlet
createOutboundRoot()
Creates a outbound root Restlet that will receive all outgoing calls from ClientResource.ConnectorService
getConnectorService()
Returns the connector service.ConnegService
getConnegService()
Returns the content negotiation service.ConverterService
getConverterService()
Returns the converter service.static Application
getCurrent()
This variable is stored internally as a thread local variable and updated each time a call enters an application.DecoderService
getDecoderService()
Returns the decoder service.EncoderService
getEncoderService()
Returns the encoder service.Restlet
getInboundRoot()
Returns the inbound root Restlet.MetadataService
getMetadataService()
Returns the metadata service.Restlet
getOutboundRoot()
Returns the outbound root Restlet.RangeService
getRangeService()
Returns the range service.Role
getRole(java.lang.String name)
Returns the role associated to the given name.java.util.List<Role>
getRoles()
Returns the modifiable list of roles.ServiceList
getServices()
Returns the modifiable list of services.StatusService
getStatusService()
Returns the status service.TaskService
getTaskService()
Deprecated.TunnelService
getTunnelService()
Returns the tunnel service.void
handle(Request request, Response response)
Handles a call.boolean
isDebugging()
Indicates if the debugging mode is enabled.void
setConnectorService(ConnectorService connectorService)
Sets the connector service.void
setConnegService(ConnegService connegService)
Sets the content negotiation service.void
setContext(Context context)
Sets the context.void
setConverterService(ConverterService converterService)
Sets the converter service.static void
setCurrent(Application application)
Sets the context to associated with the current thread.void
setDebugging(boolean debugging)
Indicates if the debugging mode is enabled.void
setDecoderService(DecoderService decoderService)
Sets the decoder service.void
setEncoderService(EncoderService encoderService)
Sets the encoder service.void
setInboundRoot(java.lang.Class<? extends ServerResource> inboundRootClass)
Sets the inbound root Resource class.void
setInboundRoot(Restlet inboundRoot)
Sets the inbound root Restlet.void
setMetadataService(MetadataService metadataService)
Sets the metadata service.void
setOutboundRoot(java.lang.Class<? extends ServerResource> outboundRootClass)
Sets the outbound root Resource class.void
setOutboundRoot(Restlet outboundRoot)
Sets the outbound root Restlet.void
setRangeService(RangeService rangeService)
Sets the range service.void
setRoles(java.util.List<Role> roles)
Sets the modifiable list of roles.void
setStatusService(StatusService statusService)
Sets the status service.void
setTaskService(TaskService taskService)
Sets the task service.void
setTunnelService(TunnelService tunnelService)
Sets the tunnel service.void
start()
Starts the application, all the enabled associated services then the inbound and outbound roots.void
stop()
Stops the application, the inbound and outbound roots then all the enabled associated services.-
Methods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setDescription, setFinderClass, setName, setOwner
-
-
-
-
Constructor Detail
-
Application
public Application()
Constructor. Note this constructor is convenient because you don't have to provide a context like forApplication(Context)
. Therefore the context will initially be null. It's only when you attach the application to a virtual host via one of its attach*() methods that a proper context will be set.
-
Application
public Application(Context context)
Constructor.- Parameters:
context
- The context to use based on parent component context. This context should be created using theContext.createChildContext()
method to ensure a proper isolation with the other applications.
-
-
Method Detail
-
getCurrent
public static Application getCurrent()
This variable is stored internally as a thread local variable and updated each time a call enters an application. Warning: this method should only be used under duress. You should by default prefer obtaining the current application using methods such asResource.getApplication()
- Returns:
- The current context.
-
setCurrent
public static void setCurrent(Application application)
Sets the context to associated with the current thread.- Parameters:
application
- The thread's context.
-
createInboundRoot
public Restlet createInboundRoot()
Creates a inbound root Restlet that will receive all incoming calls. In general, instances of Router, Filter or Finder classes will be used as initial application Restlet. The default implementation returns null by default. This method is intended to be overridden by subclasses.- Returns:
- The inbound root Restlet.
-
createOutboundRoot
public Restlet createOutboundRoot()
Creates a outbound root Restlet that will receive all outgoing calls from ClientResource. In general, instances ofRouter
andFilter
classes will be used. The default implementation returns a Restlet giving access to the the outbound service layer and finally to theContext.getClientDispatcher()
.This method is intended to be overridden by subclasses but in order to benefit from the outbound service filtering layer, the original outbound root must be careful attached again at the end of the user filtering layer.
- Returns:
- The outbound root Restlet.
-
getConnectorService
public ConnectorService getConnectorService()
Returns the connector service. The service is enabled by default.- Returns:
- The connector service.
-
getConnegService
public ConnegService getConnegService()
Returns the content negotiation service. The service is enabled by default.- Returns:
- The content negotiation service.
-
getConverterService
public ConverterService getConverterService()
Returns the converter service. The service is enabled by default.- Returns:
- The converter service.
-
getDecoderService
public DecoderService getDecoderService()
Returns the decoder service. The service is enabled by default.- Returns:
- The decoder service.
-
getEncoderService
public EncoderService getEncoderService()
Returns the encoder service. The service is disabled by default.- Returns:
- The encoder service.
-
getInboundRoot
public Restlet getInboundRoot()
Returns the inbound root Restlet.- Returns:
- The inbound root Restlet.
-
getMetadataService
public MetadataService getMetadataService()
Returns the metadata service. The service is enabled by default.- Returns:
- The metadata service.
-
getOutboundRoot
public Restlet getOutboundRoot()
Returns the outbound root Restlet.- Returns:
- The outbound root Restlet.
-
getRangeService
public RangeService getRangeService()
Returns the range service.- Returns:
- The range service.
-
getRole
public Role getRole(java.lang.String name)
Returns the role associated to the given name.- Parameters:
name
- The name of the role to find.- Returns:
- The role matched or null.
-
getRoles
public java.util.List<Role> getRoles()
Returns the modifiable list of roles.- Returns:
- The modifiable list of roles.
-
getServices
public ServiceList getServices()
Returns the modifiable list of services.- Returns:
- The modifiable list of services.
-
getStatusService
public StatusService getStatusService()
Returns the status service. The service is enabled by default.- Returns:
- The status service.
-
getTaskService
@Deprecated public TaskService getTaskService()
Deprecated.Returns a task service to run concurrent tasks. The service is enabled by default.- Returns:
- A task service.
-
getTunnelService
public TunnelService getTunnelService()
Returns the tunnel service. The service is enabled by default.- Returns:
- The tunnel service.
-
handle
public void handle(Request request, Response response)
Description copied from class:Restlet
Handles a call. The default behavior is to initialize the Restlet by setting the current context using theContext.setCurrent(Context)
method and by attempting to start it, unless it was already started. If an exception is thrown during the start action, then the response status is set toStatus.SERVER_ERROR_INTERNAL
.Subclasses overriding this method should make sure that they call super.handle(request, response) before adding their own logic.
-
isDebugging
public boolean isDebugging()
Indicates if the debugging mode is enabled. True by default.- Returns:
- True if the debugging mode is enabled.
-
setConnectorService
public void setConnectorService(ConnectorService connectorService)
Sets the connector service.- Parameters:
connectorService
- The connector service.
-
setConnegService
public void setConnegService(ConnegService connegService)
Sets the content negotiation service.- Parameters:
connegService
- The content negotiation service.
-
setContext
public void setContext(Context context)
Description copied from class:Restlet
Sets the context.- Overrides:
setContext
in classRestlet
- Parameters:
context
- The context.
-
setConverterService
public void setConverterService(ConverterService converterService)
Sets the converter service.- Parameters:
converterService
- The converter service.
-
setDebugging
public void setDebugging(boolean debugging)
Indicates if the debugging mode is enabled.- Parameters:
debugging
- True if the debugging mode is enabled.
-
setDecoderService
public void setDecoderService(DecoderService decoderService)
Sets the decoder service.- Parameters:
decoderService
- The decoder service.
-
setEncoderService
public void setEncoderService(EncoderService encoderService)
Sets the encoder service.- Parameters:
encoderService
- The encoder service.
-
setInboundRoot
public void setInboundRoot(java.lang.Class<? extends ServerResource> inboundRootClass)
Sets the inbound root Resource class.- Parameters:
inboundRootClass
- The inbound root Resource class.
-
setInboundRoot
public void setInboundRoot(Restlet inboundRoot)
Sets the inbound root Restlet.- Parameters:
inboundRoot
- The inbound root Restlet.
-
setMetadataService
public void setMetadataService(MetadataService metadataService)
Sets the metadata service.- Parameters:
metadataService
- The metadata service.
-
setOutboundRoot
public void setOutboundRoot(java.lang.Class<? extends ServerResource> outboundRootClass)
Sets the outbound root Resource class.- Parameters:
outboundRootClass
- The client rootServerResource
subclass.
-
setOutboundRoot
public void setOutboundRoot(Restlet outboundRoot)
Sets the outbound root Restlet.- Parameters:
outboundRoot
- The outbound root Restlet.
-
setRangeService
public void setRangeService(RangeService rangeService)
Sets the range service.- Parameters:
rangeService
- The range service.
-
setRoles
public void setRoles(java.util.List<Role> roles)
Sets the modifiable list of roles. This method clears the current list and adds all entries in the parameter list.- Parameters:
roles
- A list of roles.
-
setStatusService
public void setStatusService(StatusService statusService)
Sets the status service.- Parameters:
statusService
- The status service.
-
setTaskService
public void setTaskService(TaskService taskService)
Sets the task service.- Parameters:
taskService
- The task service.
-
setTunnelService
public void setTunnelService(TunnelService tunnelService)
Sets the tunnel service.- Parameters:
tunnelService
- The tunnel service.
-
start
public void start() throws java.lang.Exception
Starts the application, all the enabled associated services then the inbound and outbound roots.
-
-