Add a condition to check that message body exists before execution of this policy

Not applicable

How to verify the below condition. Getting this error while using CodeLint for my proxy

Message:

Add a condition to check that message body exists before execution of this policy

Action:

An appropriate check for a message body was not found on the enclosing Step or Flow

Extract variable policy:-

<ExtractVariables name="ExtractESResponse">
  <DisplayName>ExtractESResponse</DisplayName>
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
  <Source clearPayload="false">esResponse.content</Source>
  <JSONPayload>
    <Variable name="entitlementServerResult">
      <JSONPath>$.Response.Decision</JSONPath>
    </Variable>
  </JSONPayload>
</ExtractVariables>

Flow:

<Step>
  <Name>ExtractESResponse</Name>
  <Condition>(esResponse.content !=null and entitlementServerResult == "Permit")</Condition>
</Step>
0 2 3,439
2 REPLIES 2

You could check the Content-Length header. Assuming esReponse holds the response message, your condition could be rewritten as

<Condition>(esResponse.header.Content-Length > 0)</Condition>

You shouldn't check for the value of the variable entitlementServerResult before actually assigning it , otherwise the condition will always be false

Based on where extract variable policy is being used, add the appropriate value check. Apigeelint checks for this code qulity. No need to use all of them. Based on your use case , choose one.

  • response.content
  • response.form
  • request.content
  • request.form
  • message.content
  • message.form
  • message.verb
  • request.verb
  • request.header.Content-Length
  • response.header.Content-Length

Given sample where policy is used to extract vars from incoming request

<Step>
       <Condition>(request.content != null)</Condition>
       <Name>ev-extract-policy</Name>
</Step>

Answer reference : https://github.com/CreditMutuelArkea/sonar-apigee-plugin/issues/4