XML 到 JSON 政策部署错误问题排查

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

EitherOptionOrFormat

错误消息

通过 Edge 界面或 Edge Management API 部署 API 代理失败,并显示以下错误消息:

Error Saving Revision [revision_number]
XMLToJSON[{0}]: Either Options or Format must be specified.

错误示例

Error Saving Revision 1
XMLToJSON[{0}]: Either Options or Format must be specified.

示例屏幕截图

原因

如果 XML 到 JSON 政策中未声明 <Options><Format> 中的一个元素,则 API 代理的部署将失败。

如果未使用 <Format>,则需要使用 <Options>

使用 <Format> 元素或 <Options> 元素组。您不能同时使用 <Format><Options>。预定义格式包括:xml.comyahoogooglebadgerFish

诊断

  1. 检查发生故障的特定 API 代理中的所有 XML 到 JSON 政策。如果 XML 到 JSON 政策中没有声明任何 <Options><Format> 元素,则会导致错误。

    例如,以下政策没有声明任何一个元素:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <XMLToJSON async="false" continueOnError="false" enabled="true" name="XMLToJSON">
        <DisplayName>XMLToJSON</DisplayName>
        <Properties/>
        <OutputVariable>response</OutputVariable>
        <Source>response</Source>
    </XMLToJSON>
    

分辨率

确保 XML 到 JSON 政策的 XML 具有该政策中声明的 <Options><Format> 元素之一。

示例 1:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="XMLToJSON">
    <DisplayName>XMLToJSON</DisplayName>
    <Properties/>
    <Format>google</Format>
    <OutputVariable>response</OutputVariable>
    <Source>response</Source>
</XMLToJSON>

示例 2:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="XMLToJSON">
    <DisplayName>XMLToJSON</DisplayName>
    <Properties/>
    <Options>
        <RecognizeNumber>true</RecognizeNumber>
        <RecognizeBoolean>true</RecognizeBoolean>
        <RecognizeNull>true</RecognizeNull>
    </Options>
    <OutputVariable>response</OutputVariable>
    <Source>response</Source>
</XMLToJSON>

UnknownFormat

错误消息

通过 Edge 界面或 Edge Management API 部署 API 代理失败,并显示以下错误消息:

Error Saving Revision [revision_number]
XMLToJSON[policy_name]: Unknown Format [unknown_format].

错误示例

Error Saving Revision 1
XMLToJSON[WithFormat]: Unknown Format google.com.

示例屏幕截图

原因

如果 XML 到 JSON 政策中的 <Format> 元素定义了未知格式,则 API 代理的部署将失败。

预定义格式包括:xml.comyahoogooglebadgerFish

诊断

  1. 标识出错的 XML 到 JSON 政策以及未知格式。您可以从错误消息中找到此信息。例如,在以下错误中,政策名称为 WithFormat,未知格式为 google.com

    Error Saving Revision 1
    XMLToJSON[WithFormat]: Unknown Format google.com.
    
  2. 验证失败的 XML 到 JSON 政策中指定的未知格式是否与错误消息中标识的值(上述第 1 步)相匹配。例如,以下政策将格式指定为 google.com,它与错误消息中的内容匹配:

    <XMLToJSON async="false" continueOnError="false" enabled="true" name="WithFormat">
      <DisplayName>WithFormat</DisplayName>
      <Properties/>
      <Format>google.com</Format>
      <OutputVariable>response</OutputVariable>
      <Source>response</Source>
    </XMLToJSON>
    
  3. 如果指定的格式不是预定义的格式(xml.comyahoogooglebadgerFish),则会导致错误。

    在上面显示的 XML 到 JSON 政策示例中,格式为无效的 google.com。因此,API 代理的部署失败并显示以下错误:

    XMLToJSON[WithFormat]: Unknown Format google.com.
    

分辨率

确保 XML 到 JSON 政策的 <Format> 元素中指定的格式有效。例如:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XMLToJSON async="false" continueOnError="false" enabled="true" name="WithFormat">
  <DisplayName>WithFormat</DisplayName>
  <Properties/>
  <Format>google</Format>
  <OutputVariable>response</OutputVariable>
  <Source>response</Source>
</XMLToJSON>