Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.45.3. Root resource classes
Overview Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
A root resource class is the entry point into a JAX-RS implemented RESTful Web service. It is decorated with a
@Path
that specifies the root URI of the resources implemented by the service. Its methods either directly implement operations on the resource or provide access to sub-resources.
Requirements Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
In order for a class to be a root resource class it must meet the following criteria:
- The class must be decorated with the
@Path
annotation.The specified path is the root URI for all of the resources implemented by the service. If the root resource class specifies that its path is widgets and one of its methods implements theGET
verb, then aGET
on widgets invokes that method. If a sub-resource specifies that its URI is {id}, then the full URI template for the sub-resource is widgets/{id} and it will handle requests made to URIs like widgets/12 and widgets/42. - The class must have a public constructor for the runtime to invoke.The runtime must be able to provide values for all of the constructor's parameters. The constructor's parameters can include parameters decorated with the JAX-RS parameter annotations. For more information on the parameter annotations see Chapter 46, Passing Information into Resource Classes and Methods.
- At least one of the classes methods must either be decorated with an HTTP verb annotation or the
@Path
annotation.
Example Copy linkLink copied to clipboard!
Copy linkLink copied to clipboard!
Example 45.3, “Root resource class” shows a root resource class that provides access to a sub-resource.
Example 45.3. Root resource class
The class in Example 45.3, “Root resource class” meets all of the requirements for a root resource class.
- 1
- The class is decorated with the
@Path
annotation. The root URI for the resources exposed by the service is customerservice. - 2
- The class has a public constructor. In this case the no argument constructor is used for simplicity.
- 3
- The class implements each of the four HTTP verbs for the resource.
- 4
- The class also provides access to a sub-resource through the
getOrder()
method. The URI for the sub-resource, as specified using the the@Path
annotation, is customerservice/order/id. The sub-resource is implemented by theOrder
class.For more information on implementing sub-resources see Section 45.5, “Working with sub-resources”.