org.restlet.ext.jaxrs
Class JaxRsRestlet

java.lang.Object
  extended by org.restlet.Uniform
      extended by org.restlet.Restlet
          extended by org.restlet.ext.jaxrs.JaxRsRestlet

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 he resource method. Typcally 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.
JaxRsRestlet(Context context, RoleChecker roleChecker, MetadataService metadataService)
          Creates a new JaxRsRestlet with the given Context.
 
Method Summary
 boolean addClass(java.lang.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(java.lang.Object jaxRsProviderOrRootresourceObject)
          Adds the provider object to this JaxRsRestlet.
 ObjectFactory getObjectFactory()
          Returns the ObjectFactory for root resource class and provider instantiation, if given.
 RoleChecker getRoleChecker()
          Gets the currently used RoleChecker.
 java.util.Set<java.lang.Class<?>> getRootResourceClasses()
          Returns an unmodifiable set with the attached root resource classes.
 java.util.Collection<java.lang.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 setObjectFactory(ObjectFactory objectFactory)
          Sets the ObjectFactory for root resource class and provider instantiation.
 void setRoleChecker(RoleChecker roleChecker)
          Sets the RoleChecker to use.
 void start()
           
 
Methods inherited from class org.restlet.Restlet
getApplication, getContext, getLogger, init, isStarted, isStopped, setContext, stop
 
Methods inherited from class org.restlet.Uniform
delete, delete, get, get, handle, head, head, options, options, post, post, put, put
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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. If a resource class later wants to check if a user has a role, the request is returned with HTTP status 500 (Internal Server Error), see SecurityContext.isUserInRole(String). You may set a RoleChecker by using the constructor JaxRsRestlet(Context, RoleChecker, MetadataService) or method setRoleChecker(RoleChecker).

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

JaxRsRestlet

public JaxRsRestlet(Context context,
                    RoleChecker roleChecker,
                    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).
roleChecker - The RoleChecker to use. If you don't need the access control, you can use the RoleChecker.FORBID_ALL, the RoleChecker.ALLOW_ALL or the RoleChecker.REJECT_WITH_ERROR.
metadataService - the metadata service of the JaxRsApplication.
See Also:
JaxRsRestlet(Context, MetadataService)
Method Detail

addClass

public boolean addClass(java.lang.Class<?> jaxRsClass)
                 throws java.lang.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:
java.lang.IllegalArgumentException - if the root resource class is null.

addSingleton

public boolean addSingleton(java.lang.Object jaxRsProviderOrRootresourceObject)
                     throws java.lang.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:
java.lang.IllegalArgumentException - if null was given
See Also:
Provider

start

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

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.

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

getRoleChecker

public RoleChecker getRoleChecker()
Gets the currently used RoleChecker.

Returns:
the currently used RoleChecker.
See Also:
setRoleChecker(RoleChecker)

setRoleChecker

public void setRoleChecker(RoleChecker roleChecker)
                    throws java.lang.IllegalArgumentException
Sets the RoleChecker to use.

Parameters:
roleChecker - the roleChecker to set. Must not be null. Take a look at RoleChecker.ALLOW_ALL, RoleChecker.FORBID_ALL and RoleChecker.REJECT_WITH_ERROR.
Throws:
java.lang.IllegalArgumentException - If the given roleChecker is null.
See Also:
RoleChecker, getRoleChecker()

getRootResourceClasses

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

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

getRootUris

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

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

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.

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.


Copyright © 2005-2008 Noelios Technologies.