JSON 威胁防范运行时错误问题排查

您正在查看的是 Apigee Edge 文档。
转到 Apigee X 文档
信息

ExecutionFailed

错误代码

steps.jsonthreatprotection.ExecutionFailed

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Execution failed. reason: JSONThreatProtection[policy_name]: error_description
          at line line_num",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

错误类型和可能的原因

JSONThreatProtection 政策可以抛出许多不同类型的 ExecutionFailed 错误。下表列出了不同类型的错误及其可能原因:

错误类型 原因
已超过对象条目名称长度 已超过对象条目名称允许的字符串长度上限。
已超过对象条目计数 已超过每个对象允许的最大条目数。
已超过数组元素计数 已超过数组中允许的元素数量上限。
已超过容器深度 已超过允许的嵌套深度上限。
已超过字符串值长度 已超过字符串值允许的最大长度。
无效 JSON 对象 输入 JSON 载荷无效。

已超过对象条目名称长度

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Execution failed. reason: JSONThreatProtection[policy_name]:
          Exceeded object entry name length at line line_num",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]:
          Execution failed. reason: JSONThreatProtection[JSON-Threat-Protection-1]:
          Exceeded object entry name length at line 2",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

原因

如果 <Source> 元素指定的输入消息载荷包含一个属性名称超过 <ObjectEntryNameLength> 元素中指定的长度上限的 JSON 对象,则会出现此错误。

例如,如果 <ObjectEntryNameLength> 元素在政策中被指定为 5,但输入消息载荷的 JSON 属性的名称超过 5 个字符,则会出现此错误。

诊断

  1. 查看错误消息,以标识 JSONThreatProtection 政策名称以及出现长条目名称的行号。例如,在以下错误消息中,JSONThreatProtection 政策名称为 JSON-Threat-Protection-1,载荷中的行号为 2。

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded object entry name
    length at line 2
    
  2. 检查您在第 1 步中标识的政策,并记下 <ObjectEntryNameLength> 元素中指定的值。

    例如,在以下 JSONThreatProtection 政策中,<ObjectEntryNameLength> 设置为 5

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
        <DisplayName>JSON Threat Protection-1</DisplayName>
        <Properties/>
        <ArrayElementCount>3</ArrayElementCount>
        <ContainerDepth>12</ContainerDepth>
        <ObjectEntryCount>5</ObjectEntryCount>
        <ObjectEntryNameLength>5</ObjectEntryNameLength>
        <Source>request</Source>
        <StringValueLength>50</StringValueLength>
    </JSONThreatProtection>
    
  3. 检查输入载荷的特定行号(在第 1 步中标识),并检查对象名称的长度是否大于 <ObjectEntryNameLength> 元素中指定的值(在第 2 步中标识)。如果对象名称的长度超过该数字,则会导致错误。

    下面是一个输入载荷示例:

    {
       "number" : 500,
       "string" : "text"
    }
    

    上面显示的 JSON 载荷有一个名为 number 的属性(位于第 2 行),它包含 6 个字符(名称长度为 6)。由于对象名称长度超过 5(为 <ObjectEntryNameLength> 元素指定的值),因此会出现以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded object entry name
    length at line 2
    

分辨率

如果 JSONThreatProtection 政策旨在防止对象条目名称超过定义的值的载荷,则会出现错误消息。在这种情况下,您不需要执行任何其他操作。

但是,如果您确定可以在载荷中指定较长的对象条目名称而不会产生任何后果,请根据要求将 <ObjectEntryNameLength> 修改为合适的值。

例如,如果您认为可以允许长度不超过 10 个字符的对象名称,请按如下方式修改 JSONThreatProtection 政策:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection-1</DisplayName>
    <Properties/>
    <ArrayElementCount>3</ArrayElementCount>
    <ContainerDepth>12</ContainerDepth>
    <ObjectEntryCount>5</ObjectEntryCount>
    <ObjectEntryNameLength>10</ObjectEntryNameLength>
    <Source>request</Source>
    <StringValueLength>50</StringValueLength>
</JSONThreatProtection>

已超过对象条目计数

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Execution failed. reason: JSONThreatProtection[policy_name]:
          Exceeded object entry count at line line_num",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]:
          Execution failed. reason: JSONThreatProtection[JSON-Threat-Protection-1]:
          Exceeded object entry count at line 7",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

原因

如果 <Source> 元素指定的输入消息载荷包含的 JSON 对象的条目数量(属性)大于政策的 <ObjectEntryCount> 元素中指定的值,则会发生此错误。

