Skip to content

Corda

Inbuilt R3 Corda component: This component uses the Corda RPC client to consume events and can also be used in Producer mode to make other corda-rpc calls

For more information about the Corda component can be found here: https://camel.apache.org/components/latest/corda-component.html

Example

Template: none

import com.example.state.IOUState

import net.corda.client.jackson.JacksonSupport

class JacksonSupportBean {
    // Corda provided module that extends the popular Jackson serialization engine
    def rpcObjectMapper = JacksonSupport.createNonRpcMapper()

    def String serialize(Object myCordaStateBody) {
        return rpcObjectMapper.writeValueAsString(myCordaStateBody)
    }
}
p6.camel.registerBean('jacksonSupport', JacksonSupportBean )

p6.camel.registerBean('contractStateClass', IOUState.class)

p6.camel.getCtx().addRoutes(new RouteBuilder() {

    void configure() {

        from('corda://localhost:10005?username=user1&password=test&operation=VAULT_TRACK&contractStateClass=#contractStateClass')
        .routeId('Corda_IOUState')
        .description('IOUState Class Listener')
        .to('bean://jacksonSupport?method=serialize')
        .to('p6cmb://scripts?platform6.request.action=execute&id=ProcessCordaState')
    }
})

This example uses the nodes and cordapps deployed using the Corda Samples project: https://github.com/corda/samples

After building https://github.com/corda/samples/tree/release-V4/cordapp-example start the four nodes using the runnodes script and then deploy this route.

Note

In order to reference the com.example.state package in your route deployment script it is essential that a copy of the Example cordapp contract JAR files is copied into the folder ${P6_DATA}/lib so it is added to the Platform 6 classpath

cordapp-example-contracts-0.1.jar in this tutorial.

Please refer to the Bundled Resources Service This is the recommended way to distribute JAR files with your applications.

When specifying a contractStateClass using the camel url syntax, a key to a registered bean class must be specified.

The following syntax adds a reference to the IOUState class to the bean registry with key “contractStateClass” :

p6.camel.registerBean("contractStateClass", IOUState.class)

This key can then be used (prefixed with #) in the camel component url.

VAULT_TRACK Operation

When tracking vault state changes using the component in this way the component will emit camel exchanges with a body containing a Corda State API Object

Object references cannot easily be used by other Platform 6 services as they require Serializable entities. To overcome this issue we must serialize the Corda State Object into JSON.

The above example uses JacksonSupportBean to convert the Object to JSON

Note

It is not possible to use the inbuilt marshal().json(JsonLibrary.Jackson) syntax for this due to internal serialization constraints of some Corda objects. Because of this the Corda API provides net.corda.client.jackson.JacksonSupport that allows JSON serialization.

Here is an example of a JSON serialized Corda State Object:

{
  "consumed" : [ ],
  "produced" : [ {
    "state" : {
      "data" : {
        "@class" : "com.example.state.IOUState",
        "value" : 99,
        "lender" : "O=PartyA, L=London, C=GB",
        "borrower" : "O=PartyB, L=New York, C=US",
        "linearId" : {
          "externalId" : null,
          "id" : "1967e7e1-9d9d-4de7-a74f-99a7ee9da839"
        }
      },
      "contract" : "com.example.contract.IOUContract",
      "notary" : "O=Notary, L=London, C=GB",
      "encumbrance" : null,
      "constraint" : {
        "@class" : "net.corda.core.contracts.SignatureAttachmentConstraint",
        "key" : "aSq9DsNNvGhYxYyqA9wd2eduEAZ5AXWgJTbTEw3G5d2maAq8vtLE4kZHgCs5jcB1N31cx1hpsLeqG2ngSysVHqcXhbNts6SkRWDaV7xNcr6MtcbufGUchxredBb6"
      }
    },
    "ref" : {
      "txhash" : "968134F2532881B28C5452E41765A8C5171213996218B38B3A75BAF294845DDA",
      "index" : 0
    }
  } ],
  "flowId" : null,
  "type" : "GENERAL",
  "references" : [ ]
}