Gluon CloudLink Enterprise SDK for Java EE

We have recently announced the release of the Gluon CloudLink SDK. The SDK consists of two components:

  1. Client SDK: used in the Mobile Application code to interact with Gluon CloudLink functionality
  2. Enterprise SDK: used to manipulate the mobile content and functionality by writing Java enterprise code

The Gluon CloudLink Enterprise SDK is implemented on top of a REST API. All functionality to operate Gluon CloudLink can be achieved by executing REST calls.

For your convenience, Gluon provides two Java client implementations on top of this REST API, that allow the developers to use the enterprise SDK in two of the most popular java enterprise frameworks: Java EE and Spring. Using these enterprise SDKs is very easy, and it is documented in a number of samples. For example, if you want to use the Java EE implementation, you will learn how to do this by following the steps in the tutorial or you can alternatively download the sample by cloning our gluon-samples repository on GitHub.

The Gluon CloudLink Enterprise SDK is made available under an open-source license. The code for both implementations can be found in our public GitHub repository. In this post we will talk a bit more in depth about the Java EE implementation.

The Java EE Gluon CloudLink Enterprise SDK already uses two new additions to the Java EE framework that will be introduced in Java EE 8. One is the update of the Bean Validation API 2. The other one is the new Java API for JSON Binding. Finally, it also make use of the JAX-RS client API to communicate with the REST API of the Gluon CloudLink Enterprise SDK.

Bean Validation

Bean Validation versions 1.0 and 1.1 are already available since Java EE 6 and 7 respectively. Bean Validation version 2.0 is planned to be part of Java EE 8 and mainly adds in support for, and takes advantage of, Java SE 8. New built-in constraints are added (e.g. @Email, @NotBlank, @Positive and @Negative) and all built-in constraints are repeatable annotations now. Furthermore, it adds support for the new Java SE 8 date and time types, JavaFX properties as well as java.util.Optional. More information about all the new features can be read in the Bean Validation specification.

When injecting an instance of CloudLinkClient with CDI, Bean Validation will automatically be applied when calling any method on the instance. This ensures that valid parameters are passed in to the method that is being called. When validation fails, a ConstraintViolationException is thrown. When the exception occurs in the context of a JAX-RS resource, a custom ExceptionMapper is triggered to convert the exception into a 400 Bad Request HTTP response.

One of the new bean validation annotations is the @NotEmpty constraint. CloudLinkClient checks this constraint to prevent the use of null or empty string identifiers. Previously we used the constraints @NotNull combined with @Size(min = 1) to achieve the same result.

With the new constraint that is added in Bean Validation 2, the code can be simplified:

Another advantage is the improved message that is shown when validation fails. When we pass along an empty string to the method declared above, the validation message changes from "size must be between 1 and 2147483647" to the more readable "objectId may not be empty".

JSON Binding

The Java API for JSON Binding, or JSON-B in short, is a new addition to Java EE 8. It introduces a standard API for converting Java objects to/from JSON structures. It provides default mappings for common data types, while also allowing developers to customize the mapping process. The Java EE implementation of the Enterprise SDK uses JSON-B internally to generate and parse the JSON payload for objects that are stored in the Gluon CloudLink Data Storage.

If you want to insert a POJO object into Gluon CloudLink, you can call the following code on the Enterprise SDK:

In CloudLinkClient, the object is simply converted to and from JSON by using an instance of Jsonb:

Why Java EE?

There are a number of reasons why we are leveraging the latest Java EE standard. First of all, Gluon CloudLink is a modern, future-proof SAAS solution that is implemented as a set of microservices, running in a containerized setup. The new Java EE specifications are being built with new patterns in mind, hence there is a great fit with our requirements and with the requirements of modern Java enterprise development teams.

Second, by using the latest specifications and reference implementations, we can evaluate them, and give feedback. This is what makes the Java EE standard so great: different vendors can implement it, and many developers can use it, and give comments that will enhance the specification. By making the code open source, we hope other developers learn about how to use those new Java EE 8 specifications.

We hope you give the Java EE Gluon CloudLink Enterprise SDK a try, and as always, we are very open to comments and feedback.