0
votes

I am trying the connect to Corda using that component and sending data to Apache ActiveMQ again using Apache Camel's Corda component.

Corda is running properly. Particularly, cardapp-example is running, and Notary- PartyA - PartyB and PartyC are alive. I can query using their terminal. ActiveMQ is working properly, I test it with another input source. I've also tried to connect difeerent localhost ports of all four nodes, and also the example one showed in the Camel's corda component webpage.

public class CordaConnector {
    public void ConnectToCorda() throws Exception {
        CamelContext context = new DefaultCamelContext();
        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory();
        context.addComponent("jms", JmsComponent.jmsComponentAutoAcknowledge(connectionFactory));
        context.addRoutes(new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                from("corda://localhost:10004?username=user1&password=test&operation=VAULT_TRACK&contractStateClass=#contractStateClass").
            }
        });

        while(true) {
            context.start();
        }
    }
}

I got the following error message:

Exception in thread "main" org.apache.camel.FailedToCreateRouteException: Failed to create route route1: Route(route1)[From[corda://localhost:10004?username=user1&pa... because of Failed to resolve endpoint: corda://localhost:10004?contractStateClass=%23contractStateClass&operation=VAULT_TRACK&password=test&username=user1 due to: Error binding property (contractStateClass=#contractStateClass) with name: contractStateClass on bean: org.apache.camel.component.corda.CordaConfiguration@1de76cc7 with value: #contractStateClass
...

So when tested seperately, corda works properly, ActiveMQ works properly (with different output), and I ave tried different ports to query information. I have alos tried different commands to query, such as:

from("corda://localhost:10000?username=user1&password=test&operation=NETWORK_MAP_FEED").
to("activemq:queue:try");

I've checked this question Failed to create route route1, but was no help. I would appreciate any help on what might be the reason.

1

1 Answers

0
votes

In your route from uri, you are setting the contractStateClass property using value #contractStateClass : this references a bean named contractStateClass in the Camel registry. But since you did not bind any bean with this name in the context registry, Camel fail to resolve this value: Error binding property (contractStateClass=#contractStateClass) with name: contractStateClass on bean: org.apache.camel.component.corda.CordaConfiguration@1de76cc7 with value: #contractStateClass

You simply need to configure a bean of type Class and provide it to the camel registry. Something like that should work ( camel version 2.24.x )

import net.corda.core.contracts.OwnableState;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;

public class CordaConnector {

    public static void main(String[] args) {
        try {
            SimpleRegistry registry = new SimpleRegistry();
            registry.put("contractStateClass", OwnableState.class);
            CamelContext camelContext = new DefaultCamelContext(registry);
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() {
                    from("corda://localhost:10004?username=user1&password=test&operation=VAULT_TRACK&contractStateClass=#contractStateClass")
                            .log("got message");
                }
            });
            camelContext.start();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}

EDIT for Camel v3.x :

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.support.SimpleRegistry;

public class CordaConnector {

    public static void main(String[] args) {
        try {
            SimpleRegistry registry = new SimpleRegistry();
            registry.bind("contractStateClass", MyContractClass.class);
            CamelContext camelContext = new DefaultCamelContext(registry);
            camelContext.addRoutes(new RouteBuilder() {
                @Override
                public void configure() {
                    from("corda://localhost:10004?username=user1&password=test&operation=VAULT_TRACK&contractStateClass=#contractStateClass")
                            .log("got message");
                }
            });
            camelContext.start();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}