Java Client

Unresolved directive in java_client.adoc - include::nav.adoc[] Java Client


This example is a simple java client that logs in to the Xelion server, retrieves the server capabilities and logs out.

The source is avaiable here.

Requirements
  • Java 8 or newer

  • gson library

Build

Unzip the source, get gson.jar and build, for example:

javac -cp gson.jar;. nl\xelion\xcc\api\examples\client\Client.java
Running

Build the program and start it with:

java -cp gson.jar;. nl.xelion.xcc.api.examples.client.Client -u <user> -p <password> -h <host>

For example

java -cp gson.jar;. nl.xelion.xcc.api.examples.client.Client -u arnon -p arnon-pwd -h api.xelion.nl
Notes

The interesting Java classes of the program are:

Resource

An API resource, for example me/login or communications. A resource is parameterized with its type. The resource me/login is of type LoginResponse (Login Response) and the resource communications is of type Communication (Communications).

Request

An API request, for example POST me/login (Login Resquest).

Response

The response for an API request. A response contains the return type of the requested resource or an error response if an error occurred.

Session

A session is created after a successful login and stores the authorization token and the API base URL. This class executes the API requests.