Package org.restlet
Class Component
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.Component
-
- All Implemented Interfaces:
Uniform
public class Component extends Restlet
Restlet managing a set ofConnectors,VirtualHosts,Services andApplications. Applications are expected to be directly attached to virtual hosts or to the internal router (see RIAP pseudo-protocol for usage). Components also expose several services: access logging and status setting.
From an architectural point of view, here is the REST definition: "A component is an abstract unit of software instructions and internal state that provides a transformation of data via its interface." Roy T. Fielding
The configuration of a Component can be done programmatically or by using a XML document. There are dedicated constructors that accept either an URI reference to such XML document or a representation of such XML document, allowing easy configuration of the list of supported client and server connectors as well as services. In addition, you can add and configure virtual hosts (including the default one). Finally, you can attach applications either using their fully qualified class name or by pointing to a descriptor document (at this time only WADL description are supported, see the WADL Restlet extension for details).
The XML Schema of the configuration files is available both online and inside the API JAR under the "org.restlet.Component.xsd" name. Here is a sample of XML configuration:<?xml version="1.0"?> <component xmlns="http://restlet.org/schemas/2.0/Component"> <client protocol="CLAP" /> <client protocol="FILE" /> <client protocols="HTTP HTTPS" /> <server protocols="HTTP HTTPS" /> <defaultHost> <attach uriPattern="/abcd/{xyz}" targetClass="org.restlet.test.MyApplication" /> <attach uriPattern="/efgh/{xyz}" targetDescriptor="clap://class/org/restlet/test/MyApplication.wadl" /> </defaultHost> </component>
Components also have useful services associated. They are all enabled by default and are available as properties that can be eventually overridden:- "logService" to configure access logging.
- "statusService" to provide common representations for exception status.
- "taskService" to run tasks asynchronously.
- Author:
- Jerome Louvel
- See Also:
- Source dissertation
-
-
Constructor Summary
Constructors Constructor Description Component()Constructor.Component(java.lang.String xmlConfigurationRef)Deprecated.Use XML support in the Spring extension instead.Component(Reference xmlConfigRef)Deprecated.Use XML support in the Spring extension instead.Component(Representation xmlConfigRepresentation)Deprecated.Use XML support in the Spring extension instead.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description ClientListgetClients()Returns a modifiable list of client connectors.VirtualHostgetDefaultHost()Returns the default virtual host.java.util.List<VirtualHost>getHosts()Returns the modifiable list of virtual hosts.RoutergetInternalRouter()Returns the private internal router where Restlets like Applications can be attached.LogServicegetLogService()Returns the global log service.RealmgetRealm(java.lang.String name)Finds the realm with the given name.java.util.List<Realm>getRealms()Returns the modifiable list of security realms.ServerListgetServers()Returns the modifiable list of server connectors.ServiceListgetServices()Returns the modifiable list of services.StatusServicegetStatusService()Deprecated.UseApplication.getStatusService()instead.TaskServicegetTaskService()Returns a task service to run concurrent tasks.voidhandle(Request request, Response response)Handles a call.static voidmain(java.lang.String[] args)Deprecated.Use XML support in the Spring extension instead.voidsetClients(ClientList clients)Sets the modifiable list of client connectors.voidsetContext(Context context)Sets the context.voidsetDefaultHost(VirtualHost defaultHost)Sets the default virtual host.voidsetHosts(java.util.List<VirtualHost> hosts)Sets the modifiable list of virtual hosts.voidsetInternalRouter(Router internalRouter)Sets the private internal router were Restlets like Applications can be attached.voidsetLogService(LogService logService)Sets the global log service.voidsetRealms(java.util.List<Realm> realms)Sets the list of realms.voidsetServers(ServerList servers)Sets the modifiable list of server connectors.voidsetStatusService(StatusService statusService)Deprecated.UseApplication.setStatusService(StatusService)instead.voidsetTaskService(TaskService taskService)Sets the task service.voidstart()Starts the component.protected voidstartClients()Starts the client connectors.protected voidstartHelper()Starts the internal helper allowing incoming requests to be served.protected voidstartRealms()Starts the realms.protected voidstartRouters()Starts the virtual hosts and the internal router.protected voidstartServers()Starts the server connectors.protected voidstartServices()Starts the associated services.voidstop()Stops the component.protected voidstopClients()Stops the client connectors.protected voidstopHelper()Stops the internal helper allowing incoming requests to be served.protected voidstopRealms()Stops the realms.protected voidstopRouters()Stops the virtual hosts and the internal router.protected voidstopServers()Stops the server connectors.protected voidstopServices()Stops the associated services.voidupdateHosts()Updates the component to take into account changes to the virtual hosts.-
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
-
Component
public Component()
Constructor.
-
Component
@Deprecated public Component(Reference xmlConfigRef)
Deprecated.Use XML support in the Spring extension instead.Constructor with the reference to the XML configuration file.- Parameters:
xmlConfigRef- The URI reference to the XML configuration file.
-
Component
@Deprecated public Component(Representation xmlConfigRepresentation)
Deprecated.Use XML support in the Spring extension instead.Constructor with the representation of the XML configuration file.- Parameters:
xmlConfigRepresentation- The representation of the XML configuration file.
-
Component
@Deprecated public Component(java.lang.String xmlConfigurationRef)
Deprecated.Use XML support in the Spring extension instead.Constructor with the URI reference to the XML configuration file.- Parameters:
xmlConfigurationRef- The URI reference to the XML configuration file.
-
-
Method Detail
-
main
@Deprecated public static void main(java.lang.String[] args) throws java.lang.ExceptionDeprecated.Use XML support in the Spring extension instead.Used as bootstrap for configuring and running a component in command line. Just provide as first and unique parameter the URI to the XML file. Note that relative paths are accepted.- Parameters:
args- The list of in-line parameters.- Throws:
java.lang.Exception
-
getClients
public ClientList getClients()
Returns a modifiable list of client connectors.- Returns:
- A modifiable list of client connectors.
-
getDefaultHost
public VirtualHost getDefaultHost()
Returns the default virtual host.- Returns:
- The default virtual host.
-
getHosts
public java.util.List<VirtualHost> getHosts()
Returns the modifiable list of virtual hosts. Note that the order of virtual hosts in this list will be used to check the first one that matches.- Returns:
- The modifiable list of virtual hosts.
-
getInternalRouter
public Router getInternalRouter()
Returns the private internal router where Restlets like Applications can be attached. Those Restlets can be addressed via theProtocol.RIAP(Restlet Internal Access Protocol) client connector. This is used to manage private, internal and optimized access to local applications.
The first use case is the modularization of a large application into modules or layers. This can also be achieved using theContext.getServerDispatcher()method, but the internal router is easily addressable via an URI scheme and can be fully private to the current Component.
The second use case is the composition/mash-up of several representations via the org.restlet.ext.xml.Transformer class for example. For this you can leverage the XPath's document() function or the XSLT's include and import elements with RIAP URIs.- Returns:
- The private internal router.
-
getLogService
public LogService getLogService()
Returns the global log service. On the first call, if no log service was defined via thesetLogService(LogService)method, then a default logger service is created. This service will be enabled by default and has a logger name composed the "org.restlet." prefix followed by the simple component class name (without packages), followed by the ".LogService" suffix.- Returns:
- The global log service.
-
getRealm
public Realm getRealm(java.lang.String name)
Finds the realm with the given name.- Parameters:
name- The name.- Returns:
- The realm found or null.
-
getRealms
public java.util.List<Realm> getRealms()
Returns the modifiable list of security realms.- Returns:
- The modifiable list of security realms.
-
getServers
public ServerList getServers()
Returns the modifiable list of server connectors.- Returns:
- The modifiable list of server connectors.
-
getServices
public ServiceList getServices()
Returns the modifiable list of services.- Returns:
- The modifiable list of services.
-
getStatusService
@Deprecated public StatusService getStatusService()
Deprecated.UseApplication.getStatusService()instead.Returns the status service, enabled by default.- Returns:
- The status service.
-
getTaskService
public TaskService getTaskService()
Returns a task service to run concurrent tasks. The service is enabled by default.- Returns:
- A task service.
-
handle
public void handle(Request request, Response response)
Description copied from class:RestletHandles 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.
-
setClients
public void setClients(ClientList clients)
Sets the modifiable list of client connectors. This method clears the current list and adds all entries in the parameter list.- Parameters:
clients- A list of client connectors.
-
setContext
public void setContext(Context context)
Description copied from class:RestletSets the context.- Overrides:
setContextin classRestlet- Parameters:
context- The context.
-
setDefaultHost
public void setDefaultHost(VirtualHost defaultHost)
Sets the default virtual host.- Parameters:
defaultHost- The default virtual host.
-
setHosts
public void setHosts(java.util.List<VirtualHost> hosts)
Sets the modifiable list of virtual hosts. Note that the order of virtual hosts in this list will be used to check the first one that matches. This method clears the current list and adds all entries in the parameter list.- Parameters:
hosts- A list of virtual hosts.
-
setInternalRouter
public void setInternalRouter(Router internalRouter)
Sets the private internal router were Restlets like Applications can be attached.- Parameters:
internalRouter- The private internal router.- See Also:
getInternalRouter()
-
setLogService
public void setLogService(LogService logService)
Sets the global log service.- Parameters:
logService- The global log service.
-
setRealms
public void setRealms(java.util.List<Realm> realms)
Sets the list of realms. This method clears the current list and adds all entries in the parameter list.- Parameters:
realms- A list of realms.
-
setServers
public void setServers(ServerList servers)
Sets the modifiable list of server connectors. This method clears the current list and adds all entries in the parameter list.- Parameters:
servers- A list of server connectors.
-
setStatusService
@Deprecated public void setStatusService(StatusService statusService)
Deprecated.UseApplication.setStatusService(StatusService)instead.Sets the status service.- Parameters:
statusService- The status service.
-
setTaskService
public void setTaskService(TaskService taskService)
Sets the task service.- Parameters:
taskService- The task service.
-
start
public void start() throws java.lang.ExceptionStarts the component. First it starts all the connectors (clients then servers), the routers, the services, the realms and then the component's internal helper. Finally it calls the start method of the super class.- Overrides:
startin classRestlet- Throws:
java.lang.Exception- See Also:
startClients(),startServers(),startRouters(),startServices(),startRealms(),startHelper()
-
startClients
protected void startClients() throws java.lang.ExceptionStarts the client connectors.- Throws:
java.lang.Exception
-
startHelper
protected void startHelper() throws java.lang.ExceptionStarts the internal helper allowing incoming requests to be served.- Throws:
java.lang.Exception
-
startRealms
protected void startRealms() throws java.lang.ExceptionStarts the realms.- Throws:
java.lang.Exception
-
startRouters
protected void startRouters() throws java.lang.ExceptionStarts the virtual hosts and the internal router.- Throws:
java.lang.Exception
-
startServers
protected void startServers() throws java.lang.ExceptionStarts the server connectors.- Throws:
java.lang.Exception
-
startServices
protected void startServices() throws java.lang.ExceptionStarts the associated services.- Throws:
java.lang.Exception
-
stop
public void stop() throws java.lang.ExceptionStops the component. First it stops the component's internal helper, the realms, the services, the routers and then stops all the connectors (servers then clients) Finally it calls the stop method of the super class.- Overrides:
stopin classRestlet- Throws:
java.lang.Exception- See Also:
stopHelper(),stopRealms(),stopServices(),stopRouters(),stopServers(),stopClients()
-
stopClients
protected void stopClients() throws java.lang.ExceptionStops the client connectors.- Throws:
java.lang.Exception
-
stopHelper
protected void stopHelper() throws java.lang.ExceptionStops the internal helper allowing incoming requests to be served.- Throws:
java.lang.Exception
-
stopRealms
protected void stopRealms() throws java.lang.ExceptionStops the realms.- Throws:
java.lang.Exception
-
stopRouters
protected void stopRouters() throws java.lang.ExceptionStops the virtual hosts and the internal router.- Throws:
java.lang.Exception
-
stopServers
protected void stopServers() throws java.lang.ExceptionStops the server connectors.- Throws:
java.lang.Exception
-
stopServices
protected void stopServices() throws java.lang.ExceptionStops the associated services.- Throws:
java.lang.Exception
-
updateHosts
public void updateHosts() throws java.lang.ExceptionUpdates the component to take into account changes to the virtual hosts. This method doesn't stop the connectors or the applications or Restlets attached to the virtual hosts. It just updates the internal routes between the virtual hosts and the attached Restlets or applications.- Throws:
java.lang.Exception
-
-