Web hook Responses Timing out  Topic is solved

Discussions relating to the REST API of Jiwa 7.

Web hook Responses Timing out

Postby SBarnes » Mon Mar 07, 2022 4:42 pm

We have a customer who is getting the following response from a web hook post out from the api, I am assuming the other side is being found otherwise I would expect to see 404's and we are getting a status of 0 in the response table is there a way to increase the time we give the other side to respond?


Code: Select all
“A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Web hook Responses Timing out

Postby Mike.Sheen » Tue Mar 08, 2022 2:10 pm

The only way is to modify the REST API code which sends the webhook - this is in the Webhook method of the BusinessLogicPlugin part of the REST API plugin.

in this block of code:

Code: Select all
static async public System.Threading.Tasks.Task Webhook(JiwaFinancials.Jiwa.JiwaApplication.Manager Manager, string body, string eventName, string PluginName)
{      
   string url = Manager.Database.ReadSysData(PluginName, "WebhooksHostURL", "").ToString();
   string clientKey = Manager.Database.ReadSysData(PluginName, "WebhooksClientKey", "").ToString();
         
   if (url.Length > 0)
   {
      try
      {            
         ServiceStack.JsonServiceClient client = new ServiceStack.JsonServiceClient(url);                        
         client.Headers.Add("ClientKey", clientKey);            
         await client.PostAsync<IReturnVoid>(new JiwaFinancials.Jiwa.JiwaServiceModel.WebhooksEventsPOSTRequest() { EventName = eventName, Body = body });            
      }
...


Add a line to set the timeout property of the client before the call to PostAsync:

Code: Select all
         client.Timeout = new TimeSpan(0, 0, 1, 30);
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756

Re: Web hook Responses Timing out

Postby SBarnes » Tue Mar 08, 2022 2:15 pm

Hi Mike,

Thanks for the reply but where I am trying to increase the timeout is in CallWebhook, namely on


Code: Select all
            try
            {
                // This is the actual POST to the webhook
                subscription.URL.PostStringToUrl(message.Body,
                                                 requestFilter: webRequest =>
                                                 {
                                                     foreach (SY_WebhookSubscriptionRequestHeader subscriptionRequestHeader in subscriptionRequestHeaders)
                                                     {
                                                         webRequest.Headers[subscriptionRequestHeader.Name] = subscriptionRequestHeader.Value;
                                                     }
                                                 });
                messageResponse.HTTPCode = 200;
                newStatus = 1;
            }
            catch (System.Exception ex)
            {
                while (ex.InnerException != null) ex = ex.InnerException;

                newStatus = 2;
                messageResponse.Message = ex.Message;
                int statusCode = 0;

                if (ex.GetStatus() != null)
                    statusCode = (int)ex.GetStatus();

                messageResponse.HTTPCode = statusCode;

                if ((statusCode >= 200 && statusCode < 300) || ex.IsAny300() || statusCode == 410)
                    newStatus = 3;  // Permanent fail - we do not attempt to retry these                     
            }
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1619
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 175

Re: Web hook Responses Timing out  Topic is solved

Postby Mike.Sheen » Tue Mar 08, 2022 2:18 pm

SBarnes wrote:Hi Mike,

Thanks for the reply but where I am trying to increase the timeout is in CallWebhook


Oh - right you are.

In that case, set the Timeout property of the webRequest to be a value in ms - eg:

Code: Select all
try
{
   // This is the actual POST to the webhook
   subscription.URL.PostStringToUrl(message.Body,
                            requestFilter: webRequest =>
                            {
                               webRequest.Timeout = 3000; // 3000 ms
                               foreach (SY_WebhookSubscriptionRequestHeader subscriptionRequestHeader in subscriptionRequestHeaders)
                               {
                                  webRequest.Headers[subscriptionRequestHeader.Name] = subscriptionRequestHeader.Value;
                               }
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to REST API

Who is online

Users browsing this forum: No registered users and 3 guests

cron