Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Retry Target endpoint when get response 401 unauthorized

When we perform a retry using the ServiceCallout policy and receive a response with status code 400 or 401 from the Target endpoint, the retry is triggered. However, during the second attempt, it fails because we are not able to read the header value below adding the code please have a look

ServiceCallout Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ServiceCallout async="false" continueOnError="true" enabled="true" name="SC-RetryProxyLoopback">
<DisplayName>SC-RetryProxyLoopback</DisplayName>
<Properties/>
<Request clearPayload="false">
<Set>
<Verb>{request.verb}</Verb>
<Path>{proxy.pathsuffix}</Path>
<Headers>
<!-- Use dynamic header based on response code -->
<Header name="X-IntelligentComplianceKey">{retry.header.X-IntelligentComplianceKey}</Header>
<Header name="Authorization">{retry.header.Authorization}</Header>
<Header name="Content-Type">{request.header.Content-Type}</Header>
<Header name="X-Retry-Attempt">1</Header>
</Headers>
<Payload contentType="{request.header.Content-Type}">{request.content}</Payload>
<QueryParams>{request.queryparams}</QueryParams>
</Set>
</Request>
<Response>calloutResponse</Response>
<HTTPTargetConnection>
<URL>https://example.com</URL>
</HTTPTargetConnection>
</ServiceCallout>


and Target EndPoint

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="checkCompliance">
<Description/>
<FaultRules>
<FaultRules>
<FaultRule name="HeaderValidationError">
<Condition>(headers.valid = false) or (headers.error != null) or (auth.invalid.format = true)</Condition>
<Step>
<Name>AM-HandleHeaderError</Name>
</Step>
</FaultRule>
</FaultRules>
<FaultRule name="RetryError">
<FaultRule name="RetryError">
<Condition>(retry.error != null) or (servicecallout.SC-RetryProxyLoopback.failed = true)</Condition>
<Step>
<Name>AM-HandleRetryError</Name>
</Step>
</FaultRule>
</FaultRule>
</FaultRules>
<PreFlow name="PreFlow">
<Request>
<Step>
<Name>Compliance-Target-Path</Name>
</Step>
</Request>
<Response/>
</PreFlow>
<PostFlow name="PostFlow">
<Request/>
<Response>
<!-- Validate headers first -->
<Step>
<Condition>response.status.code = "401"</Condition>
<Name>JS-HeaderValidator</Name>
</Step>
<!-- Handle retry if headers are valid -->
<Step>
<Condition>headers.valid = true and response.status.code = "401"</Condition>
<Name>JS-RetryHandle</Name>
</Step>
<!-- Get new token if retry needed -->
<Step>
<Condition>shouldRetry = true</Condition>
<Name>KVM-PRG_detail</Name>
</Step>
<!-- Make retry request -->
<!-- <Step>
<Condition>shouldRetry = true</Condition>
<Name>SC-RetryProxyLoopback</Name>
</Step>-->
<!-- Handle response -->
<Step>
<Name>AM-HandleRetryResponse</Name>
<Condition>calloutResponse != null</Condition>
</Step>
</Response>
</PostFlow>
<HTTPTargetConnection>
<URL>https://example.com</URL>
<Properties>
<Property name="response.streaming.enabled">true</Property>
<Property name="request.streaming.enabled">true</Property>
<Property name="supports.http10">true</Property>
</Properties>
</HTTPTargetConnection>
</TargetEndpoint>

 

0 1 145
1 REPLY 1