尝试调用业务网络时出错。缺少必填字段

Error trying invoke business network. missing required field

我想从 Node-RED 向 Composer REST 服务器发送一个 POST 请求。

错误 尝试调用业务网络。错误:来自尝试的对等通信的任何 peers.Response 都没有有效响应是一个错误:错误:2 未知:执行链代码时出错:事务返回失败:ValidationException:实例 org.acme.shipping.perishable.AccelReading#c8c829bfd738d7ec63180c5225ae85bd77fad29b4ad9d8ad4bc40a14362f1060 缺少必填字段 accel_x

Playground/Test

{
  "$class": "org.acme.shipping.perishable.AccelReading",
  "accel_x": 0,
  "accel_y": 0,
  "accel_z": 0,
  "latitude": "",
  "longitude": "",
  "readingTime": "",
  "shipment": "resource:org.acme.shipping.perishable.Shipment#4879"
}

Node-RED URL

http://...:31090/api/AccelReading?data=
{"$class":"org.acme.shipping.perishable.AccelReading",
"accel_x":23264,
"accel_y":-20960,
"accel_z":-2448,
"readingTime":"2018-02-14T15:16:44.284Z",
"latitude":"51",
"longitude":"11",
"shipment":"resource:org.acme.shipping.perishable.Shipment#320022000251363131363432"
}

有效载荷

Postman POST 请求,所有参数在正文中定义为 key/value 对

回应

{
    "error": {
        "statusCode": 422,
        "name": "ValidationError",
        "message": "The `AccelReading` instance is not valid. Details: `shipment` can't be blank (value: undefined).",
        "details": {
            "context": "AccelReading",
            "codes": {
                "shipment": [
                    "presence"
                ]
            },
            "messages": {
                "shipment": [
                    "can't be blank"
                ]
            }
        },
        "stack": "ValidationError: The `AccelReading` instance is not valid. Details: `shipment` can't be blank (value: undefined).\n    at /home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:398:12\n    at AccelReading.<anonymous> (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:578:11)\n    at AccelReading.next (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/hooks.js:93:12)\n    at AccelReading.<anonymous> (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:575:23)\n    at AccelReading.trigger (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/hooks.js:83:12)\n    at AccelReading.Validatable.isValid (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/validations.js:541:8)\n    at /home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/dao.js:394:9\n    at doNotify (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n    at doNotify (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n    at doNotify (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n    at doNotify (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:155:49)\n    at Function.ObserverMixin._notifyBaseObservers (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:178:5)\n    at Function.ObserverMixin.notifyObserversOf (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\n    at Function.ObserverMixin._notifyBaseObservers (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)\n    at Function.ObserverMixin.notifyObserversOf (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:153:8)\n    at Function.ObserverMixin._notifyBaseObservers (/home/composer/.npm-global/lib/node_modules/@ibmblockchain/composer-rest-server/node_modules/loopback-datasource-juggler/lib/observer.js:176:15)"
    }
}

Postman/JSON

问题是需要刷新 Composer REST 服务器,以反映出现在 Swagger 中的所需字段。这意味着删除 REST 服务器容器并使用内部 192.x 地址重新创建 - Kubernetes 中的步骤是:

bx cs cluster-config blockchain
export KUBECONFIG=/Users/<name>/.bluemix/plugins/container-service/clusters/blockchain/kube-config-mil01-blockchain.yml
./delete/delete_composer-rest-server.sh
./create/create_composer-rest-server.sh --business-network-card admin@perishable-network

附上POST IoT business network referred to

的截图(刷新后)