2
votes

I'm very new to Camel, but basically, I've got a bean with a function called populate. Camel is not able to call this method, nor does it activate anything in the route it seems. I dont know what I'm doing wrong, can someone help?

I tried using populate() and populate in my route, I also tried getting rid of @Handler.

the Logger does not get called either, I just put it there to see what happens.

Here is my route, then I'll post my bean.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:camel="http://camel.apache.org/schema/spring"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
   http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">


 <bean id="mockSql" class="tutorial.simple.route.MockSql"/>

 <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="direct:start"/>
    <log loggingLevel="DEBUG" message="logger" id="123" customId="true"/>
    <to uri="bean:mockSql?method=populate()"/>
  </route>
</camelContext>
</beans>

heres my bean:

package tutorial.simple.route;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.camel.Handler;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;


public class MockSql {
private static final Logger log = Logger.getLogger("mockSql");

    public MockSql(){
        log.setLevel(Level.DEBUG);
        log.debug("constructed mock sql");

    }
    @Handler
    public ArrayList populate(){
    ArrayList <HashMap> ary = new ArrayList<HashMap>();
    HashMap<String, String> hm = new HashMap();
    HashMap<String, String> hm2 = new HashMap();
    hm.put("n1", "j1");
    hm2.put("n2", "j2");

    ary.add(hm);
    ary.add(hm2);

    log.debug("populated mock sql");
    return ary;
}


}

output:

[pache.camel.spring.Main.main()] MainSupport INFO Apache Camel 2.12.0.redhat-610379 starting [pache.camel.spring.Main.main()] mockSql DEBUG constructed mock sql [pache.camel.spring.Main.main()] SpringCamelContext INFO Apache Camel 2.12.0.redhat-610379 (CamelContext: camel) is starting [pache.camel.spring.Main.main()] ManagedManagementStrategy INFO JMX is enabled [pache.camel.spring.Main.main()] DefaultTypeConverter INFO Loaded 176 type converters [pache.camel.spring.Main.main()] SpringCamelContext INFO AllowUseOriginalMessage is enabled. If access to the original message is not needed, then its recommended to turn this option off as it may improve performance. [pache.camel.spring.Main.main()] SpringCamelContext INFO StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html [pache.camel.spring.Main.main()] SpringCamelContext INFO Route: route1 started and consuming from: Endpoint[direct://start] [pache.camel.spring.Main.main()] SpringCamelContext INFO Total 1 routes, of which 1 is started. [pache.camel.spring.Main.main()] SpringCamelContext INFO Apache Camel 2.12.0.redhat-610379 (CamelContext: camel) started in 0.324 seconds

1

1 Answers

1
votes

A direct endpoint can be triggeted only from another route, for example like this:

<route>
    <from uri="<other endpoint>"/>
    ...
    <to uri="direct:start"/>
</route>

so in your case the route is never triggered.