-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDummyREST.cls
55 lines (44 loc) · 1.41 KB
/
DummyREST.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Class Webinar.BO.DummyREST Extends EnsLib.REST.Operation
{
Parameter INVOCATION = "Queue";
Method sendRequest(pRequest As Ens.StringContainer, Output pResponse As Ens.StringContainer) As %Status
{
set ret = $$$OK
try {
set pResponse = ##class(Ens.StringContainer).%New()
// request URL
set url = ..Adapter.URL
// build some request body
set body = {
"query": (pRequest.StringValue),
"type": "dummy"
}
// send POST request to a dummy service
set sc = ..Adapter.PostURL(url, .httpRsp, "", body.%ToJSON())
if $$$ISERR(sc),$isobject(httpRsp),$isobject(httpRsp.Data),httpRsp.Data.Size {
return $$$ERROR($$$EnsErrGeneral,$$$StatusDisplayString(sc)_":"_httpRsp.Data.Read())
}
$$$ThrowOnError(sc)
// handle response
if $isobject(httpRsp) {
// instantiate response in json dynamic object
set jsonRsp = {}.%FromJSON(httpRsp.Data.Read())
// show response
$$$LOGINFO(jsonRsp.%ToJSON())
// retrieve some field into response
set pResponse.StringValue = jsonRsp.clientIPAddress
}
} catch ex {
set ret = ex.AsStatus()
}
quit ret
}
XData MessageMap
{
<MapItems>
<MapItem MessageType="Ens.StringContainer">
<Method>sendRequest</Method>
</MapItem>
</MapItems>
}
}