You are on page 1of 29

Cellcube Service Maintaining

Plugin for SOAP request


Plugin for SOAP request
svc_xml_generic:request/8

.xml: SOAP request template

.mapping: XPathes to parse required nodes or values from SOAP response

.error: XPathes to indentify failure SOAP response

svc_xml_generic:request/12

svc_http:request/11

svc_http:rest_request/10

Supported XPath Expressions


svc_xml_generic:request/8
XML request template

Where is it?
opt/cellcube/conf/xml_generic/

How to create it?


1. Copy the original request content in XML
2. Replace the variable parts with service session variables

Examples
svc_xml_generic:request/8
XML request template

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="https://orientation.campusen.sn/selection/service/soap">
<soapenv:Header/>
<soapenv:Body>
<![CDATA[
<Data>
<operateur>OAcjRk1</operateur>
<numero_ine>1234567890</numero_ine>
<date_naissance>19800101</date_naissance>
</Data>
]]>
</soapenv:Body>
</soapenv:Envelope>
svc_xml_generic:request/8
XML request template

<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:soap="https://orientation.campusen.sn/selection/service/soap">
<soapenv:Header/>
<soapenv:Body>
<![CDATA[
<Data>
<operateur>OAcjRk1</operateur>
<numero_ine><?DYNSTRING "$(tango.INE.)"?></numero_ine>
<date_naissance><?DYNSTRING "$(tango.BDAY.)"?></date_naissance>
</Data>
]]>
</soapenv:Body>
</soapenv:Envelope>
svc_xml_generic:request/8
Dynamical String for XML request template

<?DYNSTRING "$(SvcName.VarName.)"?>
Set the specific session variable’s value, which can only be integer, atom or string.

Session Variable Dynamical String Result

Name $(tango.id_type.)
Session crashed
<?DYNSTRING “$
[{“LIGHT”, due to the value is
(tango.id_type.)”?>
Value “profile_LIGHT”}, {“FULL”, not a string.
“profile_FULL”}]

Name $(tango.retries.)
<?DYNSTRING “$
“2”
(tango.retries.)”?>
Value “2”
svc_xml_generic:request/8
Dynamical String for XML request template

<?DYNSTRING "$(Attr.)"?>
Attr is one of the following session attributes: ussd_code, subscription, language, bearer,
anonymous, vlr, msisdn, imsi, direct_access, imei, ussdsize, end_ussdsize, operator
<?DYNSTRING "$(random.Number.)"?>
Set the random number in range [1, Number].
<?DYNSTRING "$(list.SvcName.VarName.IdxList.)"?>
Set item value of specific list session variable

Session Variable Dynamical String Result

Name $(tango.id_type.) <?DYNSTRING


“$
[{“LIGHT”, “profile_LIGHT”
(list.tango.id_type.
Value “profile_LIGHT”}, {“FULL”, [1,2].)”?>
“profile_FULL”}]
svc_xml_generic:request/8
Dynamical String for XML request template

<?DYNSTRING "$(conf.AppName.Param.)"?>
<?DYNSTRING "$(conf.AppName.Param.IdxList.)"?>
Set the specific config value, or its specific item value.

Config Dynamical String Result

Name pservices::active_auth <?DYNSTRING


“$
“false”
(conf.pservices.acti
Value false ve_auth.)”?>

<?DYNSTRING
Name pservices::barring_acl_code
“$
(conf.pservices.bar “all_imsi”
ring_acl_code.
Value [{1,all_imsi},{2,all_msisdn}]
[1,2].)”?>
svc_xml_generic:request/8
Dynamical String for XML request template
<?DYNSTRING "$(date.Format.Type.)"?>
Set date time with the specific format.
Type could be utc or local, indicating set UTC0 or local date time value.
Format composes of the following directives and plain texts:

Directive Meaning

%a locale's abbreviated weekday name (Sun..Sat)

%A locale's full weekday name, variable length (Sunday..Saturday)

%b locale's abbreviated month name (Jan..Dec)

%B locale's full month name, variable length (January..December)

%C century (year divided by 100 and truncated to an integer) [00-99]

%d day of month (01..31)

%D date (mm/dd/yy)

%e day of month (1..31)


svc_xml_generic:request/8
Dynamical String for XML request template

<?DYNSTRING "$(date.Format.Type.)"?>

Directive Meaning

%F same as %Y-%m-%d

%H hour (00..23)

%I hour (01..12)

%j day of year (001..366)

%k hour (0..23)

%l hour (1..12)

%m month (01..12)

%M minute (00..59)

%p locale's upper case AM or PM indicator

%P locale's lower case am or pm indicator


svc_xml_generic:request/8
Dynamical String for XML request template

<?DYNSTRING "$(date.Format.Type.)"?>

Directive Meaning

%r time, 12-hour (hh:mm:ss [AP]M)

