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 the VirtualHost 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.
Concurrency note: instances of this class or its subclasses can be invoked by several threads at the same time and therefore must be thread-safe. You should be especially careful when storing state in member variables.
Author:
Jerome Louvel
  • Constructor Details

    • Application

      public Application()
      Constructor. Note this constructor is convenient because you don't have to provide a context like for Application(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 the Context.createChildContext() method to ensure a proper isolation with the other applications.
  • Method Details

    • 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 getting the current application using methods such as Resource.getApplication()
      Returns:
      The current context.
    • setCurrent

      public static void setCurrent(Application application)
      Sets the context 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 of Router and Filter classes will be used. The default implementation returns a Restlet giving access to the the outbound service layer and finally to the Context.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(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 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.
    • 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 the Context.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 to Status.SERVER_ERROR_INTERNAL.

      Subclasses overriding this method should make sure that they call super.handle(request, response) before adding their own logic.

      Specified by:
      handle in interface Uniform
      Overrides:
      handle in class Restlet
      Parameters:
      request - The request to handle.
      response - The response to update.
    • 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 class Restlet
      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(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(Class<? extends ServerResource> outboundRootClass)
      Sets the outbound root Resource class.
      Parameters:
      outboundRootClass - The client root ServerResource 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(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 Exception
      Starts the application, all the enabled associated services then the inbound and outbound roots.
      Overrides:
      start in class Restlet
      Throws:
      Exception
    • stop

      public void stop() throws Exception
      Stops the application, the inbound and outbound roots then all the enabled associated services. Finally, it clears the internal cache of annotations.
      Overrides:
      stop in class Restlet
      Throws:
      Exception