Professional Documents
Culture Documents
T24 Componentisation RESTful WS PDF
T24 Componentisation RESTful WS PDF
R E STf ul W S
R20
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Amendment History:
Revisio
Date Amended Name Description
n
2 1st July 2019 T. Aubert Support of PUT, POST, DELETE and Security
Page 2
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Copyri g h t
Copyright © Temenos Headquarters SA 2009-2020.
All rights reserved.
This document contains proprietary information that is protected by copyright. No part of this document may
be reproduced, transmitted, or made available directly or indirectly to a third party without the express
written agreement of TEMENOS UK Limited. Receipt of this material directly TEMENOS UK Limited
constitutes its express permission to copy. Permission to use or copy this document expressly excludes
modifying it for any purpose, or using it to create a derivative therefrom.
Temenos Headquarters SA
2 Rue de l’Ecole-de-Chimie,
CH - 1205 Geneva,
Switzerland
Please include your name, company, address, and telephone and fax numbers, and email
address if applicable. TAFJdev@temenos.com
Page 3
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Table of Contents
Copyright................................................................................................................................................ 3
Introduction............................................................................................................................................. 5
The target audience................................................................................................................................ 5
Get ready................................................................................................................................................ 5
The first RESTful webservice................................................................................................................. 7
The URI of the services.......................................................................................................................... 8
The structure of the response................................................................................................................. 9
@Response(…) annotation................................................................................................... 9
@QueryParam(…) annotation............................................................................................ 12
Page 4
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Intro d u c t i o n
This document describe how to create RESTful webservices using the T24 Component
Framework. This never been easier to generate such services. In fact, this can be done in a
second. All the complexities are handled by the component framework and its new
functionality: the annotations.
The reader of this document should already be familiar with the JBC language and the
component framework (*.component and *.complex). We will go through examples and will
concentrate on the RESTful webservices generation. Also, we will use “postman“ to use our
service.
Get ready
component MY.FirstRest
/* return employee lastName */
private method getEmployee(
/* The first name */
IN firstName string,
/* The lastName */
OUT lastName string
)
{
jBC: GET.EMPLOYEE
}
Page 5
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
$PACKAGE MY.FirstRest
*
* Implementation of MY.FirstRest.getEmployee
*
* firstName(IN) :
* lastName(OUT) :
*
SUBROUTINE GET.EMPLOYEE(firstName, lastName)
IF firstName = "Tony" THEN
lastName = "Curtis"
END ELSE
lastName = "Unknown"
END
RETURN
By saving, the component is automatically compiled, packaged and you can find a file
MY_FirstRest.jar in the directory <tafj_home>/data/<projectName>/jars.
Let’s assume you have a jboss app server, then deploy this file (in module) and update your
module.xml :
Then restart your app server. This is needed since this is a module, not a service (yet).
Page 6
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
In order to create a webservice from your method, only one operation is needed :
add the “@GET” annotation to your method like this and save your .component.
component MY.FirstRest
/* return employee lastName */
@GET
private method getEmployee(
/* The first name */
IN firstName string,
/* The lastName */
OUT lastName string
)
{
jBC: GET.EMPLOYEE
}
Page 7
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
The URI is the part after the <protocol>://<host>:<port>. In our case : “/my-
firstrest/employee/Tony”
is composed of :
1) /my-firstrest : the root_path (the name of the war file inherited from the name of your
.component)
2) /employee : The Service name (the name of your method in lowercase without the “get”)
Note that all services created with the T24 component Framework have one method
(services) which will show you all the URIs :
So you this URI : /my-firstrest/services will list all the available URIs like this (html output) :
Page 8
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
{
"root": {
"<OUT / INOUT parameters>": "<value>"
"response": <return value of the jBC Function>
}
}
In our first example, since the method was a SUBROUTINE (not a FUNCTION), there is
nothing to show in the “response”.
@Re s p o n s e ( … ) an n o t a t i o n
The above structure of the response can be modified by using the @Response annotation.
To describe it, edit your component like this :
component MY.FirstRest
{
"my": {
"new": {
"response": {
"lastName": "Curtis"
}
}
}
}
Page 9
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Chan g i n g th e def a u l t be h a v i o u r s .
Appart changing the root path (the name of the war file) mostly everything can be modified
using annotations. In this chapter we will see how.
Example :
@Path("/training/rest")
component MY.FirstRest
Page 10
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
You can change the default with the @Path annotation for the method. At that point there is
a lot of validation being done at the component framework level.
@Path("/training/rest")
component MY.FirstRest
1) All IN, INOUT, MEMBER variables, if not annotated as @QueryParam must be in the
Path.
Page 11
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
@Qu ery P a r a m ( … ) an n o t a t i o n
Each (not OUT) variable can be annotated by the @QueryParam annotation. The
@QueryParam annotation indicates that the parameter is not part of the URI anymore, but
instead in the html query parameter.Example :
@Path("/training/rest")
component MY.FirstRest
/* return employee lastName */
@GET
@Response("my.new.response.structure")
@Path("/temenos/person")
private method getEmployee(
/* The first name */
@QueryParam
IN firstName string,
. . .
}
Makes that the http request is now :
http://localhost:9089/my-firstrest/training/rest/temenos/person?firstName=Tony
A QueryParam can have an alias. Example : @QueryParam(“name”) will make the request :
http://localhost:9089/my-firstrest/training/rest/temenos/person?name=Tony
Page 12
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
@Path("/xxx/{country}/{city}") .../xxx/{country}/{city}?name= ….
private method getEmployee(
IN country string,
IN city string,
@QueryParam("name")
IN firstName string,
OUT lastName string
)
Page 13
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Page 14
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Let’s first get back to our favourite component, an modify the getEmployee method like this :
component MY.FirstRest
$PACKAGE MY.FirstRest
*
* Implementation of MY.FirstRest.getEmployee
*
* firstName(IN) :
*
FUNCTION GET.EMPLOYEE(firstName)
IF firstName = "Tony" THEN
RETURN "Curtis"
END ELSE
RETURN "Unknown"
END
RETURN
Page 15
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Page 16
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Result :
Let’s first see what happen with lists. Modify you implementation like this :
component MY.FirstRest
/* return employee lastName */
@GET
private method getEmployee : list<string> (
/* The first name */
IN firstName string
)
{
jBC: GET.EMPLOYEE
}
FUNCTION GET.EMPLOYEE(firstName)
$USING TF.List
RET = ""
IF firstName = "Tony" THEN
TF.List.add(RET, "Curtis")
TF.List.add(RET, "Stark")
TF.List.add(RET, "Blair")
TF.List.add(RET, "Parker")
END ELSE
RETURN "Unknown"
END
RETURN RET
Page 17
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Ret u r n i n g co m p l e x str u c t u r e s
Here we will (again) modify our component and implementation to return a complex
structure. To do so, create a new Complex and edit it like this :
complex Employee
@Containment byValue
classes {
NameAndAge
{
lastName : string
age : number
}
}
Page 18
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
component MY.FirstRest
Page 19
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
Redeploy the war and the jar, restart your app server, and redo the same request :
Page 20
T 2 4 C o m p o n e n ti s a ti o n R E STf ul
WS
- @PUT & @POST are supporting, in addition to the @QueryParam, the @FormParam. The
validation rules (no duplicates, not in the @Path, …) are exactely the same.
Se c u r i t y
You method can be annotated with the standard following security annotations
RolesAllowed(...)
DeclareRoles(...)
DenyAll
PermitAll
RunAs(...)
Page 21