T24 Componentisation RESTful WS
T24 Componentisation RESTful WS
Revi s i o
Dat e Ame n d e d Na m e De s c r i p t i o n
n
Bashe e r
4 12 th April 2021 R21 AMR review
Aham e d
2
T24 Co m pon e n tisation RESTful WS
Copyri g h t
If you have any com m e n t s reg a r di n g this man u al or wish to repor t any error s in the docu m e n t a t i o n ,
plea s e docu m e n t the m and send the m to the add r e s s below:
Technology Depa r t m e n t
Teme no s Hea d q u a r t e r s SA
2 Rue de l’Ecole- de- Chimie,
CH - 1205 Geneva,
Switze rl a n d
Pleas e includ e your na m e , comp a n y, addr e s s, and telep h o n e and fax num b e r s , and email add r e s s if
applica bl e. TAFJdev@t e m e n o s . c o m
4
T24 Co m pon e n tisation RESTful WS
Intro d u c t i o n
This docu m e n t descri b e how to crea t e RESTful webs e r vic e s using the T24 Compo n e n t Fra m e w o r k . This
neve r bee n easie r to gene r a t e such servic e s. In fact, this can be done in a secon d. All the compl exiti es
are handl e d by the compo n e n t fram e w o r k and its new function ality: the annot a t i o n s.
The rea d e r of this docu m e n t shoul d alre a dy be familiar with the JBC langu a g e and the compo n e n t
fram e w o r k (*.com po n e n t and *.complex). We will go throu g h exa m pl e s and will conc e n t r a t e on the
RESTful webs e r vic e s gene r a t io n. Also, we will use “post m a n “ to use our servic e.
Get ready
By saving, the compo n e n t is auto m a ti c ally compile d, pack a g e d and you can find a file MY_FirstR e s t .ja r in
the direct o r y <t afj_hom e > / d a t a / < p r o j e c t N a m e > / j a r s .
Let’s assu m e you have a jboss app serve r, then deploy this file (in modul e) and upd a t e your modul e.x ml :
<module xmlns="urn:jboss:module:1.0" name="com.temenos.t24">
<resources>
<!-- Insert resources here -->
<resource-root path="./services/MY_FirstRest.jar" />
Then rest a r t your app serve r. This is nee d e d since this is a module, not a service (yet).
6
T24 Co m pon e n tisation RESTful WS
The first RESTf ul web s e r v i c e
In orde r to crea t e a webs e r vic e from your met ho d, only one oper a ti o n is nee d e d :
add the “@GET” annot a t i o n to your met ho d like this and save your .compo n e n t .
component MY.FirstRest
/* return employee lastName */
@GET
private method getEmployee : String(
/* The first name */
IN firstName string,
/* The lastName */
OUT lastName string
)
{
jBC: GET.EMPLOYEE
}
8
T24 Co m pon e n tisation RESTful WS
The stru c t u r e of th e res p o n s e
The respo n s e will always have the JSON form a t .
The default respo n s e struc t u r e is :
{
"root": {
"<OUT / INOUT parameters>": "<value>"
"response": <return value of the jBC Function>
}
}
@Re s p o n s e ( … ) an n o t a t i o n
The above struc t u r e of the respo n s e can be modified by using the @Respo n s e annot a t io n. To desc ri b e it,
edit your com po n e n t like this :
component MY.FirstRest
Chan g i n g th e def a u l t be h a v i o u r s .
Appar t chan gi n g the root path (the nam e of the war file) mostly everyt hi n g can be modified using
annot a ti o n s. In this cha pt e r we will see how.
10
T24 Co m pon e n tisation RESTful WS
3) If a variabl e is annot a t e d with @QueryP a r a m , it cannot be in the @Pat h.
Befor e going in exam pl e s, let’s desc ri b e the @QueryP a r a m …
@Path("/xxx/{country}/{city}")
.../xxx/ { c o u n t r y } / { c i t y } ? n a m e = ….
12
T24 Co m pon e n tisation RESTful WS
private method getEmployee :
String(
IN country string,
IN city string,
@QueryParam("name")
IN firstName string,
OUT lastName string
)
14
T24 Co m pon e n tisation RESTful WS
Ret ur n valu e (FU NCTIO N s )
Let’s first get back to our favourit e compo n e n t , an modify the getE m pl oy e e met ho d like this :
component MY.FirstRest
As mentionned earlier, the « default » structure of the response is root.response. Please refer to the specific
chapter if you want to modify it. Unlike the OU / INOUT variables, the response can be a list<...> a complex
type or a list<complex type>.
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
16
T24 Co m pon e n tisation RESTful WS
Ret u r n i n g co m p l e x stru 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
}
}
component MY.FirstRest
Redeploy the war and the jar, restart your app server, and redo the same request :
18
T24 Co m pon e n tisation RESTful 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(...)
20