You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Hilde <hi...@yahoo.de> on 2012/07/06 16:04:21 UTC

Attributes from RouteBuilder as beans in route

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.

Re: Attributes from RouteBuilder as beans in route

Posted by Hilde <hi...@yahoo.de>.
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.

Re: Attributes from RouteBuilder as beans in route

Posted by Hilde <hi...@yahoo.de>.
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.

Re: Attributes from RouteBuilder as beans in route

Posted by Claus Ibsen <cl...@gmail.com>.
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 <hi...@yahoo.de> 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