· Mar 15

Event onPostDispatch %CSP.Rest or similar

Hi all,

For a requirement of the customer, we have a BS Rest api with a lot of methods, we need to get the IP of the caller, the method and what is the time that the API has taken to process.

I've found the event onPreDispatch where I can take the IP, ClassMethod, etc.. I'm using a global variable to save this information.

ClassMethod OnPreDispatch(pUrl As %String, pMethod As %String, ByRef pContinue As %Boolean) As %Status
	set ^CallApi($CLASSNAME(),$JOB,"url") = pUrl
	set ^CallApi($CLASSNAME(),$JOB,"method") = pMethod
	set ^CallApi($CLASSNAME(),$JOB,"Start") = $HOROLOG
	set ^CallApi($CLASSNAME(),$JOB,"remote_addr") = %request.CgiEnvs("REMOTE_ADDR")
	set pContinue = 1
	quit $$$OK

Now, I need to get the end time, and save all the information using a BO that save the information out of IRIS (Async)

Is there any method/event/whatever that is fired when has finished the call? Then I can kill the global variable and get the end time, call to the out process, etc..

Thanks in advance

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1.3 (Build 389U) Wed Feb 15 2023 14:50:06 EST
Discussion (5)2
Log in or sign up to continue


As you are in Aync mode, it's a bit tricky to get the end time. In sync mode, you just have to wait for the answer to be back.

In this case I would use the session id from the message that is going out of the business service to the BO.

So in the BS, try something like this:

Method OnProcessInput(
    pDocIn As %RegisteredObject,
    Output pDocOut As %RegisteredObject) As %Status
    // here you need to pass the jobid from the %CSP.REST that is invoking the BS
    set tJobId = pDocIn.JobID
    // your code here
    set ^CallApi($CLASSNAME(),tJobId,"sessionid") = ..%SessionId
    set pDocOut = pDocIn
    quit $$$OK

Then in the BO, you can use the session id to get the information from the global.

Method MyAsyncMethod(
    pRequest As %RegisteredObject,
    Output pResponse As %RegisteredObject) As %Status
    set tSessionId = ..%SessionId
    // lookup for the good session id
    for {
        set tClassname = $ORDER(^CallApi(tClassname))
        for {
            set tJobId = $ORDER(^CallApi(tClassname,tJobId))
            if ^CallApi(tClassname,tJobId,"sessionid") = tSessionId {
                set ^CallApi(tClassname,tJobId,"End") = $HOROLOG
    // your code here
    quit $$$OK

I hope this helps.

I don't think there is a callback method available.

One option could be to subclass %CSP.REST and use your subclass instead of %CSP.REST.

You subclass can be something like:

Class MyCustomCSP.REST Extends %CSP.REST

ClassMethod DispatchRequest(url As %String, method As %String, forwarded As %Boolean = 0, args...) As %Status
	Set sc=##super(url,method,forwarded,.args)
	; your "onPostDispatch" code here 
	Quit sc