【问题标题】:wso2 Could not save JSON payload. Invalid input stream foundwso2 无法保存 JSON 有效负载。找到无效的输入流
【发布时间】:2015-06-19 14:11:28
【问题描述】:
  1. 这是我在 WSO2 中的第一个 REST API,在 wso2 中的顺序如下。

<? xml version = "1.0" encoding = "UTF-8" ?>
< api xmlns = "http://ws.apache.org/ns/synapse"
    name = "createIssue"
    context = "/rest"
    hostname = "XXX"
    port = "XXX" >
      < resource methods = "POST"
    inSequence = "createInSequence"
    `enter code here`
    outSequence = "createOutSequence" >
      < faultSequence / >
      < /resource>
</api >



      <? xml version = "1.0"
    encoding = "UTF-8" ?>
      < sequence xmlns = "http://ws.apache.org/ns/synapse"
    name = "createInSequence" >
          < log level = "custom" >
          < property name = "location"
          expression = "json-eval($.fields)" / >
      < /log>
      </sequence >
  1. 我调用 api 的 curl 命令如下。

    'curl -X POST -H "Content-Type:application/json" -d@"h:\createissue_own.json" "http://ip:port/rest/api/createissue"'

  2. WSo2 esb 控制台显示如下错误

    newJsonPayload。无法保存 JSON 有效负载。找到无效的输入流。'

  3. 输入的 json,是一个有效的 json,我已经验证并在下面给出。

{
  "fields": {
    "project": {
      "id": "10301"
    },
    "summary": "Issue",
    "description": "Description text",
    "issuetype": {
      "id": "10205"
    },
    "customfield_10600": {
      "id": "10300"
    },
    "customfield_10602": {
      "id": "10301"
    },
    "customfield_10603": "ID text",
    "customfield_10608": {
      "id": "10303"
    },
    "customfield_10609": " text",
    "customfield_10610": " text",
    "customfield_10611": " text",
    "customfield_10612": "Postcode text"
  }
}

请有任何建议。我无法点击 url,并记录输入的 json。

【问题讨论】:

  • 我的问题是 ws02 开发人员 eclipse - 使用 CAF 部署,但由于一个部署实例失败,它继续失败而没有显示错误。从 ESB 控制台中删除了 api 并进行了新的部署,它开始工作了。

标签: json api rest wso2


【解决方案1】:

当您将带有 application/json Content-Type 标头的 XML 有效负载发送到 ESB 时,通常会出现此错误。我们可以在这里做的最好的事情是启用有线日志并检查发送到 ESB 的 HTTP 标头和有效负载。要启用有线日志,请按照以下步骤操作,

  • 关闭 ESB 实例
  • 移动到 $ESB_HOME/repository/conf 目录并找到 log4j.properties 文件然后取消注释以下行

    log4j.logger.org.apache.synapse.transport.http.wire=DEBUG

  • 然后再次重启 ESB 实例并发送请求

监控 ESB 控制台中的wirelogs,如下所示

符号“>>”表示写入 ESB 的内容,“

我也怀疑你的 curl 命令,因此下面给出了一个示例 curl 命令。

   curl -v -d @test.json -H "Content-Type:application/json" http://localhost:8280/rest/api/createissue

【讨论】:

  • 好的。如果我们发现内容类型在 application/xml 中,如何将其作为 application/json 传递。我仅将标头和属性标头添加为 application/json。
猜你喜欢
  • 1970-01-01
  • 2020-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-27
  • 2016-06-19
  • 2019-12-13
  • 1970-01-01
相关资源
最近更新 更多