Discussion:
Not able to define processor in Camel
nettome
2014-07-24 12:22:46 UTC
Permalink
Hi,
I'm new to Camel and learning it step by step.
I have a scenario where i have to process a task in a route. I'm creating a
XML file and loading the routes from it.
Below is my xml file -

<routes xmlns="http://camel.apache.org/schema/spring">
<bean id= "jsonProcessor" class="com.validator.parser.JsonParser" />
<route id="fromFile">
<from uri="file:/data/inbox"/>
<process ref="jsonProcessor" />
<to uri="cache:default"/>
</route>
</routes>

Code to load the XML file -

ModelCamelContext context = (ModelCamelContext) new DefaultCamelContext();
RouteBuilder builder = null;
File fileFolder = new
File("/home/workspace/Validator/src/main/resources/com/validator/routes");

// load route from XML and add them to the existing camel context
RoutesDefinition routes;

try {

for(final File file : fileFolder.listFiles()){
if(file.isFile()){
InputStream in = new FileInputStream(file);
routes = context.loadRoutesDefinition(in);
context.addRouteDefinitions(routes.getRoutes());
}
}

context.start();
Thread.sleep(4000);
} catch (Exception e) {
e.printStackTrace();
}




JsonParser is a Processor and I want the route to go to the processor. But
while I'm doing the above I'm getting the following error -

Caused by: java.lang.IllegalArgumentException: registry entry called
jsonProcessor must be specified on: process[ref:jsonProcessor]


there are couple of things I'm missing/not clear over here -

1. Is my bean definition correct?
2. Should I create the camelContext in the XML file or the Java code
3. Is my XML structured properly.

Please guide. I'm stuck and not able to find much on the internet.

thanks!
Claus Ibsen
2014-07-24 12:28:31 UTC
Permalink
Hi

<bean id= "jsonProcessor" class="com.validator.parser.JsonParser" />

should be outside <route>
Post by nettome
Hi,
I'm new to Camel and learning it step by step.
I have a scenario where i have to process a task in a route. I'm creating a
XML file and loading the routes from it.
Below is my xml file -
<routes xmlns="http://camel.apache.org/schema/spring">
<bean id= "jsonProcessor" class="com.validator.parser.JsonParser" />
<route id="fromFile">
<from uri="file:/data/inbox"/>
<process ref="jsonProcessor" />
<to uri="cache:default"/>
</route>
</routes>
Code to load the XML file -
ModelCamelContext context = (ModelCamelContext) new DefaultCamelContext();
RouteBuilder builder = null;
File fileFolder = new
File("/home/workspace/Validator/src/main/resources/com/validator/routes");
// load route from XML and add them to the existing camel context
RoutesDefinition routes;
try {
for(final File file : fileFolder.listFiles()){
if(file.isFile()){
InputStream in = new FileInputStream(file);
routes = context.loadRoutesDefinition(in);
context.addRouteDefinitions(routes.getRoutes());
}
}
context.start();
Thread.sleep(4000);
} catch (Exception e) {
e.printStackTrace();
}
JsonParser is a Processor and I want the route to go to the processor. But
while I'm doing the above I'm getting the following error -
Caused by: java.lang.IllegalArgumentException: registry entry called
jsonProcessor must be specified on: process[ref:jsonProcessor]
there are couple of things I'm missing/not clear over here -
1. Is my bean definition correct?
2. Should I create the camelContext in the XML file or the Java code
3. Is my XML structured properly.
Please guide. I'm stuck and not able to find much on the internet.
thanks!
--
View this message in context: http://camel.465427.n5.nabble.com/Not-able-to-define-processor-in-Camel-tp5754376.html
Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen-H+wXaHxf7aLQT0dZR+***@public.gmane.org
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
nettome
2014-07-24 12:37:28 UTC
Permalink
Hi Claus,
I tried that as below -

<bean id= "jsonProcessor"
class="com.ericsson.pmed.validator.parser.JsonParser" />
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="fromFile">
<from uri="file:/data/inbox"/>
<process ref="jsonProcessor" />
<to uri="cache:default"/>
</route>

</routes>

but then I'm getting the following error -