例如,如果 <ObjectEntryCount> 元素为 5,但输入 JSON 载荷包含超过 5 个条目,则会抛出此错误。

诊断

  1. 查看错误消息,以标识 JSONThreatProtection 政策名称以及已超过条目计数的行号。例如,在以下错误消息中,政策名称为 JSON-Threat-Protection-1,载荷中的行号为 7

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded object entry count
    at line 7
    
  2. 记下政策的 <ObjectEntryCount> 元素(在第 1 步中标识)中指定的值。

    在以下政策示例中,<ObjectEntryCount> 设置为 5

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
        <DisplayName>JSON Threat Protection-1</DisplayName>
        <Properties/>
        <ArrayElementCount>3</ArrayElementCount>
        <ContainerDepth>12</ContainerDepth>
        <ObjectEntryCount>5</ObjectEntryCount>
        <ObjectEntryNameLength>6</ObjectEntryNameLength>
        <Source>request</Source>
        <StringValueLength>50</StringValueLength>
    </JSONThreatProtection>
    
  3. 检查输入载荷的特定行号(在第 1 中标识),并检查载荷中的实体数是否大于为 <ObjectEntryCount> 元素指定的值(在第 2 步中标识)。如果对象数超过对象条目计数,则会导致错误。

    下面是一个输入载荷示例:

    {
    "name" : "John",
    "id" : 234687,
    "age" : 31,
    "city" : "New York",
    "country" : "USA",
    "company" : "Google"
    }
    

    在上面显示的 JSON 载荷中,第 6 个条目出现在第 7 行(公司)。由于输入 JSON 载荷中对象条目的计数大于 5(为 <ObjectEntryCount> 元素指定的值),因此会出现以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded object entry count at
    line 7
    

解决方法

如果 JSONThreatProtection 政策旨在防止对象条目数超过特定阈值的载荷,则会出现错误消息。在这种情况下,您不需要执行任何其他操作。

但是,如果您确定可以在载荷中包含更多的对象条目而不会产生任何后果,请根据要求将 <ObjectEntryCount> 修改为合适的值。

例如,如果您认为最多可允许 10 个对象条目,则按如下方式修改 JSONThreatProtection 政策:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection-1</DisplayName>
    <Properties/>
    <ArrayElementCount>3</ArrayElementCount>
    <ContainerDepth>12</ContainerDepth>
    <ObjectEntryCount>10</ObjectEntryCount>
    <ObjectEntryNameLength>6</ObjectEntryNameLength>
    <Source>request</Source>
    <StringValueLength>50</StringValueLength>
</JSONThreatProtection>

已超过数组元素计数

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Execution failed. reason: JSONThreatProtection[policy_name]:
          Exceeded array element count at line line-num",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]:
          Execution failed. reason: JSONThreatProtection[JSON-Threat-Protection-1]:
          Exceeded array element count at line 3",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

原因

如果 <Source> 元素指定的输入消息载荷包含的 JSON 数字的元素数超过在政策的 <ArrayElementCount> 元素中指定的数量,则会出现此错误。

例如,如果 <ArrayElementCount> 元素被指定为 3,但输入载荷的 JSON 数组包含 3 个以上元素,则会抛出此错误。

诊断

  1. 查看错误消息,以标识政策名称和已超过数组长度的行号。例如,在以下错误消息中,政策名称为 JSON-Threat-Protection-1,载荷中的行号为 3

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded array element count at line 3
    
  2. 记下为政策的 <ArrayElementCount> 元素(在第 1 步中标识)指定的值。

    在以下 JSONThreatProtection 政策示例中,<ArrayElementCount> 设置为 3

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
        <DisplayName>JSON Threat Protection-1</DisplayName>
        <Properties/>
        <ArrayElementCount>3</ArrayElementCount>
        <ContainerDepth>12</ContainerDepth>
        <ObjectEntryCount>5</ObjectEntryCount>
        <ObjectEntryNameLength>6</ObjectEntryNameLength>
        <Source>request</Source>
        <StringValueLength>50</StringValueLength>
    </JSONThreatProtection>
    
  3. 检查输入载荷的特定行号(在第 1 步中标识),并检查指定数组的计数是否大于 <ArrayElementCount> 元素中指定的数字(在第 2 步中标识)。如果数组元素的数量超过计数,则会导致错误。

    下面是一个输入载荷示例:

    {
     "name":"Ford",
     "models":[
        "Mustang",
        "Endeavour",
        "Fiesta",
        "EcoSport",
        "Focus"
     ]
    }
    

    上面显示的 JSON 载荷在行 3 名为 models 的数组中具有 5 个元素。由于数组元素的数量大于 3(为 <ArrayElementCount> 元素指定的值),您会收到以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded array element count
    at line 3
    