%R time, 24-hour (hh:mm)

%s seconds since `00:00:00 1970-01-01 UTC'

%sx seconds since `00:00:00 1970-01-01 UTC' print in hexa

%S second (00..60); the 60 is necessary to accommodate a leap second

%T time, 24-hour (hh:mm:ss)

%u day of week (1..7); 1 represents Monday

%V week number of year with Monday as first day of week (01..53)

%y last two digits of year (00..99)

%Y year (1970...)
svc_xml_generic:request/8
Dynamical String for XML request template

<?DYNSTRING "$(date.Format.Type.)"?>

Example Result

<?DYNSTRING "$(date.%F %Thehe.local.)"?> 2017-12-01 12:50:31hehe

<?DYNSTRING "$(date.%F %T,%a.utc.)"?> 2017-12-01 04:52:47,Fri

<?DYNSTRING "$(date.%F %k:%M:%S, %s, 2017-12-01 4:56:13, 1512104173,


%sx.utc.)"?> 5a20e0ed
svc_xml_generic:request/8
Dynamical String for XML request template

Merge multiple strings:


<?DYNSTRING "$(date.%Y%m%d%H%M%S.utc.)$(random.100.)"?> =>
20171201045247039
svc_xml_generic:request/8
Mapping File

Where is it?
opt/cellcube/conf/xml_generic/

Used to get specific variables from SOAP response in XML format.

Stores an erlang term, i.e. a list of decoding directives:

[{value,"TXNSTATUS","/descendant::COMMAND/TXNSTATUS/text()"},
{xmlnode,"wallet_node","/descendant::COMMAND/DATA/WALLETTYPE"},
{complex,"/descendant::COMMAND/DATA/WALLETTYPE",
[{value,"cpx_name","/descendant::WTNAME/text()"},
{value,"cpx_id","/descendant::WID/text()"},
{value,"cpx_grade","/descendant::GRADE/text()"}
]}
].
svc_xml_generic:request/8
Mapping File
{value, VarName, XPath}
Get the text or attribute value via XPath, then store the value into session variable $
(SvcName.VarName.). SvcName is specified in the plugin’s arguments. If XPath
corresponds to multiple items, the stored value is a list.
{xmlnode, VarName, XPath}
Get the node via XPath, and store it into session variable $(SvcName.VarName.), then
deal with it in concrete plugin. If XPath corresponds to multiple nodes, the stored value is
a list.
{complex, XPath, SubConds}
Search the node corresponding to XPath, and get the values matching SubConds.
svc_xml_generic:request/8
Mapping File example: single node

<?xml version="1.0"?> [{"TXNSTATUS","100"},


<COMMAND> {"wallet_node",
<TXNSTATUS>200</TXNSTATUS> {xmlElement,'WALLETTYPE',...}},
<TRID>1234567890</TRID> {"cpx_name","John"},
<DATA> {"cpx_id","111"},
<WALLETTYPE> {"cpx_grade","A"}
<WTNAME>John</WTNAME> ]. parsing result
<WID>111</WID>
<GRADE>A</GRADE>
</WALLETTYPE>
</DATA>
</COMMAND>
SOAP response [{value,"TXNSTATUS","/descendant::COMMAND/TXNSTATUS/text()"},
{xmlnode,"wallet_node","/descendant::COMMAND/DATA/WALLETTYPE"},
{complex,"/descendant::COMMAND/DATA/WALLETTYPE",
[{value,"cpx_name","/descendant::WTNAME/text()"},
{value,"cpx_id","/descendant::WID/text()"},
{value,"cpx_grade","/descendant::GRADE/text()"}
]}
]. mappings
svc_xml_generic:request/8
Mapping File example: multiple nodes

<?xml version="1.0"?> [{"TXNSTATUS","100"},


<COMMAND> {"wallet_node",
<TXNSTATUS>200</TXNSTATUS> {xmlElement,'WALLETTYPE',...}},
<TRID>1234567890</TRID> {"cpx_name",["Will","John"]},
<DATA> {"cpx_id",["222","111"]},
<WALLETTYPE> {"cpx_grade",["B","A"]}
<WTNAME>John</WTNAME> ]. parsing result
<WID>111</WID>
<GRADE>A</GRADE>
</WALLETTYPE> reverted order
<WALLETTYPE>
<WTNAME>Will</WTNAME>
<WID>222</WID>
[{value,"TXNSTATUS","/descendant::COMMAND/TXNSTATUS/text()"},
<GRADE>B</GRADE>
{xmlnode,"wallet_node","/descendant::COMMAND/DATA/WALLETTYPE"},
</WALLETTYPE>{complex,"/descendant::COMMAND/DATA/WALLETTYPE",
</DATA> [{value,"cpx_name","/descendant::WTNAME/text()"},
</COMMAND> {value,"cpx_id","/descendant::WID/text()"},
{value,"cpx_grade","/descendant::GRADE/text()"}
SOAP response ]}
]. mappings
svc_xml_generic:request/8
Mapping File example: irregular nodes

