0% found this document useful (0 votes)
72 views

IRIS Creating Publisher API

Uploaded by

bablujp72
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views

IRIS Creating Publisher API

Uploaded by

bablujp72
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Creation of Publisher API

In IRIS & T24 Transact


CREATION of PUBLISHER API in T24 Transact ENQUIRY
Publisher APIs are built over PROVIDER APIs so that the JSON structure and field
values of PROVIDER API request and response can be modified as per the end user
requirement at IRIS layer.
Step 1: From the provider APIs api-docs, take the swagger JSON, modify as per your
requirement of JSON structure and save it.

Here, the path is changed only.

mb-api-publish-v1.0.0-swagger.json
Modified JSON File:
Step 2: Check the correctness of that swagger JSON via the open-source swagger
editor, the URL of which is given below. If any structural errors are thrown, resolve it.
htps://editor-next.swagger.io/
Step 3: Import this swagger defini�on in workbench using the “Import API
defini�on” op�on and download the publisher zip file.

MD Shibli Mollah
T24 Technical Analyst
Download the zip file.
Step 4: Create a maven project with archetype-service catalog and import the zip file
downloaded in the previous step.

--------------------------------------------------------------------------------------------------------------------------------------
Step 5: Navigate to publisherProject - Published-AcBal
<<publisherProject>>\src\main\java\ com.api.service
package directory, right click and select New -> Java -> Class and enter the
class name as <<AnyRelevantName>>Mapper and add the interface named
“Processor” under Interfaces.

MD Shibli Mollah
T24 Technical Analyst
MD Shibli Mollah
T24 Technical Analyst
Step 6: The mapper class will be generated as shown below.

The process() method in the mapper must have the code logic to transform the provider API
to publisher API and vice versa.
The code logic must be in such a way that the fields present in the JSON response body of
the provider API are mapped to the fields defined in the swagger of published API using the
published API swagger classes generated.

Mapper class for ENQUIRY based API:


For ENQUIRY API, we will require only a response mapper since we do not send a
request body.
Below are the steps to create a Response Mapper for an ENQUIRY API based on
ACCOUNT applica�on.
a. As men�oned in step 6, create a mapper class with a relevant name (UpdateAcBalInfo)
and Processor interface. In the generated mapper java file, comment the constructor (if not
required). Only the process method will be used.
b. To map the fields of the provider API, we must first receive the header and JSON body
content (containing header and body sec�on of JSON response) of the provider API a�er
ensuring the htp response code is 200. Below is the corresponding code line. On confirming
it is a successful response, we obtain the JSON response – header and body sec�on.

public void process(Exchange exchange) throws Exception {


// TODO Auto-generated method stub
String HttpResponseCode =
exchange.getIn().getHeaders().get("CamelHttpResponseCode").toString();
Message in = exchange.getIn();
String response = (String) in.getBody(String.class);
JSONObject = new JSONObject(response);

MD Shibli Mollah
T24 Technical Analyst
JSONObject jsonHeader = jsonObject.getJSONObject("header");
String updateResponse = null;

if (HttpResponseCode.equals("200")) {

JSONObject jsonBody =
jsonObject.getJSONArray("body").getJSONObject(0);

Receive the header and body content of provider JSON response.


String responseCode = null;
String accountNo = null;
String alternateAccountNo = null;
String currency = null;
String balance = null;

try {
responseCode = jsonBody.get("response").toString();
accountNo = jsonBody.get("accountId").toString();
alternateAccountNo = jsonBody.get("accountIBAN").toString();
currency = jsonBody.get("currency").toString();
balance = jsonBody.get("availableBalance").toString();
} catch (Exception e) {}

jsonBody.remove("accountId");
jsonBody.remove("accountIBAN");
// jsonBody.remove("currency");
jsonBody.remove("availableBalance");

jsonBody.put("accountNo", accountNo);
jsonBody.put("alternateAccountNo", alternateAccountNo);
jsonBody.put("balance", balance);

jsonHeader.remove("audit");
jsonHeader.remove("page_start");
jsonHeader.remove("page_token");
jsonHeader.remove("total_size");
jsonHeader.remove("page_size");
jsonHeader.remove("status");

jsonHeader.put("statusCode", responseCode);
updateResponse = "{\"header\":" + jsonHeader + ",\"body\":" + jsonBody
+ "}";
}

ObjectMapper om = JSONHelper.createObjectMapper();
JsonNode modifiedResponse = om.readTree(updateResponse);
in.setBody(modifiedResponse);
}

