org.restlet.ext.jaxrs
Class JaxRsRestlet

java.lang.Object
  extended by org.restlet.Restlet
      extended by org.restlet.ext.jaxrs.JaxRsRestlet
All Implemented Interfaces:
Uniform

public class JaxRsRestlet
extends Restlet

This class choose the JAX-RS resource class and method to use for a request and handles the result from the resource method. Typically you should instantiate a JaxRsApplication to run JAX-RS resource classes.

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:
Stephan Koops

Constructor Summary
JaxRsRestlet(Context context, MetadataService metadataService)
          Creates a new JaxRsRestlet with the given Context.
 
Method Summary
 boolean addClass(Class<?> jaxRsClass)
          Will use the given JAX-RS root resource class.
If the given class is not a valid root resource class, a warning is logged and false is returned.
 boolean addSingleton(Object jaxRsProviderOrRootresourceObject)
          Adds the provider object to this JaxRsRestlet.
 void attachDefault(Restlet notMatchedRestlet)
          Sets the Restlet that is called, if no (root) resource class or method could be found.
 Restlet getNoResMethodHandler()
          Returns the Restlet that is called, if no resource method class could be found.
 Restlet getNoResourceClHandler()
          Returns the Restlet that is called, if no resource class could be found.
 Restlet getNoRootResClHandler()
          Returns the Restlet that is called, if no root resource class could be found.
 ObjectFactory getObjectFactory()
          Returns the ObjectFactory for root resource class and provider instantiation, if given.
 Set<Class<?>> getRootResourceClasses()
          Returns an unmodifiable set with the attached root resource classes.
 Collection<String> getRootUris()
          Returns a Collection with all root uris attached to this JaxRsRestlet.
 void handle(Request request, Response response)
          Handles a call by looking for the resource metod to call, call it and return the result.
 void setNoResMethodHandler(Restlet noResMethodHandler)
          Sets the Restlet that will handle the Requests, if no resource method could be found.
 void setNoResourceClHandler(Restlet noResourceClHandler)
          Sets the Restlet that will handle the Requests, if no resource class could be found.
 void setNoRootResClHandler(Restlet noRootResClHandler)
          Sets the Restlet that is called, if no root resource class could be found.
 void setObjectFactory(ObjectFactory objectFactory)
          Sets the ObjectFactory for root resource class and provider instantiation.
 void start()
           
 
Methods inherited from class org.restlet.Restlet
createFinder, finalize, getApplication, getAuthor, getContext, getDescription, getFinderClass, getLogger, getName, getOwner, handle, handle, handle, isStarted, isStopped, setAuthor, setContext, setDescription, setFinderClass, setName, setOwner, stop
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JaxRsRestlet

public JaxRsRestlet(Context context,
                    MetadataService metadataService)
Creates a new JaxRsRestlet with the given Context. Only the default providers are loaded.

Parameters:
context - the context from the parent, see Restlet.Restlet(Context).
metadataService - the metadata service of the JaxRsApplication.
See Also:
JaxRsRestlet(Context, MetadataService)
Method Detail

addClass

public boolean addClass(Class<?> jaxRsClass)
                 throws IllegalArgumentException
Will use the given JAX-RS root resource class.
If the given class is not a valid root resource class, a warning is logged and false is returned.

Parameters:
jaxRsClass - A JAX-RS root resource class or provider class to add. If the root resource class is already available in this JaxRsRestlet, it is ignored for later calls of this method.
Returns:
true if the class is added or was already included, or false if the given class is not a valid class (a warning was logged).
Throws:
IllegalArgumentException - if the root resource class is null.

addSingleton

public boolean addSingleton(Object jaxRsProviderOrRootresourceObject)
                     throws IllegalArgumentException
Adds the provider object to this JaxRsRestlet.

Parameters:
jaxRsProviderOrRootresourceObject - the JAX-RS provider or root resource object
Returns:
true, if the provider is ok and added, otherwise false.
Throws:
IllegalArgumentException - if null was given
See Also:
Provider

attachDefault

public void attachDefault(Restlet notMatchedRestlet)
Sets the Restlet that is called, if no (root) resource class or method could be found.

Parameters:
notMatchedRestlet - the Restlet to call, if no (root) resource class or method could be found.
See Also:
setNoRootResClHandler(Restlet), setNoResourceClHandler(Restlet), setNoResMethodHandler(Restlet), Router.attachDefault(Restlet)

getNoResMethodHandler

public Restlet getNoResMethodHandler()
Returns the Restlet that is called, if no resource method class could be found.

Returns:
the Restlet that is called, if no resource method class could be found.
See Also:
setNoResMethodHandler(Restlet)

getNoResourceClHandler

public Restlet getNoResourceClHandler()
Returns the Restlet that is called, if no resource class could be found.

Returns:
the Restlet that is called, if no resource class could be found.

getNoRootResClHandler

public Restlet getNoRootResClHandler()
Returns the Restlet that is called, if no root resource class could be found. You could remove a given Restlet by set null here.
If no Restlet is given here, status 404 will be returned.

Returns:
the Restlet that is called, if no root resource class could be found.
See Also:
setNoRootResClHandler(Restlet)

getObjectFactory

public ObjectFactory getObjectFactory()
Returns the ObjectFactory for root resource class and provider instantiation, if given.

Returns:
the ObjectFactory for root resource class and provider instantiation, if given.

getRootResourceClasses

public Set<Class<?>> getRootResourceClasses()
Returns an unmodifiable set with the attached root resource classes.

Returns:
an unmodifiable set with the attached root resource classes.

getRootUris

public Collection<String> getRootUris()
Returns a Collection with all root uris attached to this JaxRsRestlet.

Returns:
a Collection with all root uris attached to this JaxRsRestlet.

handle

public void handle(Request request,
                   Response response)
Handles a call by looking for the resource metod to call, call it and return the result.

Specified by:
handle in interface Uniform
Overrides:
handle in class Restlet
Parameters:
request - The Request to handle.
response - The Response to update.

setNoResMethodHandler

public void setNoResMethodHandler(Restlet noResMethodHandler)
Sets the Restlet that will handle the Requests, if no resource method could be found.

Parameters:
noResMethodHandler - the noResMethodHandler to set
See Also:
getNoResMethodHandler(), setNoResourceClHandler(Restlet), setNoRootResClHandler(Restlet), attachDefault(Restlet)

setNoResourceClHandler

public void setNoResourceClHandler(Restlet noResourceClHandler)
Sets the Restlet that will handle the Requests, if no resource class could be found. You could remove a given Restlet by set null here.
If no Restlet is given here, status 404 will be returned.

Parameters:
noResourceClHandler - the noResourceClHandler to set
See Also:
getNoResourceClHandler(), setNoResMethodHandler(Restlet), setNoRootResClHandler(Restlet), attachDefault(Restlet)

setNoRootResClHandler

public void setNoRootResClHandler(Restlet noRootResClHandler)
Sets the Restlet that is called, if no root resource class could be found. You could remove a given Restlet by set null here.
If no Restlet is given here, status 404 will be returned.

Parameters:
noRootResClHandler - the Restlet to call, if no root resource class could be found.
See Also:
getNoRootResClHandler(), setNoResourceClHandler(Restlet), setNoResMethodHandler(Restlet), attachDefault(Restlet)

setObjectFactory

public void setObjectFactory(ObjectFactory objectFactory)
Sets the ObjectFactory for root resource class and provider instantiation.

Parameters:
objectFactory - the ObjectFactory for root resource class and provider instantiation.

start

public void start()
           throws Exception
Overrides:
start in class Restlet
Throws:
Exception


Copyright © 2005-2013 Restlet.