Regex policy JSONPayload behaviour

I have come across a very different behavior of regex policy. I am trying to apply regex pattern on every json field of my schema using <JSONPayload>.

Now whenever any field is missing in my payload, regex policy stops working after that point.

Is there any solution for it?

0 6 157
6 REPLIES 6

Hi Apigee Experts

Same issue I am facing with my policy.

I have mentioned all fields expression with Pattern in <JSONPayload> but regex policy is stopping to trace(work) if I am changing any sequence in json or flow .

Could you please let me guide if any solution available for this ?

Thanks in advance .

Hi @pulkit Agrawal and @Ruchi Purohit


Following code snippet is from RegularExpressionProtection policy. In order to check every field on Json paylaod if there is a child element under JsonPayload called JsonPath. Which contains child element called Expression . if you put the value called $. that will check every filed on your JsonPayload for pattern you have defined.

    <JSONPayload>
        <JSONPath>
            <Expression>$.</Expression>
            <Pattern>yourregexpattern</Pattern>
        </JSONPath>
    </JSONPayload>

Have your RegularExpressionProtection policy set up in similar way to check each field?

Also things to consider is request must contain valid Json Payload and request header Content-Type set up to application/json.

Regards

Jayesh

Hi @Jayesh Upadhyay

Thanks for response .

I have concern for all the fields including mandatory and optional parameter in Json if having different regular expression then how to deal with them.

In my case I have started to put <JSONPath> in <JSONPayload> tag for each field expression and their pattern ,but it is performing uncertain .

So do you have idea to deal with my problem

For the same query I also have strated my seperate post .

Thanks and Regards

HI @Ruchi Purohit

Please check latest reply from @pulkit Agrawal on this same thread as this is existing limitation on Apigee side but how he manged to go about working around this limitations.

Hi All,

We finally resolved this issue with below approach :

(APIGEE accepted that this is an issue with regex policy hence this is a valid concern which will be fixed in near future)

1. Add a policy where all the mandatory fields are present.

2. Created regex policy for each of the optional field.

Total time taken by a large structured regex and combined time of many single field regex is exact the same so performance wise it doesn't make any difference though it is a tedious task.

Regards,

Pulkit.

Thank you @pulkit Agrawal for your update and it's good to understand how you managed to work around existing limitation.