With Java service, you can interact with your software application that does not support restful APIs. A service that uses a custom Java adapter is a Java service. The Java adapter is a custom Java class and you can create a Java adapter either by implementing com.konylabs.middleware.common.JavaService
interface or com.konylabs.middleware.common.JavaService2
interface. Kony recommends to use JavaService2 as you can get an access to DataControllerRequest
and DataControllerResponse
objects.
You must load the required JAR files to define a Java service. The JAR files contain the Java classes. The Java classes contain the Java methods. These methods have the logic defined that is required for a service. Java services are mostly used with Webconnector Services.
Note: The middleware-system.jar
helps you to develop a Java adapter. You can download the middleware-system.jar
from Admin Console's download page.
Note: You should not modify JVM timezone through custom code as modifying it can result in app server outage.
Note: You should not modify the result object directly through the Pre-processor code for a Java service. This is because any changes made to the result object may be overridden by the Java service's invoke method. Hence, any modifications to the result object should be done only at the Java service level.
The data structure of the Kony Result object (com.konylabs.middleware.datamapping.Result)
shows that all the data is converted, but the complete data in the Kony Result object in not exposed as expected. You get a part of the data in Kony Fabric because only a few unnamed records are converted into an object instead of an array.
The use of JSON Arrays is particularly important for the mapping of data in user interface segments that require arrays as data input.
The following code details sample original JSON data, data converted to Kony Object, and in the result - data converted only limited unnamed records into an object in Kony Fabric (loss of data).
//Sample: Original JSON Data:
{"booking":[ {"amount":-254.6,"description":"Paiement carte BIM STORES PALMIER le 21/02/2016 à 18:54","doc_id":17150820,"value_date":"2016-02-19","temporary":false,"date":"2016-02-21"},{"amount":-44.26,"description":"Paiement internet LYDEC ECOM le 19/02/2016 à 13:04","doc_id":17146660,"value_date":"2016-02-18","temporary":false,"date":"2016-02-19"},{"amount":-37.26,"description":"Paiement internet LYDEC ECOM le 19/02/2016 à 13:19","doc_id":17146835,"value_date":"2016-02-18","temporary":false,"date":"2016-02-19"},{"amount":-14.34,"description":"Paiement internet LYDEC ECOM le 19/02/2016 à 13:11","doc_id":17146744,"value_date":"2016-02-18","temporary":false,"date":"2016-02-19"} ]}
Sample: Data converted to KONY Object:
Dataset [id=booking, index=-1, records=[ Record [index=-1, order=0, id=, params=[ Param [name=amount, value=-254.6], Param [name=description, value=Paiement carte BIM STORES PALMIER le 21/02/2016 à 18:54], Param [name=doc_id, value=17150820], Param [name=value_date, value=2016-02-19], Param [name=temporary, value=false], Param [name=date, value=2016-02-21] ], datasets=[], records=[] ], Record [index=-1, order=0, id=, params=[ Param [name=amount, value=-44.26], Param [name=description, value=Paiement internet LYDEC ECOM le 19/02/2016 à 13:04], Param [name=doc_id, value=17146660], Param [name=value_date, value=2016-02-18], Param [name=temporary, value=false], Param [name=date, value=2016-02-19] ], datasets=[], records=[] ],
//Sample: Data converted only limited unnamed records into an object in Kony Fabric:
"booking": { "": { "date": "2016-02-21", "temporary": "false", "amount": "-254.6", "description": "Paiement carte BIM STORES PALMIER le 21/02/2016 à 18:54", "doc_id": "17150820", "value_date": "2016-02-19" } }
To write a Java class for a Java adapter, follow these steps:
com.konylabs.middleware.common.JavaService
interface or com.konylabs.middleware.common.JavaService2
interface.com.konylabs.middleware.common.JavaService
, you have to implement the following invoke()
method with the signature:public Object invoke(String paramString, Object[] paramArrayOfObject) throws Exception;
com.konylabs.middleware.common.JavaService2
, you have to implement the following invoke()
method with the signature:public Object invoke(String methodID, Object[] objectArray, DataControllerRequest request, DataControllerResponse response) throws Exception;
A middleware API is provided to get the output params/records/datasets configured as part of a service definition of a Java service.
The following is a sample code:
ServiceOutputWrapper serviceOutputWrapper = request.getServicesManager().getOperationData() .getServiceOutputWrapper();
Note: Request is an instance of data controller request.
To configure Java service in the Integration Service Definition tab, follow these steps:
Note: You can select multiple JAR files from the Java Connector JARs list if required.
Important: To upload an updated JAR file, upload the new file, which must have the same name as the old JAR file. The new JAR file overrides the existing file.dsd
Field | Description |
---|---|
Custom Code |
Custom Code enables you to specify dependent JAR. Important: Make sure that you upload a custom JAR file that is built on the same JDK version used for installing Kony Fabric Integration. You can download the uploaded jars to your local system. |
Throttling |
API throttling enables you to limit the number of request calls within a minute. If an API exceeds the throttling limit, it will not return the service response.
|
Note: All options in the Advanced section are optional.
In the Description field, provide a suitable description for the service.
The Operation List tab appears when you click Add Operation in the Service Definition page.
Note: Click Operations List tab > Configure Operation. The Configured Operations list appears.
To create an operation, follow these steps:
Note: To use an existing integration service, refer to How to Use an Existing Integration Service.
In the Operation Modal tab, follow these steps:
This tab contains the request input, response output, and advanced sections. The input values are data types, scope, and format types. By default, the system will display the Request Input tab.
Note: You can add an entry by clicking the Add button if entries for the input and the output tabs do not exist.
You can also delete an entry. Select the check box for an entry, and then click Delete .
Field | Description |
---|---|
Name | It is prepopulated with the operation name. You can change the name if required. |
Operation Security Level |
It specifies how a client must authenticate to invoke this operation. Select one of the following security operations in the Operation Security Level field.
|
Field | Description |
---|---|
Custom Code Invocation - Preprocessor and Postprocessor (for Java and JavaScript) | You can add pre and post processing logic to services to modify the request inputs. When you test, the services details of various stages in the service execution are presented to you for better debugging. All options in the Advanced section are optional. For more details, refer to Preprocessor and Postprocessor. |
Properties |
Additional Configuration Properties allows you to configure service call time out cache response. For information on different types of configuration properties, refer Properties. |
Front End API | Front-end API allows you map your endpoint (or) backend URL of an operation to a front-end URL. For detailed information, refer Custom Front-end URL. |
Server Events | Using Server Events you can configure this service to trigger or process server side events. For detailed information, refer Server Events. |
Note: All options in the Advanced section are optional.
Integration services accept only form-url-encoded
inputs for all the input parameters provided in the service input parameters (request input).
To forward the body of the client's request to backend as it is, select the Enable pass-through input body check box. For more details on API Proxy service, refer to How to Enable Pass-through Proxy for Operations.
You can perform the following actions in Request Input tab:
Field | Description |
---|---|
Name | It Contains a Unique Identifier. Change the name if required. |
Test Value | Enter a value. A test value is used for testing the service. |
Default Value | Enter the value, if required. The default value will be used if the test value is empty. |
Scope |
Select Request or Session. It is set to Request by default.
|
Data Type |
Select one of the following data types.
|
Encode |
Select the check box to enable encoding of an input parameter. For example, the name New York Times would be encoded as New%20York%20Times when the encoding is set to True. The encoding must also adhere to the HTML URL encoding standards. |
Description |
Provide a suitable description. |
To validate the operation details, click Save and Test. For more details, refer to Test a Service Operation.
Note: If you define parameters inside a record as the session, the session scope will not get reflected for the parameters.
In Java service, the response (output) from a backend is not parsed based on the response values. The complete response from the backend is sent to the client device.
Note: By default, the opStatus
and httpStatusCode
values for Java and JavaScript services are added as 0 and 200.
To validate the operation details, click Save and Test. For more details, refer to Test a Service Operation.
If you click Cancel, the Edit Service Parameters window will close without saving any information.
Note: To add more operations for your Java service, repeat Step 3 through Step 4.
Note: You can view the service in the Data Panel feature of Kony Visualizer. By using the Data Panel, you can link back-end data services to your application UI elements seamlessly with low-code to no code. For more information on Data Panel, click here.
If you want to edit an existing Java service, you can edit details such as service name, JAR files, operation modal details. While editing a Java service, you can change the Java service type. A Java service must be available in the Integration home screen. To add an existing Integration service, refer to Use an Existing Service.
To edit an existing Java service, follow these steps:
The operation details are displayed in the Edit Service Parameters dialog.
Copyright © 2020 Kony, Inc. All rights reserved. |