分辨率

如果 JSONThreatProtection 政策旨在防止具有特定数组计数阈值的载荷,则会出现错误消息。在这种情况下,您无需执行任何其他操作。

但是,如果确定允许数组使用更多数量的元素,请根据要求将 <ArrayElementCount> 修改为合适的值。

例如,如果您认为最多可允许 5 个数组元素,请按以下方式修改政策:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection-1</DisplayName>
    <Properties/>
    <ArrayElementCount>5</ArrayElementCount>
    <ContainerDepth>12</ContainerDepth>
    <ObjectEntryCount>5</ObjectEntryCount>
    <ObjectEntryNameLength>6</ObjectEntryNameLength>
    <Source>request</Source>
    <StringValueLength>50</StringValueLength>
</JSONThreatProtection>

已超过容器深度

错误响应正文

运行时流量返回 500 响应代码,并显示以下错误:

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Execution failed. reason: JSONThreatProtection[policy_name]:
          Exceeded container depth at line line-num",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]:
          Execution failed. reason: JSONThreatProtection[JSON-Threat-Protection-1]:
          Exceeded container depth at line 5",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

原因

如果 <Source> 元素指定的输入消息载荷包含 JSON 元素的容器深度超过在政策 <ContainerDepth> 中指定的容器深度上限的 JSON 对象,则会出现此错误。容器深度是 JSON 元素允许的最大嵌套深度。例如,如果一个数组包含的一个对象还包含一个对象,则将导致包含深度为 3。

例如,如果 <ContainerDepth> 元素为 3,但输入载荷具有超出此限制的容器深度,则会抛出此错误。

诊断

  1. 查看错误消息,以标识 JSONThreatProtection 政策名称以及已超过容器深度的行号。例如,在以下错误消息中,政策名称为 JSON-Threat-Protection-1,载荷中的行号为 5

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded container depth at
    line 5
    
  2. 记下为 <ContainerDepth> 元素指定的值(在第 1 步中标识)。

    在以下 JSONThreatProtection 政策示例中,<ContainerDepth> 设置为 5

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
        <DisplayName>JSON Threat Protection-1</DisplayName>
        <Properties/>
        <ArrayElementCount>3</ArrayElementCount>
        <ContainerDepth>5</ContainerDepth>
        <ObjectEntryCount>5</ObjectEntryCount>
        <ObjectEntryNameLength>20</ObjectEntryNameLength>
        <Source>request</Source>
        <StringValueLength>50</StringValueLength>
    </JSONThreatProtection>
    
  3. 检查输入载荷的特定行号(在第 1 步中标识),并检查载荷中的容器深度是否高于在 <ContainerDepth> 元素中指定的值(在第 2 步中标识)。如果容器深度超过计数,则会导致错误。

    下面是一个输入载荷示例:

    {
     "ContainerDepth2":[ {
           "ContainerDepth4":[
              {
                 "ContainerDepth6":[
                    "1",
                    "2"
                 ]
              }
           ]
        }
     ]
    }
    

    上面显示的 JSON 载荷的容器深度在第 5 行为 6。由于深度大于 5,即为 JSONThreatProtection 政策的 <ContainerDepth> 元素指定的值,因此您会收到以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded container depth at
    line 5
    

分辨率

如果 JSONThreatProtection 政策旨在防止容器深度超过指定值的载荷,则会出现错误消息。在这种情况下,您无需执行任何其他操作。

但是,如果您确定更高的容器深度可接受,请根据要求将 <ContainerDepth> 修改为合适的值。

例如,如果您认为可以允许高达 10 的容器深度,则可以按以下方式修改政策:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection-1</DisplayName>
    <Properties/>
    <ArrayElementCount>3</ArrayElementCount>
    <ContainerDepth>10</ContainerDepth>
    <ObjectEntryCount>5</ObjectEntryCount>
    <ObjectEntryNameLength>20</ObjectEntryNameLength>
    <Source>request</Source>
    <StringValueLength>50</StringValueLength>
</JSONThreatProtection>

已超过字符串值长度

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Execution failed. reason: JSONThreatProtection[policy_name]:
          Exceeded string value length at line line-num",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]:
          Execution failed. reason: JSONThreatProtection[JSON-Threat-Protection-1]:
          Exceeded string value length at line 3",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

原因

如果 <Source> 元素指定的输入消息载荷包含值字符数超过 <StringValueLength> 元素的允许值的 JSON 元素,就会出现此错误。

