Closed gdeudney closed 12 years ago
Hi there,
the method described in my blog post applies only to very simple scenarios. I think I should have mentioned that but I didn't... The post is from times when Groovy had no anonymous classes support and thus implementing it the proper way was not really nice.
But to the point. When you create a route like in the post you're not going through the proper chain of methods. That's why only on-level routing works (so to speak). from(src).to(dest) will work just fine but going over a filter will throw an exception like the one you are experiencing. There is however a very simple solution available.:
def index = { if (camelContext.routes.size() == 0) { camelContext.addRoutes(new RouteBuilder() { @Override void configure() { from("seda:input") .filter({ it.in.body.contains('from') }) .to("stream:out") } }); } render text: camelContext.routes.size().toString(), contentType: "text/plain" }
Here we're taking the proper approach to route building and it works just fine.
Hope it helps.
Matthias.
2012/1/20 Gmonkey < reply@reply.github.com
I have an issue with runtime routes and using filters. I am using the example from http://padcom13.blogspot.com/2011/01/grails-camel-and-adding-routes-in.html Here is the only change from("seda:input").filter {it.in.body.contains("from")}.to("stream:out")
I get the following error
| Error 2012-01-19 21:22:22,396 ["http-bio-8080"-exec-10] ERROR errors.GrailsExc eptionResolver - ClassCastException occurred when processing request: [GET] /in tuitiveoms/startFixEngine/index org.apache.camel.model.FilterDefinition cannot be cast to org.apache.camel.model .RouteDefinition. Stacktrace follows: Message: org.apache.camel.model.FilterDefinition cannot be cast to org.apache.ca mel.model.RouteDefinition Line | Method
->> 643 | addRouteDefinitions in org.apache.camel.impl.DefaultCamelContext
| 20 | index in com.transatron.fix.StartFixEngineController$$EN MVWQ8M | 886 | runTask . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker | 908 | run in '' ^ 662 | run . . . . . . . . in java.lang.Thread
Not sure what I am doing wrong.
Thanks
Reply to this email directly or view it on GitHub: https://github.com/padcom/grails-routing/issues/8
Closing as not directly plugin related
Thanks works well.
I have an issue with runtime routes and using filters.
I am Grails 2.0.0 and the latest version 1.1.6 of camel route I am using the example from http://padcom13.blogspot.com/2011/01/grails-camel-and-adding-routes-in.html Here is the only change from("seda:input").filter {it.in.body.contains("from")}.to("stream:out")
I get the following error
| Error 2012-01-19 21:22:22,396 ["http-bio-8080"-exec-10] ERROR errors.GrailsExc eptionResolver - ClassCastException occurred when processing request: [GET] test/testRouteFilter/index org.apache.camel.model.FilterDefinition cannot be cast to org.apache.camel.model .RouteDefinition. Stacktrace follows: Message: org.apache.camel.model.FilterDefinition cannot be cast to org.apache.ca mel.model.RouteDefinition Line | Method
->> 643 | addRouteDefinitions in org.apache.camel.impl.DefaultCamelContext
| 20 | index in TestRouteFilterController$$EN MVWQ8M | 886 | runTask . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker | 908 | run in '' ^ 662 | run . . . . . . . . in java.lang.Thread
Not sure what I am doing wrong
Thanks