This is one of the Holon Platform example projects.
This example shows how to setup RESTful server and client applications using the Holon platform JAX-RS module Spring Boot support, with both sides PropertyBox
data container support using JSON as data exchange format, leveraging on the Holon platform JSON module Jackson JAX-RS support.
This is the Spring Boot version of the JAX-RS and PropertyBox example.
This example addresses the following topics:
- Setup a JAX-RS server RESTful API with PropertyBox JSON support using Spring Boot.
- Use the
@PropertySetRef
annotation to handlePropertyBox
type requests - Setup a JAX-RS client with PropertyBox JSON support.
- Obtain and use RestClient to invoke API operations involving
PropertyBox
object types and handle errors.
This JAX-RS server implements a simple RESTful API to provide the Product data model entity management, backed by an in-memory store.
The server API uses the PropertyBox
class as data container and JSON as data exchange format, leveraging on the Holon platform JSON module Jackson JAX-RS support.
The ProductEndpoint class represents the API endpoint and provides operations to get a product, get all products and create/update/delete a product. It is declared as a singleton Spring bean through the @Component
annotation and it is auto-configured as JAX-RS resource by the Holon platform auto configuration facilities.
The Client unit test class performs a set of API operations using a default RestClient
instance obtained through the static forTarget()
method, which creates a default RestClient
implementation relying on the available RestClientFactory
s (in this example, a standard platform JAX-RS Client based implementation will be created) and setting a default base target URI.
The Client
test class output will be:
Created URI: http://localhost:{port}/api/products/1
Created id: 1
Updated description: Updated
Created URI: http://localhost:{port}/api/products/2
Products: 1 - Updated; 2 - Product 2
Deleted product with id: 1
Deleted product with id: 2
Products count: 0
The Holon platform provides a set of Spring Boot starters to quickly setup a JAX-RS server with different server runtimes and JSON providers.
In this example, the starter dependency declared in the project pom
uses Jersey as JAX-RS server implementation, Tomcat as embedded servlet container and Jackson as JSON provider:
<dependency>
<groupId>com.holon-platform.jaxrs</groupId>
<artifactId>holon-starter-jersey</artifactId>
</dependency>
You can simply replace this dependency with another one among the available the Holon Platform JAX-RS starters to use a different JAX-RS implementation / embedded servlet container / JSON provider combination, for example to use Undertow as servlet container and/or Gson as JSON provider or Resteasy as JAX-RS implementation:
Starter Artifact id | Description |
---|---|
holon-starter-jersey |
Spring Boot JAX-RS server starter using Jersey, Tomcat and Jackson as JSON provider |
holon-starter-jersey-gson |
Spring Boot JAX-RS server starter using Jersey, Tomcat and Gson as JSON provider |
holon-starter-jersey-undertow |
Spring Boot JAX-RS server starter using Jersey, Undertow and Jackson as JSON provider |
holon-starter-jersey-undertow-gson |
Spring Boot JAX-RS server starter using Jersey, Undertow and Gson as JSON provider |
holon-starter-jersey-client |
Spring Boot JAX-RS client starter using Jersey and Jackson as JSON provider |
holon-starter-jersey-client-gson |
Spring Boot JAX-RS client starter using Jersey and Gson as JSON provider |
holon-starter-resteasy |
Spring Boot JAX-RS server starter using Resteasy, Tomcat and Jackson as JSON provider |
holon-starter-resteasy-gson |
Spring Boot JAX-RS server starter using Resteasy, Tomcat and Gson as JSON provider |
holon-starter-resteasy-undertow |
Spring Boot JAX-RS server starter using Resteasy, Undertow and Jackson as JSON provider |
holon-starter-resteasy-undertow-gson |
Spring Boot JAX-RS server starter using Resteasy, Undertow and Gson as JSON provider |
For the client side:
Starter Artifact id | Description |
---|---|
holon-starter-resteasy-client |
Spring Boot JAX-RS client starter using Resteasy and Jackson as JSON provider |
holon-starter-resteasy-client-gson |
Spring Boot JAX-RS client starter using Resteasy and Gson as JSON provider |
See the JAX-RS and PropertyBox with Spring Boot and a Datastore example to see how to setup and use a Datastore
for data persistence.
The complete Holon Platform reference guide is available here.
For the specific documentation about the modules and the components used in this example see:
- Holon platform JSON module reference documentation
- Holon platform JAX-RS module reference documentation
- Documentation about the PropertyBox data structure
- Documentation about the RestClient platform RESTful client
The Holon Platform is built using Java 8, so you need a JRE/JDK version 8 or above to build and run this example projects.
All the Holon Platform modules and examples are Open Source software released under the Apache 2.0 license.
See Holon Platform Examples for the examples directory.