简体   繁体   中英

How to handle Apigee error case when query parameter checking in proxy

I have the following. The parameter "g" is allowed to be "on" or "off", otherwise go to an error policy. However, the exception case is never called. Instead, the "on" case is called if something that is not "on" or "off" is passed as "g". Why is that? Or, is there a better way of expressing this?

<PreFlow name="PreFlow">
    <Request>
        <Step>
            <Condition>message.queryparam.g := "on"</Condition>
            <Name>GOn</Name>
        </Step>
        <Step>
            <Condition>message.queryparam.g := "off"</Condition>
            <Name>GOff</Name>
        </Step>
        <Step>
            <Condition>!((message.queryparam.g := "off") || (message.queryparam.g := "on"))</Condition>
            <Name>GError</Name>
        </Step>
    </Request>

I just tested your conditions and they work properly. If the request has the following query parameter values:

g=on or g=ON , the GOn policy will execute.

g=off or g=OFF , the GOff policy will execute.

g={anythingelse} , the GError policy will execute.

The := operator is the equals case-insensitive operator. How are you determining that the conditions are not working? Using your example, I made each of the policies a RaiseFault with a different fault response payload. This allowed me to verify which policy was executed depending on the value of g .

I agree with Michael, the code as shown is correct.

Thinking about possible issues that could cause this code to not work as expected:

  1. Make sure that the names are correct inside your GOn, GOff, and GError policies. (If you are working offline, the name of the file has nothing to do with which policy gets called.) For example, the outer element of the GOn policy should look something like

    <AssignMessage name="GOn">

  2. If GOn uses AssignMessage to modify message, you might blow away the g query parameter during a step, and your later checks might fail. If you are modifying the message, store message.queryparam.g into a different variable before you do your checks.

  3. I would use the trace tool and a tool like Postman to see what is happening for each request. The trace should tell you the variables that have been checked and their values, and you might be able to see where you are going wrong.

如果您有多个条件检查,请尝试使用javascritp。在Java脚本中检查各种条件并设置flag。然后在基于flag的值的流中执行所需的策略。但是对于上述实例,如Michael所指出的,条件应该能按预期工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM