Java Service
Java Service is a component used within the Syncloop Platform to create APIs that require complex functionality or interactions with Java code and libraries. By leveraging Java services, you can call Java applications directly from your APIs. A Java service is invoked by the API and utilizes a JAR file from the library. Inside this JAR file, multiple classes are stored, which use Java Library for execution. There are two main reasons for using a Java Service:
Implement Custom Algorithms: Sometimes, the programming logic is too complex to be achieved or supported directly within the API setup. In such cases, a customized Java service is created by writing suitable Java code, which is then called through the API.
Communicate with Java Libraries: The Syncloop platform does not support direct communication with Java libraries through APIs. To overcome this limitation and enable communication with Java libraries or reuse existing Java code, you can write a Java service and call it from the API.
Creating a Java Service
To create a Java Service on the Syncloop Platform, follow these steps:
Right-click on the Package Folder.
Select New -> Services -> Java
Note:
A Java Service cannot invoke or call any other Java Service.
A Java Service cannot invoke or call any other API.
Code Window
The Code Window is where you write your actual Java code for the Java Service. When creating a Java Service, a default code template is provided. It is important to keep the code format unchanged.
Input and Output Parameters
The input and output parameters in the Java Service support all the data types available in the API. These variables are provided as input to the Java code, where they are processed, and the output is derived and stored in the output parameters of the API.
To access input parameters within the Java Service code, you can use the DataPipeline object. This object is responsible for retrieving data from input parameters and storing output data in the output parameters. The DataPipeline object provides several methods and properties for handling various data types and variable arrays.
Example: To retrieve an input parameter as a string:
dataPipeline.getString("parameterName"); // Recommended approach
dataPipeline.getAsString("parameterName");
Similar methods are available for other data types. To access array objects, you can use:
dataPipeline.get("arrayParameterName");
To set an output parameter, you can use the following methods:
dataPipeline.putString("outputParameterName", "outputValue"); // Recommended approach
dataPipeline.putAsString("outputParameterName", "outputValue");
Similar methods are available for other data types. To set array objects, you can use:
dataPipeline.put("arrayOutputParameterName", arrayValue);
Mapping Parameters
When calling a Java Service from an API, you can map the input and output parameters of the Java Service to the input and output parameters of the API. This enables you to utilize the methods defined in the Java Service within the API and efficiently use Java libraries through a flow service indirectly.
For more details on how to call a Java Service from an API, refer to the accompanying video tutorial.