Skip to content

Latest commit

 

History

History

propertybox

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Holon platform examples: JAX-RS and PropertyBox

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, with both sides PropertyBox data container support using JSON as data exchange format, leveraging on the Holon platform JSON module Jackson JAX-RS support.

Topics

This example addresses the following topics:

  • Setup a JAX-RS server RESTful API with PropertyBox JSON support.
  • Use the @PropertySetRef annotation to handle PropertyBox 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.

Example structure

This example project is composed of 3 modules: model, server and client.

Data model module

The model module contains a shared data model for a Product entity, defined using the Holon Platform Property model. This module is inherited by both server and client modules.

Server module

The server module is a JAX-RS server implementation using Jersey and Grizzly web server to provide a simple RESTful API to provide the Product data model entity management, backed by an in-memory store. The holon-jaxrs-server artifact provides support and dependencies for JAX-RS server setup.

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 Jackson support for the PropertyBox type is provided by the holon-jackson-jaxrs artifact and it is automatically configured in the JAX-RS server.

The ProductEndpoint class represents the API endpoint and provides operations to get a product, get all products and create/update/delete a product.

To start the server run the Server class main method, a Jersey Grizzly server will be started and listening to port 8080 at localhost, exposing the API endpoint at the /api path, until any key is pressed on console.

Client module

The server module is a JAX-RS client implementation using Jersey, leveraging on the holon-jaxrs-client artifact and on the holon-jackson-jaxrs artifact for PropertyBox type JSON support using Jackson.

The main Client class performs a set of API operations (expecting the server module running and listening to the http://localhost:8080/api base URI) using a default RestClient instance obtained through the static forTarget() method, which creates a default RestClient implementation relying on the available RestClientFactorys and setting a default base target URI.

Since the holon-jaxrs-client artifact is present in classpath, the actual RestClient implementation will be the standard platform JAX-RS Client based implementation.

The Client main method output will be:

Created URI: http://localhost:8080/api/products/1
Created id: 1
Updated description: Updated
Created URI: http://localhost:8080/api/products/2
Products: 1 - Updated; 2 - Product 2
Deleted product with id: 1
Deleted product with id: 2
Products count: 0

Using Gson as JSON provider

To use Gson as JSON provider instead of Jackson, simply replace the holon-jackson-jaxrs dependency with the holon-gson-jaxrs dependency in both server and client project pom.

Using Spring Boot

To learn how to use Spring Boot for JAX-RS server setup, see the JAX-RS and PropertyBox with Spring Boot example.

Documentation

The complete Holon Platform reference guide is available here.

For the specific documentation about the modules and the components used in this example see:

System requirements

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.

License

All the Holon Platform modules and examples are Open Source software released under the Apache 2.0 license.

Holon Platform Examples

See Holon Platform Examples for the examples directory.