简体   繁体   English

代理中查询参数检查时如何处理Apigee错误情况

[英]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. 参数“ g”允许为“ on”或“ off”,否则转到错误策略。 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". 相反,如果将非“ on”或“ off”的值作为“ g”传递,则调用“ on”情况。 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=ong=ON ,将执行GOn策略。

g=off or g=OFF , the GOff policy will execute. g=offg=OFF ,将执行GOff策略。

g={anythingelse} , the GError policy will execute. g={anythingelse} ,将执行GError策略。

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. 使用您的示例,我将每个策略都设置为具有不同故障响应有效负载的RaiseFault。 This allowed me to verify which policy was executed depending on the value of g . 这使我可以验证根据g的值执行了哪个策略。

I agree with Michael, the code as shown is correct. 我同意Michael,显示的代码是正确的。

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. 确保您的GOn,GOff和GError策略中的名称正确。 (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 (如果正在脱机工作,则文件名与调用策略无关。)例如,GOn策略的外部元素应类似于

    <AssignMessage name="GOn"> <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. 如果GOn使用AssignMessage修改消息,则可能会在一个步骤中破坏g查询参数,并且以后的检查可能会失败。 If you are modifying the message, store message.queryparam.g into a different variable before you do your checks. 如果要修改消息,请在执行检查之前将message.queryparam.g存储到其他变量中。

  3. I would use the trace tool and a tool like Postman to see what is happening for each request. 我将使用跟踪工具Postman之类的工具来查看每个请求的情况。 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所指出的,条件应该能按预期工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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