例如,如果政策中的 <StringValueLength> 元素设置为 50,但输入载荷的一个或多个元素的值超过 50 个字符,则会抛出此错误。

诊断

  1. 查看错误消息,以标识政策名称和已超过字符串长度的行号。在以下示例中,政策名称为载荷 3 中的 JSON-Threat-Protection-1 and 行。

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded string value length at line 3
    
  2. 记下为 <StringValueLength> 元素指定的值(在第 1 步中标识)。

    在以下 JSONThreatProtection 政策示例中,<StringValueLength> 设置为 50

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
        <DisplayName>JSON Threat Protection-1</DisplayName>
        <Properties/>
        <ArrayElementCount>3</ArrayElementCount>
        <ContainerDepth>5</ContainerDepth>
        <ObjectEntryCount>5</ObjectEntryCount>
        <ObjectEntryNameLength>20</ObjectEntryNameLength>
        <Source>request</Source>
        <StringValueLength>50</StringValueLength>
    </JSONThreatProtection>
    
  3. 检查输入载荷的特定行号(在第 1 中标识),并检查值的长度是否大于为 <StringValueLength> 元素指定的字符数(在第 2 步中标识)。如果值的长度超过限制,则会导致错误。

    下面是一个输入载荷示例:

    {
      "Country": "New Zealand",
      "Place Name": "Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu"
    }
    

    上面显示的 JSON 载荷有一个名为 Place Name 的对象,其值 Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu 在第 3 行包含 85 个字符。由于该值的长度大于 50,即在 <StringValueLength> 元素中指定的值,因此会收到以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    JSONThreatProtection[JSON-Threat-Protection-1]: Exceeded string value length
    at line 3
    

分辨率

如果 JSONThreatProtection 政策旨在防止值超过特定字符串长度的载荷,则会出现错误消息。在这种情况下,您无需执行任何其他操作。

但是,如果您确定可以在载荷中指定较长的值长度,请根据您的要求将 <StringValueLength> 修改为合适的值。

例如,如果您认为允许值的长度最多 90,请按以下方式修改政策:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection-1</DisplayName>
    <Properties/>
    <ArrayElementCount>3</ArrayElementCount>
    <ContainerDepth>5</ContainerDepth>
    <ObjectEntryCount>5</ObjectEntryCount>
    <ObjectEntryNameLength>20</ObjectEntryNameLength>
    <Source>request</Source>
    <StringValueLength>90</StringValueLength>
</JSONThreatProtection>

非有效 JSON 对象

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Execution failed. reason: string: at line line-num",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]:
          Execution failed. reason: Expecting : at line 3",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.ExecutionFailed"
        }
    }
}

原因

如果 JSONThreatProtection 政策中的 <Source> 元素指定的输入消息载荷不是有效的 JSON 对象,则会出现此错误。

诊断

  1. 查看错误消息,以标识政策名称和发生错误的行号。在以下示例中,政策名称为载荷 2 中的 JSON-Threat-Protection-1 and 行。

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason: Expecting : at line 3
    
  2. 检查输入载荷的特定行号(在第 1 步中标识),并检查载荷中传递的 JSON 对象确实是有效的 JSON 对象。

    下面是一个输入载荷示例:

    {
      "Longitude": 6.11499,
      "Latitude"  50.76891
    }
    

    在上面显示的 JSON 载荷中,第 3 行没有 ":"(冒号)。由于它是无效的 JSON 对象,因此您会收到以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]: Execution failed. reason:
    Expecting : at line 3
    

分辨率

确保将有效的输入 JSON 载荷传递到包含 JSONThreatProtection 政策的任何 API 代理。

对于上述事例,请按如下所示修改 JSON 载荷:

{
    "Longitude": 6.11499,
  "Latitude" : 50.76891
}

SourceUnavailable

错误代码

steps.jsonthreatprotection.SourceUnavailable

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]::
          Source[var_name] is not available"
        "detail": {
            "errorcode": "steps.jsonthreatprotection.SourceUnavailable"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]::
          Source requests is not available",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.SourceUnavailable"
        }
    }
}

原因

如果 JSONThreatProtection 政策的 <Source> 元素中指定的消息变量属于以下情况之一,就会出现此错误:

  • 超出范围(在执行政策的特定流中不可用)
  • 不是 requestresponsemessage 有效值之一

例如,如果将政策中的 <Source> 元素设置为在执行政策的流中不存在的变量,就会发生此错误。

