如何在puta的corda api中使用post?

时间:2018-07-23 04:01:22

标签: corda

**您如何在Corda API中使用post?除了使用put方法,我们还可以使用post吗?

就像@PUT一样,@ POST **有任何选项

 @PUT
 @Path("create-iou")
 fun createIOU(@QueryParam("iouValue") iouValue: Int, 
      @QueryParam("partyName") partyName: CordaX500Name?): 
      Response {
            if (iouValue <= 0 ) {
                return Response.status(BAD_REQUEST).entity("Query parameter 'iouValue' must be non-negative.\n").build()
            }
            if (partyName == null) {
                return Response.status(BAD_REQUEST).entity("Query parameter 'partyName' missing or has wrong format.\n").build()
            }
            val otherParty = rpcOps.wellKnownPartyFromX500Name(partyName) ?:
                    return Response.status(BAD_REQUEST).entity("Party named $partyName cannot be found.\n").build()

            return try {
                val signedTx = rpcOps.startTrackedFlow(::Initiator, iouValue, otherParty).returnValue.getOrThrow()
                Response.status(CREATED).entity("Transaction id ${signedTx.id} committed to ledger.\n").build()

            } catch (ex: Throwable) {
                logger.error(ex.message, ex)
                Response.status(BAD_REQUEST).entity(ex.message!!).build()
            }
        }

2 个答案:

答案 0 :(得分:1)

是的,只需将注释更改为@POST

@PUT
@Path("create-iou")
fun createIOU(@QueryParam("iouValue") iouValue: Int, 
    @QueryParam("partyName") partyName: CordaX500Name?): Response {

    ...

}

答案 1 :(得分:1)

我用过

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("create-iou")
fun createIOU(@FormParam("iouValue") iouValue: Int...

仅将注释更改为@POST的解决方案对我不起作用,并给了我这个例外:

  

java.lang.IllegalArgumentException:指定为非null的参数为null