T3IRFX5 Published API 201809
T3IRFX5 Published API 201809
2
3
4
Published APIs map and orchestrate between Open UA requirements and services
rendered by Provider APIs.
5
The objective of lab exercise 7 is to design a Published API service
6
To develop a Published API service do the following
1. In the workbench, click on APIs > Import API definition, browse the target OAS
definition for the published API service
2. Supply a service Id and click on Generate. This generates service XML and mock
response for published API. Download the generated artefacts
3. A Published API service project is no different from a Provider API service project
in eclipse. Follow the same steps to create the service project using the irf-
service-archetype. Copy the downloaded artefacts into service project. Build and
install the publisher service project.
4. Add this as a dependency to the container project.
5. Verify in the management service that the new service is listed
7
Test the Published API from a REST client using the status report endpoint URL. The
mock response is returned as expected.
Now test the Provider API endpoint individually. The request hits T24 and generates
a T24 response according to its swagger schema. This endpoint route is the intended
target of published API.
8
Since the 3rd party UA request to Published service must be redirected to Provider API
service, modify camel routes to replace the mock responder with a call to Provider
API route
(1) The API call to GET /api/v1.0.0/published/payments/{accountId}/statusreport, is
redirected to the corresponding Provider API route
(2) Provider API executes the call and
(3) Generates the response in accordance with its OAS definition
9
10
11
The request payload to Published API has to be mapped to a dissimilar Provider API
request schema and Provider API response has to be mapped to Published API
response schema. The exercise uses Swagger Codegen which is an open source code-
generator to build server stubs and client SDKs directly from a OAS document. These
stubs can then be used to map the two schemas.
1. Create a sample project, published-models, for the code generator, in eclipse -
File > new > project > maven-archetype-archetype (any archetype). Copy
swagger-codegen-cli-2.2.1.jar to the root of your project
2. Verify the .jar using the following command from command line
java -jar swagger-codegen-cli-2.2.1.jar help generate
3. Amend pom.xml of published-models project to add required dependencies
indicated in slide
[Note: Maven force update may be required on the models project if the project
shows the error - Project configuration is not up-to-date with pom.xml. Select:
Maven->Update Project... from the project context menu]
12
4. Navigate to the models project path in windows command prompt. Generate java
code using the Published API and Provider API OAS document
java -jar swagger-codegen-cli-2.2.1.jar generate -i ..\published-
fundsTransfer\src\main\resources\api-docs\published-fundsTransfer-v1.0.0-
swagger.json -l java
java -jar swagger-codegen-cli-2.2.1.jar generate -i ..\provider-
fundsTransfer\src\main\resources\api-docs\provider-fundsTransfer-v1.0.0-
swagger.json -l java
Note : You may need to alter the Java compiler level and JRE.
5. View generated java code
6. Run as Maven > Install. Add the model project dependency to the Published API
service project
13
In the publisher service project, write a new Java class that implements the Apache
Camel Processor. The Processor interface can be used to implement the consumers
of message exchanges.
Switch to the Java perspective
• Right click on the package under src/main/java > New > Java class
• Supply a name for the class - FTInitiationRequestProcessor
• Add the Apache camel Processor interface.
This creates FTInitiationRequestProcessor.java with a class that implements
Processor. It has one public method process. Add the mapping logic in this method.
14
Write the mapping logic using the getter and setter methods generated by swagger
code generator for the two schemas. In the sample partial code snippet, the fields of
Published API request schema is set to fields of Provider API request.
15
Similarly write a new java class for mapping Provider API response to Published API
response schema
• Right click on the package under src/main/java > New > Java class
• Supply a name for the class - FTStatusReportResponseProcessor
• Add the Apache camel Processor interface.
This creates FTStatusReportResponseProcessor.java with a class that implements
Processor. It has one public method process. Add the mapping logic in this method.
16
In the sample code snippet, fields from the Provider API response schema is mapped
to the Published API response schema.
17
Add the mapping processor implementation in the route and declare the beans in the
service XML. Build and install.
18
Test the Published API GET request for status report from a REST client. This time, the
transformed response suited to the Published API schema is generated.
19
Test the POST request. The newly added request processer successfully maps the
Published API request payload to Provider API request body. The Provider API
forwards the request to T24 which successfully initiates an FT payment generates a
successful response. A similar response mapping processor needs to be written to
map the Provider API response to the Published API response schema.
20
To build a deployable war file,
1) On the container project, run a maven build with Goals = clean install –
PbuildForJMS.
2) Alternatively, in the pom.xml, set the buildForJMS profile to be true and
buildForStandalone and buildForTCS profiles to be false
On successful build, a war file with the name irisR18.war is generated under target
folder of the container project. Deploy the war file in the jboss application server.
21
22
23