Is their a way to make an http adapter wait a certain number of seconds?

I have an http adapter that calls out to a web service and is looking for a "Completed" response. I want the adapter to wait a certain number of seconds before calling out again to get a response. I have tried setting the retry interval on the business operation but that does not do it. See my code below.

While pResponse.StringValue = "Processing" {
set tSC=..Adapter.PostURL(tURL,.tHTTPResponse,,tId)
do tHTTPResponse.Data.Rewind()
set pResponse.StringValue = tHTTPResponse.Data.Read(3000000,.tSC)
$$$TRACE("Second Response: "_pResponse.StringValue)

}

  • 0
  • 0
  • 195
  • 3
  • 2

Answers

HANG command exists.

You can put between each command (if you have enought time ;-)) ) an hang command:

while response.StringValue="Processing" {
hang 5 // pause for 5 seconds
// get new response
}

Regards and
have a nice day
Julius

Redefine HTTP adapter like this:

Class Production.Adapter.HTTPOutboundAdapter Extends EnsLib.HTTP.OutboundAdapter
{

Method PostURL(pURL As %String, Output pHttpResponse As %Net.HttpResponse, pFormVarNames As %String, pData...) As %Status [ CodeMode = expression ]
{
..SendFormDataArray(.pHttpResponse, "POST", ..GetRequest(), .pFormVarNames, .pData, pURL)
}

ClassMethod GetRequest() As %Net.HttpRequest
{
    set request = ##class(%Net.HttpRequest).%New()
    set request.Timeout = 300 // Wait 300 seconds for response
    quit request
}

}

And use it instead of default adapter.

Comments

Hang  is not recommended to use in business component as the business component/adapter as the component or adapter will be blocked for that specified time.

However I would suggest something else in your code, to use Read($zutil(96,39)) instead of fixed value. $zutil(96,39) contains the number of characters  that a String can  hold.  If Intersystems  increase the number of characters for a string in future it will automatically take that maximum characters .

Instead of

$zutil(96,39) 

you can use

$$$MaxStringLength

for the same effect, but greater readability.