<?xml version="1.0"?>
<COMMAND> [{"TXNSTATUS","100"},
<TXNSTATUS>200</TXNSTATUS> {"wallet_node",
<TRID>1234567890</TRID> {xmlElement,'WALLETTYPE',...}},
<DATA> {"cpx_name",
<WALLETTYPE> [{error,not_found},"Will","John"]},
<WTNAME>John</WTNAME> {"cpx_id",["333","222","111"]},
<WID>111</WID> {"cpx_grade",
<GRADE>A</GRADE> [{error,not_found},
</WALLETTYPE> {error,not_found},
<WALLETTYPE> "A"]}
<WTNAME>Will</WTNAME> ]. parsing result
<WID>222</WID>
<GRADE/>
</WALLETTYPE>
<WALLETTYPE>
<WTNAME></WTNAME>
<WID>333</WID>
</WALLETTYPE> same mapping
</DATA> no GRADE
</COMMAND>
SOAP response
svc_xml_generic:request/8
Error File
Where is it?
opt/cellcube/conf/xml_generic/

Used to directly indentify failure response. If any one of listed XPathes is found,
the plugin redirects to error or the default link. Although found a XPath, the
corresponding value won’t be saved into session, but the label is. So its usage is
very limited.
[{"TXNSTATUS","/descendant::COMMAND/TXNSTATUS/text()"},
{"wallet_node","/descendant::COMMAND/DATA/WID/text()"}].
label XPath always points a value

Normally stores an empty list:

[].
svc_xml_generic:request/12
This plugin extends svc_xml_generic:request/8 by providing several extra
arguments.
http_method specifies the HTTP conversation method, only supports
GET/PUT/POST. So that the plugin can handle REST requests.
header_enrichment_from_xmlhttp, host and port: If
header_enrichment_from_xmlhttp is true, the plugin searches config
pserver::xmlhttp_hosts for customized HTTP headers by querying host and port.
svc_http:request/11
This plugin sends http request to the specific URL and extracts the specific
variables and their values from response.
If http request complete successfully, the session will be filled with extracted
variables/values then redirect to the ok page.
If http request fails, redirect to the nok page.
url specifies the URL to be requested.
escape specifies whether encode url according to RFC2396 and HTML4.0 B2.1:
http://www.foo.com/search?你好 
http://www.foo.com/search?%E4%BD%A0%E5%A5%BD
svc_http:request/11
routing specifies the appropriate HTTP route.
See config pdist::httpclient_routing
service_name specifies the service name of output variables.
decode_fun specifies the function for decoding the HTTP response. There are only
two options:
http_parser:parse: parses HTTP response format like
“Username=zsmart&Password=zsmart&ACTION_ID=AddFellowISDN” 
[{{service_name, “Username”}, “zsmart”}, {{service_name, “Password”}, “zsmart”},
{{service_name, “ACTION_ID”}, “AddFellowISDN”}]
json_parser:parse: parses JSON response format like
{“Username” : ”zsmart”, “Password” : “zsmart”, “ACTION_ID” : “AddFellowISDN”} 
{{service_name, “json”}, {“Username” : ”zsmart”, “Password” : “zsmart”, “ACTION_ID” :
“AddFellowISDN”}}
svc_http:request/11
filter specifies list of variables to be retrieved. Multiple variables are comma-
separated, '*' means all, empty means none.
e.g. var1,var2,var3
timeout specifies the request timeout in milliseconds.
method specifies the http request method, could be “post” or “get”.
svc_http:rest_request/10
This plugin sends REST http request to the specific URL and parse result from
response.
If http request completes, and the result is parsed successfully, the session will redirect to
the ok page.
If http request fails, redirect to the nok page.
method specifies the http request method, could be “post”, “get”, “put” or “delete”.
url specifies the URL to be requested.
header specifies the Herader of request.
It should be format as Tag1:Value1${new_line}Tag2:Value2...
body specifies the the Body of request.
routing specifies the appropriate HTTP route.
See config pdist::httpclient_routing
svc_http:rest_request/10
parse_fun specifies the function for parsing the HTTP response. Format:
Module:Function.
The M:F accepts Args (Session, HTTPCode, ResponseHeader, ResponseBody)
Return {ok, NewSession}|{nok, NewSession}.
Default value is http_parser:rest_parse, return ok only when HTTPCode is 200
timeout specifies the request timeout in milliseconds.
Supported XPath Expressions
Cellcube only supports XPath 1.0:
https://www.w3.org/TR/1999/REC-xpath-19991116/

XPath tutorial: https://www.w3schools.com/xml/xpath_intro.asp


Questions ?
Thank You !

You might also like