诊断

  1. 从错误消息中表示政策名称以及来源变量的名称。例如,在以下错误消息中,政策名称为 JSON-Threat-Protection-1,来源变量为 requests

    JSONThreatProtection[JSON-Threat-Protection-1]:: Source requests is not available
    
  2. 检查为在第 1 步中标识的 <Source> 元素指定的值。

    在以下 JSONThreatProtection 政策示例中,<Source> 元素设置为 requests

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
        <DisplayName>JSON Threat Protection-1</DisplayName>
        <Properties/>
        <ArrayElementCount>3</ArrayElementCount>
        <ContainerDepth>5</ContainerDepth>
        <ObjectEntryCount>5</ObjectEntryCount>
        <ObjectEntryNameLength>20</ObjectEntryNameLength>
        <Source>requests</Source>
        <StringValueLength>50</StringValueLength>
    </JSONThreatProtection>
    

    <Source> 元素的有效值包括 requestresponsemessage。由于请求不是有效的值,并且在执行的政策中不存在,因此您会收到以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]:: Source requests is not available
    

分辨率

确保在失败的 JSONThreatProtection 政策的 <Source> 元素中设置的变量设置为 requestresponsemessage,并且在政策执行的流中存在。

如需更正上面所示的 JSONThreatProtection 政策示例,您可以修改 <Source> 元素以使用 request 变量,因为它存在于请求流中:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection-1</DisplayName>
    <Properties/>
    <ArrayElementCount>3</ArrayElementCount>
    <ContainerDepth>5</ContainerDepth>
    <ObjectEntryCount>5</ObjectEntryCount>
    <ObjectEntryNameLength>20</ObjectEntryNameLength>
    <Source>request</Source>
    <StringValueLength>50</StringValueLength>
</JSONThreatProtection>

NonMessageVariable

错误代码

steps.jsonthreatprotection.NonMessageVariable

错误响应正文

{
    "fault": {
        "faultstring": "JSONThreatProtection[policy_name]:
          Variable var_name does not resolve to a Message"
        "detail": {
            "errorcode": "steps.jsonthreatprotection.NonMessageVariable"
        }
    }
}

错误响应正文示例

{
    "fault": {
        "faultstring": "JSONThreatProtection[JSON-Threat-Protection-1]:
          Variable message.content does not resolve to a Message",
        "detail": {
            "errorcode": "steps.jsonthreatprotection.NonMessageVariable"
        }
    }
}

原因

如果将 JSONThreatProtection 政策的 <Source> 元素设置为非消息类型的变量,则会出现此错误。

消息类型变量表示整个 HTTP 请求和响应。内置的 Apigee Edge 流变量请求、响应和消息均为消息类型。如需详细了解消息变量,请参阅变量参考文档

诊断

  1. 从错误消息中标识 JSONThreatProtection 政策名称以及来源变量的名称。例如,在以下错误消息中,政策名称为 JSON-Threat-Protection-1,来源变量为 message.content

    JSONThreatProtection[JSON-Threat-Protection-1]: Variable message.content does not resolve to a Message
    
  2. 检查 JSONThreatProtection 政策的 <Source> 元素(在第 1 步中标识)。

    在以下 JSONThreatProtection 政策示例中,<Source> 设置为 message.content,而不是 message

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
        <DisplayName>JSON Threat Protection-1</DisplayName>
        <Properties/>
        <ArrayElementCount>3</ArrayElementCount>
        <ContainerDepth>5</ContainerDepth>
        <ObjectEntryCount>5</ObjectEntryCount>
        <ObjectEntryNameLength>20</ObjectEntryNameLength>
        <Source>message.content</Source>
        <StringValueLength>50</StringValueLength>
    </JSONThreatProtection>
    

    由于 message.content 不是消息类型,因此会收到以下错误:

    JSONThreatProtection[JSON-Threat-Protection-1]: Variable message.content does
    not resolve to a Message
    

分辨率

确保失败的 JSONThreatProtection 政策的 <Source> 元素设置为在政策执行的流中存在的消息类型流变量。

如需更正该政策,您可以修改 <Source> 元素来指定类型为消息的变量。例如,在失败的 JSONThreatProtection 中,您可以将 <Source> 元素指定为 message

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<JSONThreatProtection async="false" continueOnError="false" enabled="true" name="JSON-Threat-Protection-1">
    <DisplayName>JSON Threat Protection-1</DisplayName>
    <Properties/>
    <ArrayElementCount>3</ArrayElementCount>
    <ContainerDepth>5</ContainerDepth>
    <ObjectEntryCount>5</ObjectEntryCount>
    <ObjectEntryNameLength>20</ObjectEntryNameLength>
    <Source>message</Source>
    <StringValueLength>50</StringValueLength>
</JSONThreatProtection>