Grokbase Groups Camel users July 2012
FAQ
Hello!

We use the Java DSL to model Camel Routes.
The RouteBuilder class that we use for this very Route has an attribute and
we would like to use this
attribute as a bean inside the Route.

Here is the code snippet:

public class CreateScriptRoute extends RouteBuilder {
...
private ScriptParams params;

@Override
public void configure() throws Exception {
from("direct:createScriptTransformDBInit")
.routeId("createScriptTransformDBInit")
.bean(params) // that fails!!!
.choice()

...

}

However when I try I get the following error:

Caused by: java.lang.IllegalArgumentException: bean, ref or beanType must be
provided
at
org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:202)
at
org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:441)
at
org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:179)

Is there a way to use the attribute in the bean section of the Route anyway?
I need that instance
because it is injected especially for testing.

Cheers
Hilde

--
View this message in context: http://camel.465427.n5.nabble.com/Attributes-from-RouteBuilder-as-beans-in-route-tp5715628.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Search Discussions

  • Claus Ibsen at Jul 6, 2012 at 2:23 pm
    Hi

    Make sure to set the params attribue before Camel is starting, so its != null
    On Fri, Jul 6, 2012 at 4:04 PM, Hilde wrote:
    Hello!

    We use the Java DSL to model Camel Routes.
    The RouteBuilder class that we use for this very Route has an attribute and
    we would like to use this
    attribute as a bean inside the Route.

    Here is the code snippet:

    public class CreateScriptRoute extends RouteBuilder {
    ...
    private ScriptParams params;

    @Override
    public void configure() throws Exception {
    from("direct:createScriptTransformDBInit")
    .routeId("createScriptTransformDBInit")
    .bean(params) // that fails!!!
    .choice()

    ...

    }

    However when I try I get the following error:

    Caused by: java.lang.IllegalArgumentException: bean, ref or beanType must be
    provided
    at
    org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:202)
    at
    org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:441)
    at
    org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:179)

    Is there a way to use the attribute in the bean section of the Route anyway?
    I need that instance
    because it is injected especially for testing.

    Cheers
    Hilde

    --
    View this message in context: http://camel.465427.n5.nabble.com/Attributes-from-RouteBuilder-as-beans-in-route-tp5715628.html
    Sent from the Camel - Users mailing list archive at Nabble.com.


    --
    Claus Ibsen
    -----------------
    FuseSource
    Email: cibsen@fusesource.com
    Web: http://fusesource.com
    Twitter: davsclaus, fusenews
    Blog: http://davsclaus.com
    Author of Camel in Action: http://www.manning.com/ibsen
  • Hilde at Jul 9, 2012 at 5:53 am
    Hello Claus!

    Thanks for your hint but the routes are defined in the blueprint.xml and
    there is also the camel
    context defined. Please see the following code snippet from the
    blueprint.xml:

    <bean id="createScriptTransformDBInitRoute"

    class="processcontrol.initialization.routes.CreateScriptTransformDBInitRoute"/>

    <camel:camelContext>
    <camel:routeBuilder ref="createScriptTransformDBInitRoute" />
    ...

    Furthermore my test method in its test class that is extended by the super
    class CamelBlueprintTestSupport
    adds the aforementioned camel route on the fly to the context.
    Actually the injection should be happen successfully:

    public class TestCreateScriptTransformDBInitRoute extends
    CamelBlueprintTestSupport {

    @Test
    public void testCreateScriptRecreate() throws Exception {
    CreateScriptTransformDBInitRoute route = new
    CreateScriptTransformDBInitRoute();
    route.setParams(params);
    route.addRoutesToCamelContext(context);
    ...

    Could you give me another approach?

    Thank you!
    Hilde

    --
    View this message in context: http://camel.465427.n5.nabble.com/Attributes-from-RouteBuilder-as-beans-in-route-tp5715628p5715692.html
    Sent from the Camel - Users mailing list archive at Nabble.com.
  • Hilde at Jul 9, 2012 at 1:54 pm
    Hello!

    I have solved it by take all params from the attribute and set theses values
    in the header instead of calling a bean to do the same.
    The endpoint URIs are now setted by the attribute directly because taking
    these informations from the
    header is not allowed because of dynamical reasons. The workaround I came
    across in chosing the recipientList doesn't work as
    we leverage an Content Based Router (choice,when) too.

    Actually I was just to leave the route small instead to bring all into it.

    Cheers
    Hilde

    --
    View this message in context: http://camel.465427.n5.nabble.com/Attributes-from-RouteBuilder-as-beans-in-route-tp5715628p5715736.html
    Sent from the Camel - Users mailing list archive at Nabble.com.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriescamel
postedJul 6, '12 at 2:12p
activeJul 9, '12 at 1:54p
posts4
users2
websitecamel.apache.org

2 users in discussion

Hilde: 3 posts Claus Ibsen: 1 post

People

Translate

site design / logo © 2022 Grokbase