The Guided Tour walks you through the following tasks:
Examine how the TRS toolkit, can help you create a TRS provider, using JAX-RS
- Open the file org.eclipse.lyo.rio.trs.resources.BaseResource.java. Notice @Path("/trs/"+TRSConstants.TRS_TERM_BASE) at the top of the class.
- This is a JAX-RS annotation that assigns a relative path (from the jax-rs servlet context) for the Base Resource RESTful endpoint. There are various constants and vocabularies defined in the toolkit to abstract the terms and namespaces from TRS provider implementers.
- In the reference application, the Base Resource is paged so that, according to the specification, a get on the base resources will do a redirect to the first page of base resources. This is what happens in the getBase() endpoint.
- The other method, getBasePage(page), returns the Base resource at the given page. The class org.eclipse.lyo.core.trs.Base is provided by the TRS toolkit. It is basically a simple java bean that has been annotated with various OSLC4J annotations to allow the OSLC4J marshalling to create the proper RDF document for the JAX-RS configured serialization.
- Both methods have additional annotations such as @GET, which identifies the type of HTTP traffic it can handle, as well as an @Produces that identifies the return type the method can handle. In all cases, the REST endpoints can return RDF XML, XML, or JSON. JAX-RS dynamically returns the correct format based on the HTTP request that is received.
- Open the file org.eclipse.lyo.rio.trs.resources.TRSResource.java
- In similar fashion it also has an @Path annotation that identifies the root of the RESTful service for the Tracked Resource Set.
- The reference application is utilizing the segmented Changelog concept from the TRS Specification (sec 22.214.171.124). The method getTrackedResourceSet() returns a tracked resource set with the most recent segment of the changelog.
- The other method in this class, getChangeLog(page), returns the segmented portion of the change as requested by the HTTP request
Trying it out
- Ensure that the reference application is running. If it is not, in the Project Explorer view, in the org.eclipse.lyo.rio.trs project, right-click Launch TRS Reference App.launch and click Run As -> Launch TRS Reference App.
- The TRS Reference Application includes an index.html file that contains links to the various capabilities provided by the application. To open the page, point your browser at http://<hostname>:8082/org.eclipse.lyo.rio.trs (e.g. http://localhost:8082/org.eclipse.lyo.rio.trs)
- The first section of the page provides links to the Base and Tracked Resource Set as implemented by the BaseResource and TRSResource classes we observed earlier. Navigate to the Base Resources link. You'll see the Base Resources document in XML form. The format and syntax has been handled by the TRS toolkit's annotated beans and the OSLC4J serializers.
- Navigate to the Tracked Resource Set link. The change log contained in the Tracked Resource Set should contain a rdf:nil to represent no changes have been made to the resources.
- Return to the index page and click Create Change Request.
- Type in a title and a description, and then click Submit Bug. Make note of the change request number.
- Go back to the Tracked Resource Set page and refresh if necessary. Notice an entry in the change log section of the Tracked Resource Set containing a Creation event. If you repeat the creation event more than 3 times, you'll notice the change log being segmented with a previous element containing a URI to return the previous segment of the change log.