How to use service callout policy in faultrule?

Hi everyone,

I have 2 conditions where I want to use service callout policy.

First, when everything works fine and I use service callout policy to store some data into BaaS.

Second, when something goes wrong then fault rule was executed, and I want to use service callout policy inside that fault rule to store some data into BaaS.

The problem is in the second condition, the service callout policy wasn't executed at all when other policies inside that fault rule was executed. The service callout just failed.

Anyone can explain situation? Or do I miss something fundamental regarding service callout policy?

Regards,

Yoga

0 8 632
8 REPLIES 8

rovyas
New Member

I dont think you need to do something special to execute your service callout policy as part of fault blcok.I have used Service Callout in my fault block and it works in the same pattern as it works in normal flow.

May be you can share your fault steps and policy configurations, which will give us more idea

Sorry my bad, I should've share my fault steps and policy configuration in the first place.

This is my service callout policy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="true" enabled="true" name="SC-Store-Failed-Request-To-Baas">
    <DisplayName>SC - Store Failed Request To Baas</DisplayName>
    <Properties/>
    <Request clearPayload="true" variable="myRequest">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <Headers>
                <Header name="Accept">application/json</Header>
            </Headers>
            <Verb>POST</Verb>
            <Payload contentType="application/json">{"error":"{error.status.message}"}</Payload>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <HTTPTargetConnection>
        <Properties/>
        <URL>https://yogaprakoso90-test.apigee.com/failedtransactions</URL>
    </HTTPTargetConnection>
</ServiceCallout>
<br>

And this is my fault rule:

<FaultRules>
        <FaultRule name="Error Duplicate Transaction">
            <Step>
                <Name>EV-Extract-Error-Code-And-Cause</Name>
            </Step>
            <Step>
                <Name>SC-Store-Failed-Request-To-Baas</Name>
            </Step>
            <Condition>(error.reason.phrase Matches "DUPLICATE_TRANSACTION") </Condition>
        </FaultRule>
<FaultRules>

In the trace, the error flow goes into fault rule called "Error Duplicate Transaction" then execute extract variable policy, and then failed to execute service callout policy.

@Yoga Prakoso,

Can you check the trace if the Service Callout is getting failed or it is getting skipped?

The service callout is getting failed, not skipped.

@Yoga Prakoso

Can you please check if both the service callouts you are using have same name for the 'variable' attribute? If both have the same names, then the variable "servicecallout.requesturi" contains the appended values of pathSuffixes. This could be happening in your case also. Further, you can investigate in trace if all the variables were populated as expected. If not, can you attach the proxy bundle here?

Both service callout has different name in the attributes. I couldn't see "servicecallout.requesturi" because the policy was failed to be executed. Unfortunately I can't attach the proxy bundle here because of my company policy.
Maybe I just need to find another way to get my job done.

Seems like the sentence "you can investigate in trace if all the variables were populated as expected" is the keyword to solve my problem. My service callout is now working, the main problem is my extract variable policy didn't extract data as I expected which lead to failed service callout policy.

Thank you everyone