Hi All,
I have a QAction to handle the http response through a StatusCode Parameter. I have to check the trigger with the interval of 60 seconds during Success or failure.
The issue is during failure like Timeout error the StatusCode is null and the response content is also null So it is not calling the QAction(1002) and LastFailedPollingTime parameter is set to a default value of -1 and the logic of 60 seconds interval is failing so the Polling is happening every second. What would be the right approach to handle the exception in this case.
Any suggestion would be helpful.
Thanks in advance.
<QAction id="1002" name="Process Directory Status HTTP Response" encoding="csharp" triggers="1010">
<Condition>
<![CDATA[id:1010 != -1]]>
</Condition>
</QAction>
<Param id="1010" trending="false">
<Name>GetDirectoryStatus_Response_StatusCode</Name>
<Description>Get Directory Status- Response - Status Code</Description>
<Type>read</Type>
<Information>
</Information>
<Interprete>
<RawType>other</RawType>
<Type>string</Type>
<LengthType>next param</LengthType>
</Interprete>
<Alarm>
<Monitored>true</Monitored>
<Normal>200 OK</Normal>
</Alarm>
<Display>
<RTDisplay>true</RTDisplay>
<Positions>
<Position>
<Page>Configuration</Page>
<Column>1</Column>
<Row>2</Row>
</Position>
</Positions>
</Display>
<Measurement>
<Type>string</Type>
</Measurement>
</Param>
<Param id="1011" trending="false">
<Name>GetDirectoryStatus_Response_Content</Name>
<Description>Get Directory Status- Response - Content</Description>
<Type>read</Type>
<Information>
</Information>
<Interprete>
<RawType>other</RawType>
<Type>string</Type>
<LengthType>next param</LengthType>
<DefaultValue>-1</DefaultValue>
<Exceptions>
<Exception id="1" value="-1">
<Display state="disabled">N/A</Display>
<Value>-1</Value>
</Exception>
</Exceptions>
</Interprete>
<Display>
<RTDisplay>false</RTDisplay>
</Display>
<Measurement>
<Type>string</Type>
</Measurement>
</Param>
<HTTP>
<Session id="1001" name="Get Directory Status">
<Connection id="1001" name="Get Directory Status" timeout="10000">
<Request verb="GET" url="/directory/getDirectoryState">
</Request>
<Response statusCode="1010">
<Content pid="1011" />
</Response>
</Connection>
</Session>
</HTTP>
QAction1002
public static class QAction
{
/// <summary>
/// The QAction entry point.
/// </summary>
/// <param name="protocol">Link with SLProtocol process.</param>
public static void Run(SLProtocolExt protocol)
{
var triggerParameter = protocol.GetTriggerParameter();
try
{
protocol.Log("triggerParameter" + triggerParameter);
var sStatusCode = protocol.Getdirectorystatus_response_statuscode_1010.ToStr();
var sResponseContent = protocol.Getdirectorystatus_response_content_1011.ToStr();
protocol.Log("sResponseContent" + sResponseContent);
protocol.Log("Status Code" + sStatusCode);
// FIXED: Always update failed polling time on error conditions
if (sResponseContent.IsNullOrEmpty() || sResponseContent == "-1")
{
protocol.Log("QA" + protocol.QActionID + "|" + triggerParameter + "|Run|Response was Null or Empty!", LogType.Error, LogLevel.NoLogging);
protocol.Getdirectorystatus_response_lastfailedpollingtime = DateTime.Now; // ADDED
return;
}
if (sStatusCode.Contains("200 OK"))
{
var oGetDirectoryStatusResponse = JsonConvert.DeserializeObject<GetDirectoryStatusResponse>(sResponseContent);
if (oGetDirectoryStatusResponse != null && oGetDirectoryStatusResponse.Services != null)
{
oGetDirectoryStatusResponse.SaveBusbyServicesData(protocol);
}
protocol.Getdirectorystatus_response_lastsuccessfulpollingtime = DateTime.Now;
}
else
{
protocol.Getdirectorystatus_response_lastfailedpollingtime = DateTime.Now;
protocol.Log($"QA{protocol.QActionID}|{triggerParameter}|HTTP Error: {sStatusCode}", LogType.Error, LogLevel.NoLogging);
}
protocol.Getdirectorystatus_response_content_1011 = -1;
protocol.Getdirectorystatus_response_content_display_1014 = sResponseContent;
}
catch (Exception ex)
{
// FIXED: Update failed polling time on exception
protocol.Getdirectorystatus_response_lastfailedpollingtime = DateTime.Now; // ADDED
protocol.Log("QA" + protocol.QActionID + "|" + triggerParameter + "|Run|Exception thrown:" + Environment.NewLine + ex, LogType.Error, LogLevel.NoLogging);
}
}
}
Hi Divya,
You can solve this by using an “after group” trigger that runs whenever the group containing the HTTP request finishes executing. This trigger fires regardless of whether the HTTP request succeeds or fails.
Inside your QAction, you can then evaluate the response content and status code parameters to determine the outcome and handle it accordingly.