Sample Mapper Class:

UpdateAcInfo.java UpdateAcBalInfo.java UpdateAcBalInfo.java

c. Edit the service.xml of the publisher API by adding this ResponseMapper


(UpdateAcBalInfo) as a process a�er redirec�ng it to the provider API.
MD Shibli Mollah
T24 Technical Analyst
<get uri="/party/accounts/{accountId}" id="getAcBal">
<param name="accountId" type="path" required="true"/>
<!-- Publisher API Uri -->
<to uri="direct-vm:party-v1.0.0.v1.0.0.getAcBal"/>
</get>
</rest>
<route id="direct-vm.party-v1.0.0.v1.0.0.getAcBal">
<from uri="direct-vm:party-v1.0.0.v1.0.0.getAcBal"/>
<!-- Provider API Uri -->
<to uri="direct-vm:party-accounts.v1.0.0.getAcBal"/>
<process ref="UpdateAcBalInfo"/>
</route>
<route id="direct.mockResponder">
<from uri="direct:mockResponder"/>
<process ref="mockResponder"/>
</route>

Add the bean: OPTIONAL


<bean id="UpdateAcBalInfo" class="com.api.service.UpdateAcBalInfo"/>

party-v1.0.0-published-myacbal-service-v1.0.0.xml party-v1.0.0-published-myacbal-service-v1.0.0.xml

Special Note: We must redirect the URI of the other versions of the service xml’s of
the Publisher API by changing like this, otherwise war file deployment will be failed.
<route id="direct-vm.party-v1.0.0.v1.0.getAcBal">
<from uri="direct-vm:party-v1.0.0.v1.0.getAcBal"/>
<!-- OWN PUBLISHER API Uri -->
<to uri="direct-vm:party-v1.0.0.v1.0.0.getAcBal"/>
</route>

MD Shibli Mollah
T24 Technical Analyst
party-v1.0.0-published-myacbal-service-v1.0.xml party-v1.0.0-published-myacbal-service-v1.xml

Step 7: Maven Install the publisher API project(s).

Published-AcBal-0.0.1-SNAPSHOT.jar Published-AcBal-0.0.1-SNAPSHOT.jar

MD Shibli Mollah
T24 Technical Analyst
Step 8: Include the publisher API and provider API project(s) dependency in
the container project’s pom.xml and perform maven install.

Step 9: Create a new bean with any relevant name for “id” atribute in
applica�onContext.xml of the container project for the mapper class created.
Enable Basic Auth/JWT required.
<!-- Response mapper added -->
<bean id="UpdateAcBalInfo" class="com.api.service.UpdateAcBalInfo">
</bean>

MD Shibli Mollah
T24 Technical Analyst
SAVE it.

PublishedAcBalContainer.war PublishedAcBalContainer.war

Step 10: Deploy the war in applica�on server (or) jety server.

Step 11: APIs can now be accessed with structure of published API JSON and
the corresponding response is now formed as per requirement.

MD Shibli Mollah
T24 Technical Analyst
Below screenshots show the JSON requests and responses for the examples
explained in this document.

AcBalanceContainer_response.json

MD Shibli Mollah
T24 Technical Analyst
UpdatedAcBalanceContainer_response.json
A�er changing the Java Code to meet our expecta�on.

UpdateAcBalInfo.java

MD Shibli Mollah
T24 Technical Analyst
Final_Published_response.json

MD Shibli Mollah
T24 Technical Analyst

You might also like