【发布时间】:2021-03-28 18:13:01
【问题描述】:
我是 Corda 的初学者,我正在尝试使用 Spring Boot API 执行流程。我用的时候:
@PostMapping(value = [ "create-iou" ], 产生 = [ TEXT_PLAIN_VALUE ] , headers = [ "Content-Type=application/x-www-form-urlencoded" ])
我的流程正在执行(通过使用失眠测试它)。但是当我把它改成
@PostMapping(value = [ "create-iou" ], 产生 = [ APPLICATION_JSON_VALUE ], headers = [ "Content-Type=application/json" ])
它给了我一个 406 不可接受的错误:没有返回响应的正文。
这是我创建/复制的 API:
@PostMapping(value = [ "create-iou" ], produces = [ TEXT_PLAIN_VALUE ] , headers = [ "Content-Type=application/x-www-form-urlencoded" ])
fun createIOU(request: HttpServletRequest): ResponseEntity<String> {
val iouValue = request.getParameter("iouValue").toInt()
val partyName = request.getParameter("partyName")
?: return ResponseEntity.badRequest().body("Query parameter 'partyName' must not be null.\n")
if (iouValue <= 0 ) {
return ResponseEntity.badRequest().body("Query parameter 'iouValue' must be non-negative.\n")
}
val partyX500Name = CordaX500Name.parse(partyName)
val otherParty = proxy.wellKnownPartyFromX500Name(partyX500Name) ?: return ResponseEntity.badRequest().body("Party named $partyName cannot be found.\n")
return try {
val signedTx = proxy.startTrackedFlow(::Initiator, iouValue, otherParty).returnValue.getOrThrow()
ResponseEntity.status(HttpStatus.CREATED).body("Transaction id ${signedTx.id} committed to ledger.\n")
} catch (ex: Throwable) {
logger.error(ex.message, ex)
ResponseEntity.badRequest().body(ex.message!!)
}
}
我想返回这样的东西:
{
iouValue: 99,
lender: PartyA,
borrower: PartyB
}
使用 http 端点执行流程时。
【问题讨论】:
标签: spring spring-boot corda