Class 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 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.
    • 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 throw WebApplicationException.
      • objectFactory

        private volatile ObjectFactory objectFactory
        Deprecated.
      • resourceClasses

        private final ResourceClasses resourceClasses
        Deprecated.
    • Method Detail

      • addClass

        public boolean addClass​(java.lang.Class<?> jaxRsClass)
                         throws java.lang.IllegalArgumentException
        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.
        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.IllegalArgumentException
        Deprecated.
        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.IllegalArgumentException
        Deprecated.
        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
      • 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 Restlet Representation.
        Parameters:
        entity - the entity to convert.
        resourceMethod - The resource method created the entity. Could be null, if an exception is handled, e.g. a WebApplicationException.
        jaxRsResponseMediaType - The MediaType of the JAX-RS Response. May be null.
        jaxRsRespHeaders - The headers added to the Response by the Response.ResponseBuilder.
        accMediaTypes - the accepted media type from the current call context, or the returned of the JAX-RS Response.
        Returns:
        the corresponding Restlet Representation. Returns null only if null was given.
        Throws:
        javax.ws.rs.WebApplicationException
        ImplementationException
        See Also:
        AbstractMethodWrapper.EntityGetter
      • 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 - The MessageBodyWriters, that support the class of the returned entity object as generic type of the MessageBodyWriter.
        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.
        Specified by:
        handle in interface Uniform
        Overrides:
        handle in class Restlet
        Parameters:
        request - The Request to handle.
        response - The Response to update.
      • 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 method
        resourceMethod - the resource method; it is needed for the conversion. Could be null, if an exception is handled, e.g. a WebApplicationException.
      • 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
      • 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 invoke
        resourceObject - the resource object to invoke the method on.
        Returns:
        the object returned by the (sub) resource method.
        Throws:
        RequestHandledException - if the request is already handled
        javax.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-RS Response to a Restlet Response.
        Parameters:
        jaxRsResponse - The response returned by the resource method, perhaps as attribute of a WebApplicationException.
        resourceMethod - The resource method creating the response. Could be null, if an exception is handled, e.g. a WebApplicationException.
      • loadDefaultProviders

        private void loadDefaultProviders()
        Deprecated.
      • 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.Exception
        Deprecated.
        Description copied from class: Restlet
        Starts 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.
        Overrides:
        start in class Restlet
        Throws:
        java.lang.Exception