Package org.restlet.ext.jaxrs
Class JaxRsRestlet
- java.lang.Object
-
- org.restlet.Restlet
-
- org.restlet.ext.jaxrs.JaxRsRestlet
-
- All Implemented Interfaces:
Uniform
@Deprecated public class JaxRsRestlet extends Restlet
Deprecated.Will be removed in next minor release.This class choose the JAX-RS resource class and method to use for a request and handles the result from he resource method. Typically you should instantiate a
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.JaxRsApplicationto run JAX-RS resource classes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classJaxRsRestlet.ResObjAndMethDeprecated.Structure to return the obtainedResourceObjectand the identifiedResourceMethod.(package private) classJaxRsRestlet.ResObjAndRemPathDeprecated.Structure to return the obtainedResourceObjectand the remaining path after identifying the object.(package private) classJaxRsRestlet.RroRemPathAndMatchedPathDeprecated.Structure to return an instance of the identifiedRootResourceClass, the matched URI path and the remaining path after identifying the root resource class.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.annotation.Annotation[]EMPTY_ANNOTATION_ARRAYDeprecated.private ExceptionHandlerexcHandlerDeprecated.Contains and handles the exceptions occurring while in resource objects and providers, and also for the other cases where the runtime environment should throwWebApplicationException.private ObjectFactoryobjectFactoryDeprecated.private JaxRsProvidersprovidersDeprecated.private ResourceClassesresourceClassesDeprecated.private ThreadLocalizedContexttlContextDeprecated.Contains the thread localizedCallContexts.
-
Constructor Summary
Constructors Constructor Description JaxRsRestlet(Context context, MetadataService metadataService)Deprecated.Creates a new JaxRsRestlet with the given Context.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanaddClass(java.lang.Class<?> jaxRsClass)Deprecated.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.private booleanaddDefaultProvider(java.lang.Object jaxRsProvider)Deprecated.Adds the provider object as default provider to this JaxRsRestlet.booleanaddSingleton(java.lang.Object jaxRsProviderOrRootresourceObject)Deprecated.Adds the provider object to this JaxRsRestlet.private booleanaddSingleton(java.lang.Object jaxRsProvider, boolean defaultProvider)Deprecated.Adds the provider object to this JaxRsRestlet.voidattachDefault(Restlet notMatchedRestlet)Deprecated.Sets the Restlet that is called, if no (root) resource class or method could be found.private RepresentationconvertToRepresentation(java.lang.Object entity, ResourceMethod resourceMethod, MediaType jaxRsResponseMediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> jaxRsRespHeaders, SortedMetadata<MediaType> accMediaTypes)Deprecated.Converts the given entity - returned by the resource method - to a RestletRepresentation.private ResourceObjectcreateSubResource(ResourceObject o, SubResourceLocator subResourceLocator, CallContext callContext)Deprecated.private MediaTypedetermineMediaType(MediaType jaxRsResponseMediaType, ResourceMethod resourceMethod, java.lang.Class<?> entityClass, java.lang.reflect.Type genericReturnType)Deprecated.Determines the MediaType for a response, see JAX-RS-Spec (2008-08-27), section 3.8 "Determining the MediaType of Responses"RestletgetNoResMethodHandler()Deprecated.Returns the Restlet that is called, if no resource method class could be found.RestletgetNoResourceClHandler()Deprecated.Returns the Restlet that is called, if no resource class could be found.RestletgetNoRootResClHandler()Deprecated.Returns the Restlet that is called, if no root resource class could be found.ObjectFactorygetObjectFactory()Deprecated.Returns the ObjectFactory for root resource class and provider instantiation, if given.java.util.Set<java.lang.Class<?>>getRootResourceClasses()Deprecated.Returns an unmodifiable set with the attached root resource classes.java.util.Collection<java.lang.String>getRootUris()Deprecated.Returns a Collection with all root uris attached to this JaxRsRestlet.voidhandle(Request request, Response response)Deprecated.Handles a call by looking for the resource metod to call, call it and return the result.private RequestHandledExceptionhandleInvocationTargetExc(java.lang.reflect.InvocationTargetException ite)Deprecated.Handles the given Exception, catched by an invoke of a resource method or a creation if a sub resource object.private voidhandleResult(java.lang.Object result, ResourceMethod resourceMethod)Deprecated.Sets the result of the resource method invocation into the response.private JaxRsRestlet.ResObjAndMethidentifyMethod(JaxRsRestlet.ResObjAndRemPath resObjAndRemPath, MediaType givenMediaType)Deprecated.Identifies the method that will handle the request, see JAX-RS-Spec (2008-04-16), section 3.7.2 "Request Matching", Part 3: Identify the method that will handle the request:"private JaxRsRestlet.RroRemPathAndMatchedPathidentifyRootResource(RemainingPath u)Deprecated.Identifies the root resource class, see JAX-RS-Spec (2008-04-16), section 3.7.2 "Request Matching", Part 1: "Identify the root resource class"private ResourceObjectinstantiateRrc(RootResourceClass rrc)Deprecated.Instantiates the root resource class and handles thrown exceptions.private java.lang.ObjectinvokeMethod(ResourceMethod resourceMethod, ResourceObject resourceObject)Deprecated.Invokes the (sub) resource method.private voidjaxRsRespToRestletResp(javax.ws.rs.core.Response jaxRsResponse, ResourceMethod resourceMethod)Deprecated.Converts the given JAX-RSResponseto a RestletResponse.private voidloadDefaultProviders()Deprecated.private JaxRsRestlet.ResObjAndRemPathobtainObject(JaxRsRestlet.RroRemPathAndMatchedPath rroRemPathAndMatchedPath)Deprecated.Obtains the object that will handle the request, see JAX-RS-Spec (2008-04-16), section 3.7.2 "Request Matching", Part 2: "btain the object that will handle the request"private JaxRsRestlet.ResObjAndMethrequestMatching()Deprecated.Implementation of algorithm in JAX-RS-Spec (2008-04-16), Section 3.7.2 "Request Matching"voidsetNoResMethodHandler(Restlet noResMethodHandler)Deprecated.Sets the Restlet that will handle theRequests, if no resource method could be found.voidsetNoResourceClHandler(Restlet noResourceClHandler)Deprecated.Sets the Restlet that will handle theRequests, if no resource class could be found.voidsetNoRootResClHandler(Restlet noRootResClHandler)Deprecated.Sets the Restlet that is called, if no root resource class could be found.voidsetObjectFactory(ObjectFactory objectFactory)Deprecated.Sets the ObjectFactory for root resource class and provider instantiation.voidstart()Deprecated.Starts the Restlet.-
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
-
-
-
-
Field Detail
-
EMPTY_ANNOTATION_ARRAY
private static final java.lang.annotation.Annotation[] EMPTY_ANNOTATION_ARRAY
Deprecated.
-
excHandler
private final ExceptionHandler excHandler
Deprecated.Contains and handles the exceptions occurring while in resource objects and providers, and also for the other cases where the runtime environment should throwWebApplicationException.
-
objectFactory
private volatile ObjectFactory objectFactory
Deprecated.
-
providers
private final JaxRsProviders providers
Deprecated.
-
resourceClasses
private final ResourceClasses resourceClasses
Deprecated.
-
tlContext
private final ThreadLocalizedContext tlContext
Deprecated.Contains the thread localizedCallContexts.
-
-
Constructor Detail
-
JaxRsRestlet
public JaxRsRestlet(Context context, MetadataService metadataService)
Deprecated.Creates a new JaxRsRestlet with the given Context. Only the default providers are loaded.- Parameters:
context- the context from the parent, seeRestlet(Context).metadataService- the metadata service of theJaxRsApplication.- See Also:
JaxRsRestlet(Context, MetadataService)
-
-
Method Detail
-
addClass
public boolean addClass(java.lang.Class<?> jaxRsClass) throws java.lang.IllegalArgumentExceptionDeprecated.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.
-
addDefaultProvider
private boolean addDefaultProvider(java.lang.Object jaxRsProvider)
Deprecated.Adds the provider object as default provider to this JaxRsRestlet.- Parameters:
jaxRsProvider- The provider object or class name.- Returns:
- true, if the provider is ok and added, otherwise false.
- Throws:
java.lang.IllegalArgumentException- if null was given
-
addSingleton
public boolean addSingleton(java.lang.Object jaxRsProviderOrRootresourceObject) throws java.lang.IllegalArgumentExceptionDeprecated.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
-
addSingleton
private boolean addSingleton(java.lang.Object jaxRsProvider, boolean defaultProvider) throws java.lang.IllegalArgumentExceptionDeprecated.Adds the provider object to this JaxRsRestlet.- Parameters:
jaxRsProvider- The provider object or class name.defaultProvider-- Returns:
- true, if the provider is ok and added, otherwise false.
- Throws:
java.lang.IllegalArgumentException- if null was given
-
attachDefault
public void attachDefault(Restlet notMatchedRestlet)
Deprecated.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)
-
convertToRepresentation
private Representation convertToRepresentation(java.lang.Object entity, ResourceMethod resourceMethod, MediaType jaxRsResponseMediaType, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> jaxRsRespHeaders, SortedMetadata<MediaType> accMediaTypes) throws ImplementationException
Deprecated.Converts the given entity - returned by the resource method - to a RestletRepresentation.- Parameters:
entity- the entity to convert.resourceMethod- The resource method created the entity. Could be null, if an exception is handled, e.g. aWebApplicationException.jaxRsResponseMediaType- The MediaType of the JAX-RSResponse. May be null.jaxRsRespHeaders- The headers added to theResponseby theResponse.ResponseBuilder.accMediaTypes- the accepted media type from the current call context, or the returned of the JAX-RSResponse.- Returns:
- the corresponding Restlet Representation. Returns
nullonly if null was given. - Throws:
javax.ws.rs.WebApplicationExceptionImplementationException- See Also:
AbstractMethodWrapper.EntityGetter
-
createSubResource
private ResourceObject createSubResource(ResourceObject o, SubResourceLocator subResourceLocator, CallContext callContext) throws javax.ws.rs.WebApplicationException, RequestHandledException
Deprecated.- Parameters:
o-subResourceLocator-callContext-- Returns:
- ResourceObject
- Throws:
javax.ws.rs.WebApplicationExceptionRequestHandledException
-
determineMediaType
private MediaType determineMediaType(MediaType jaxRsResponseMediaType, ResourceMethod resourceMethod, java.lang.Class<?> entityClass, java.lang.reflect.Type genericReturnType) throws javax.ws.rs.WebApplicationException
Deprecated.Determines the MediaType for a response, see JAX-RS-Spec (2008-08-27), section 3.8 "Determining the MediaType of Responses"- Parameters:
jaxRsResponseMediaType-resourceMethod- The ResourceMethod that created the entity.entityClass- needed, if neither the resource method nor the resource class is annotated with @Produces.genericReturnType- needed, if neither the resource method nor the resource class is annotated with @Produces.methodAnnotation- needed, if neither the resource method nor the resource class is annotated with @Produces.mbws- TheMessageBodyWriters, that support the class of the returned entity object as generic type of theMessageBodyWriter.- Returns:
- the determined
MediaType. If no method is given, "text/plain" is returned. - Throws:
javax.ws.rs.WebApplicationException
-
getNoResMethodHandler
public Restlet getNoResMethodHandler()
Deprecated.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()
Deprecated.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()
Deprecated.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()
Deprecated.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 java.util.Set<java.lang.Class<?>> getRootResourceClasses()
Deprecated.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()
Deprecated.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)
Deprecated.Handles a call by looking for the resource metod to call, call it and return the result.
-
handleInvocationTargetExc
private RequestHandledException handleInvocationTargetExc(java.lang.reflect.InvocationTargetException ite) throws RequestHandledException
Deprecated.Handles the given Exception, catched by an invoke of a resource method or a creation if a sub resource object.- Parameters:
ite-methodName-- Throws:
RequestHandledException- throws this message to exit the method and indicate, that the request was handled.RequestHandledException
-
handleResult
private void handleResult(java.lang.Object result, ResourceMethod resourceMethod)Deprecated.Sets the result of the resource method invocation into the response. Do necessary converting.- Parameters:
result- the object returned by the resource methodresourceMethod- the resource method; it is needed for the conversion. Could be null, if an exception is handled, e.g. aWebApplicationException.
-
identifyMethod
private JaxRsRestlet.ResObjAndMeth identifyMethod(JaxRsRestlet.ResObjAndRemPath resObjAndRemPath, MediaType givenMediaType) throws RequestHandledException
Deprecated.Identifies the method that will handle the request, see JAX-RS-Spec (2008-04-16), section 3.7.2 "Request Matching", Part 3: Identify the method that will handle the request:"- Returns:
- Resource Object and Method, that handle the request.
- Throws:
RequestHandledException- for example if the method was OPTIONS, but no special Resource Method for OPTIONS is available.ResourceMethodNotFoundException
-
identifyRootResource
private JaxRsRestlet.RroRemPathAndMatchedPath identifyRootResource(RemainingPath u) throws javax.ws.rs.WebApplicationException, RequestHandledException
Deprecated.Identifies the root resource class, see JAX-RS-Spec (2008-04-16), section 3.7.2 "Request Matching", Part 1: "Identify the root resource class"- Parameters:
u- the remaining path after the base ref- Returns:
- The identified root resource object, the remaining path after
identifying and the matched template parameters; see
JaxRsRestlet.RroRemPathAndMatchedPath. - Throws:
javax.ws.rs.WebApplicationExceptionRequestHandledException
-
instantiateRrc
private ResourceObject instantiateRrc(RootResourceClass rrc) throws javax.ws.rs.WebApplicationException, RequestHandledException
Deprecated.Instantiates the root resource class and handles thrown exceptions.- Parameters:
rrc- the root resource class to instantiate- Returns:
- the instance of the root resource
- Throws:
javax.ws.rs.WebApplicationException- if a WebApplicationException was thrown while creating the instance.RequestHandledException- If an Exception was thrown and the request is already handeled.
-
invokeMethod
private java.lang.Object invokeMethod(ResourceMethod resourceMethod, ResourceObject resourceObject) throws javax.ws.rs.WebApplicationException, RequestHandledException
Deprecated.Invokes the (sub) resource method. Handles / converts also occuring exceptions.- Parameters:
resourceMethod- the (sub) resource method to invokeresourceObject- the resource object to invoke the method on.- Returns:
- the object returned by the (sub) resource method.
- Throws:
RequestHandledException- if the request is already handledjavax.ws.rs.WebApplicationException- if a JAX-RS class throws an WebApplicationException
-
jaxRsRespToRestletResp
private void jaxRsRespToRestletResp(javax.ws.rs.core.Response jaxRsResponse, ResourceMethod resourceMethod)Deprecated.Converts the given JAX-RSResponseto a RestletResponse.- Parameters:
jaxRsResponse- The response returned by the resource method, perhaps as attribute of aWebApplicationException.resourceMethod- The resource method creating the response. Could be null, if an exception is handled, e.g. aWebApplicationException.
-
loadDefaultProviders
private void loadDefaultProviders()
Deprecated.
-
obtainObject
private JaxRsRestlet.ResObjAndRemPath obtainObject(JaxRsRestlet.RroRemPathAndMatchedPath rroRemPathAndMatchedPath) throws javax.ws.rs.WebApplicationException, RequestHandledException
Deprecated.Obtains the object that will handle the request, see JAX-RS-Spec (2008-04-16), section 3.7.2 "Request Matching", Part 2: "btain the object that will handle the request"- Parameters:
rroRemPathAndMatchedPath-- Throws:
javax.ws.rs.WebApplicationExceptionRequestHandledExceptionjava.lang.RuntimeException
-
requestMatching
private JaxRsRestlet.ResObjAndMeth requestMatching() throws RequestHandledException, javax.ws.rs.WebApplicationException
Deprecated.Implementation of algorithm in JAX-RS-Spec (2008-04-16), Section 3.7.2 "Request Matching"- Returns:
- (Sub)Resource Method
- Throws:
RequestHandledExceptionjavax.ws.rs.WebApplicationException
-
setNoResMethodHandler
public void setNoResMethodHandler(Restlet noResMethodHandler)
Deprecated.Sets the Restlet that will handle theRequests, 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)
Deprecated.Sets the Restlet that will handle theRequests, 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)
Deprecated.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)
Deprecated.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 java.lang.ExceptionDeprecated.Description copied from class:RestletStarts the Restlet. By default its only sets "started" internal property to true. WARNING: this method must be called at the end of the starting process by subclasses otherwise concurrent threads could enter into the call handling logic too early.
-
-