XTIVIA Jetservice is a framework designed to generate JAX-RS REST services deployed in Liferay DXP. XTIVIA Jetservice is a companion framework to XTIVIA Jetray that provides a yeoman-based generator that rapidly creates a gradle-based JAX-RS REST services project with a few prompts. It includes support for an OSGi/DXP Configuration UI and optionally includes support for XTIVIA Service Guard.
Creating your project
Let us walk through the code generator step by step. This will generate a new OSGi module with two sample APIs ready to deploy in Liferay DXP.
- Spin up a running instance of OOB DXP Liferay server. Set context path in CXF Endpoint and Rest Extenders to “/rest”. Make sure that telnet client is enabled.
- Make sure the acceptable versions of software are installed e.g. gradle (I tested with v 5.0), node (tested with version 10.13.0), npm (tested with version 6.5.0), gulp (tested with version 2.0.1) and yeoman (tested with version 2.0.5).
- The yeoman prompts go like:
You can now open up the gradle project in your favorite IDE and browse the code.
- Build the project as follows.
- Deploy the project as follows.
Reviewing the sample APIs and CRUD operations
We can now retrieve the list of all people from our sample API with the following URL:
Or query for a specific people record with this URL:
You can add a people record with a post to this URL:
Which returns the id for the added record (ex: 1545550719798).
You can update a record with a PUT to this URL:
Finally, you can delete the record with a DELETE to this URL:
After running through those examples, you’ll see the query that this sample person returns does not exist.
Anatomy of the project
The entry point of this project is the RestApplication class where we have the base path “/hr” configured. We will add our resources to this object. Out of the box, this app comes with two sample resources. The PeopleResource is mapped to the route “/people”. With the PeopleResource installed in the RestApplication, the full path to this API will be as follows:
URL path breakdown:
- Liferay JAX-RS services base: /o/rest
- RestApplication path: /hr
- PeopleResource API path: /people
In addition, we added the EchoResource (duly mapped to “/echo” route) to the RestApplication class. This EchoResource contains an example for consuming Liferay DXP configuration. After making the necessary changes, you can build and deploy the project to Liferay DXP.
These two sample resources can be used to model the necessary resources for your new application. Generally, your first step is to change the base path in the RestApplication from “/hr” to match your desired plans. Then you develop new resources using the examples provided. Once you’re ready, you can remove the sample code as you prepare for your production release.
If you have questions on how you can best leverage XTIVIA Jetservice and/or need help with your Liferay DXP implementation, please engage with us via comments on this blog post, or reach out to us at https://www.xtivia.com/contact/ or email@example.com.
You can also continue to explore Liferay DXP and XTIVIA services framework by checking out Migrating to Liferay DXP, The Top 10 New Features in Liferay DXP, or Using the XTIVIA Services Framework For Liferay REST Services.