unexpected element (uri:"", local:"bean"). Expected elements are
<{http://camel.apache.org/schema/spring}aggregate>,
Claus Ibsen
2014-07-24 12:42:10 UTC
Permalink
Ah you load routes from an xml file, then you cannot define spring beans etc.

You can use the class component
http://camel.apache.org/class

And instead of <process> then use <to> where the uri is using the
class component
And then remove the <bean>
Post by nettome
Hi Claus,
I tried that as below -
<bean id= "jsonProcessor"
class="com.ericsson.pmed.validator.parser.JsonParser" />
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="fromFile">
<from uri="file:/data/inbox"/>
<process ref="jsonProcessor" />
<to uri="cache:default"/>
</route>
</routes>
but then I'm getting the following error -
unexpected element (uri:"", local:"bean"). Expected elements are
<{http://camel.apache.org/schema/spring}aggregate>,
--
View this message in context: http://camel.465427.n5.nabble.com/Not-able-to-define-processor-in-Camel-tp5754376p5754380.html
Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen-H+wXaHxf7aLQT0dZR+***@public.gmane.org
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
nettome
2014-07-24 13:09:17 UTC
Permalink
Hi Claus,
I did that and that has removed the error, thanks!

check the xml below -

<routes xmlns="http://camel.apache.org/schema/spring">
<route id="fromFile">
<from uri="file:/data/inbox?noop=ture"/>
<to uri = "class:com.validator.parser.JsonParser" />
<to uri="cache:default" />
</route>

</routes>

But, Now i face a new problem... the way the above route should work is that
I read a file. do some processing on it and save that in a Cache. The cache
component is a component that I created not the camel-cache component.

JsonParser is a Processor that is suppose to process the file(json file) and
the cache then would store the proceseed message most prob a JsonNode.

My processor code (JsonParser) is not getting hit now, how to proceed around
that? Neither is it gng to the CacheComponentProducer I created however I
can see the sysout in my CacheComponent on the console.
Claus Ibsen
2014-07-24 13:13:30 UTC
Permalink
Hi

You code had a sleep 4 sec that is not a lot of time.

See how to keep running camel
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
Post by nettome
Hi Claus,
I did that and that has removed the error, thanks!
check the xml below -
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="fromFile">
<from uri="file:/data/inbox?noop=ture"/>
<to uri = "class:com.validator.parser.JsonParser" />
<to uri="cache:default" />
</route>
</routes>
But, Now i face a new problem... the way the above route should work is that
I read a file. do some processing on it and save that in a Cache. The cache
component is a component that I created not the camel-cache component.
JsonParser is a Processor that is suppose to process the file(json file) and
the cache then would store the proceseed message most prob a JsonNode.
My processor code (JsonParser) is not getting hit now, how to proceed around
that? Neither is it gng to the CacheComponentProducer I created however I
can see the sysout in my CacheComponent on the console.
--
View this message in context: http://camel.465427.n5.nabble.com/Not-able-to-define-processor-in-Camel-tp5754376p5754386.html
Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen-H+wXaHxf7aLQT0dZR+***@public.gmane.org
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
nettome
2014-07-24 16:24:37 UTC
Permalink
I increased the time to 20 seconds still I my producer is not called.
I don't think that's the problem.
Claus Ibsen
2014-07-24 19:29:25 UTC
Permalink
And you are sure there is a file for the Camel route to pickup?
Post by nettome
I increased the time to 20 seconds still I my producer is not called.
I don't think that's the problem.
--
View this message in context: http://camel.465427.n5.nabble.com/Not-able-to-define-processor-in-Camel-tp5754376p5754406.html
Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen-H+wXaHxf7aLQT0dZR+***@public.gmane.org
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
nettome
2014-07-25 07:20:00 UTC
Permalink
Yes, I'm able to read the file..

System.out.println(file.getName());
InputStream in = new FileInputStream(file);
routes = context.loadRoutesDefinition(in);
context.addRouteDefinitions(routes.getRoutes());

in the above code, I'm getting my route.xml file defined as below -
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="fromFile">
<from uri="file:/data/inbox?noop=ture"/>
<to uri = "class:com.ericsson.pmed.validator.parser.JsonParser" />
<to uri="cache:default" />
</route>

</routes>


but, my CacheComponentProducer is not invoked.
Also, when I'm doing the same thing in a java program through JAVA DSL, its
working. My CacheComponentProducer is getting called.

where should i look for it...
Claus Ibsen
2014-07-25 07:31:55 UTC
Permalink
Hi

See this example and its source code how its done
http://camel.apache.org/console-example.html
Post by nettome
Yes, I'm able to read the file..
System.out.println(file.getName());
InputStream in = new FileInputStream(file);
routes = context.loadRoutesDefinition(in);
context.addRouteDefinitions(routes.getRoutes());
in the above code, I'm getting my route.xml file defined as below -
<routes xmlns="http://camel.apache.org/schema/spring">
<route id="fromFile">
<from uri="file:/data/inbox?noop=ture"/>
<to uri = "class:com.ericsson.pmed.validator.parser.JsonParser" />
<to uri="cache:default" />
</route>
</routes>
but, my CacheComponentProducer is not invoked.
Also, when I'm doing the same thing in a java program through JAVA DSL, its
working. My CacheComponentProducer is getting called.
where should i look for it...
--
View this message in context: http://camel.465427.n5.nabble.com/Not-able-to-define-processor-in-Camel-tp5754376p5754431.html
Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen-H+wXaHxf7aLQT0dZR+***@public.gmane.org
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/
Loading...