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 18.104.22.168). 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.
Examine how the TRS toolkit helps create a TRS provider, via generic Servlet
- Open the file org.eclipse.lyo.rio.trs\src\main\webapp\WEB-INF\web.xml. Notice the servlet mapping for the relative path /restx/trs/base/. This maps the Base resource RESTful endpoint to the servlet class com.ibm.team.integration.refapps.trs.servlet.BaseGeneric.
- Open the file org.eclipse.lyo.rio.trs.servlet.BaseGeneric. It has an overridden doGet method, which implements the root of the RESTful service for the Base Resource.
- 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. If the path for the Get request contains the page number, it returns the response corresponding to the Base resource at the given page. In a simple servlet implementation, we serialize the Base resource to the response stream using OSLC4JMarshaller. The current implementation of the Base end point only handles RDF XML, but it could be extended to various other media types based on the HTTP request.
- Similary, the file web.xml also contains the servlet mapping for two other endpoints for Tracked Resource Set and Change Log.
- The servlet mapping for the relative path /restx/trs/ maps the Tracked Resource Set RESTful endpoint to the servlet class org.eclipse.lyo.rio.trs.servlet.TRSGeneric.
- Open the file org.eclipse.lyo.rio.trs.servlet.TRSGeneric. It has an overridden doGet method, which implements 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 toGet() populates a TrackedResourceSet (a simple java bean provided by the toolkit for representing a tracked resource set) with the most recent segment of the changelog. It then serializes the TrackedResourceSet object to the response stream using OSLC4JMarshaller.
- In a similar fashion, the Changelog endpoint, which is mapped to the the relative path /restx/trs/changelog/, is implemented in the class org.eclipse.lyo.rio.trs.servlet.ChangeLogGeneric.java.