I want to set a flag and on the basis of flag, I want to process it further.
Condition1: If this flag is true, I should stop the processing here and return a success message to the client and exit from policy.
Condition2: If the flag is not true(Otherwise), I want to continue processing. Or, I want to do some furthur logic in policy.
When I try to use stop processing assertion or raise an error assertion, it is actually throwing an error in stead of success response. It also says unhandled exception in audit logs.
Please suggest how can I proceed.
Stop processing always return failure, raise error will terminate the policy execution. What you see is expected.
Use Return template response assertion instead of stop processing assertion to return successful message, by default it won't exit the policy, but if you have option "Send response immediately" checked, it will exit policy immediately after return response assertion.
I used return template assertion, but it doesn't exit policy, and it goes to next assertions.
When you implemented the return template response did you check the box that returns response immediately?
Here is the snippet from the CA Wiki:
Select this check box to send the template response message immediately, with or without a payload. The transmission of a payload depends on the status code (for example, a '204 (No Content) response status indicates to skip payload transmission).
Clear this check box to send the template response at the completion of the policy.
WARNING: Do not enable this option for most common use cases. Doing so closes the connection immediately and disables keep-alive, causing significant performance degradation. Additionally, the Gateway will apply no WS-Security decoration to the response message.
Return Template Response to Requestor Assertion - CA API Gateway - 9.3 - CA Technologies Documentation here is the full page.
I did the same. It exits from the loop. But, it starts following next assertion. That I don't want. I want to exit from policy itself.
The stop will just fail this branch, so in an At least one assertion it will go the the next branch.
If using stop, you should organise your assertions around it to get the execution flow needed (e.g. before the stop you can set a variable and check on this in next exeution branches).
Btw you will mostly see this assertion used in error situations.