On Thu, Jul 28, 2011 at 6:51 PM, Rogelio Alejandro Ortiz Sevilla
<rogelio.sevil...@gmail.com> wrote:
> Thanks A LOT for the answer mr. Claus, i used
>
> <bean beanType="com.mycompany.MyPojo" method="getHtmlCode"/>
>
> And works great!!!.  I do have a follow up question if you don't mind, it's
> also about data injection. My route class currently  looks like this:
>
>
> MyRouteClass extends RouteBuilder{
>
> private String myVar1;
> //getter and setter for myVar1
>
> public void configure() throws Exception {
>                    FileInputStream fis = new
> FileInputStream("myroute.xml");
>                    RoutesDefinition routes =
>  getContext().loadRoutesDefinition(fis);
>  }
>
> }
>
> And in my xml file i have this:
>
> <from uri="quartz://fetchUrl?cron=0+0/1+*+*+*+?"/>
>            <setProperty propertyName="coolProperty">
>                <simple>myVar1</simple>
>            </setProperty>
>
>
> Obviously the property is getting the literal value "myVar1" which is
> something i don't want. I need to send the value contained on
> the instance member myVar1, is there any way i could achieve this??
>

Where is the source for that myVar1 value?

You can use property placeholders if the source is a properties file
http://camel.apache.org/using-propertyplaceholder.html



> Thanks A LOT in advance
>
>
>
> 2011/7/28 Claus Ibsen <claus.ib...@gmail.com>
>
>> Camel is not a bean container. You have to have the bean installed already.
>> For example in the spring xml file.
>>
>> However you can tell Camel the FQN of the bean class and it can invoke
>> it directly, in case it has a default ctr.
>>
>> In the camel route do something like:
>> <bean type="com.foo.MyBean"/>
>>
>> The attribute may have a slightly different name, than type.
>>
>>
>> On Thu, Jul 28, 2011 at 5:08 PM, rogelio_sevilla1
>> <rogelio.sevil...@gmail.com> wrote:
>> > I think i was wrong, the info on this page:
>> >
>> > http://camel.apache.org/loading-routes-from-xml-files.html
>> >
>> > is the right answer, however, i think i'm missing something. Currently, i
>> > have a camel route that looks like this:
>> >
>> > public void configure() throws Exception {
>> >                   FileInputStream fis = new
>> FileInputStream("myroute.xml");
>> >                    RoutesDefinition routes =
>> > getContext().loadRoutesDefinition(fis);
>> > }
>> >
>> >
>> > And my  myroute.xml  file looks like this:
>> >
>> >
>> >
>> > <?xml version="1.0" encoding="UTF-8"?>
>> >    <routes xmlns="http://camel.apache.org/schema/spring";>
>> >        <bean id="myPojo" class="com.mycompany.MyPojo"/>
>> >        <route>
>> >            <from uri="quartz://fetchUrl?cron=0+0/1+*+*+*+?"/>
>> >            <setProperty propertyName="contract">
>> >                <simple>contract</simple>
>> >            </setProperty>
>> >            <setProperty propertyName="dataFeedSource">
>> >                <simple>dataFeedSource</simple>
>> >            </setProperty>
>> >            <setProperty propertyName="dataFeedType">
>> >                <simple>dataFeedType</simple>
>> >            </setProperty>
>> >            <setProperty propertyName="url">
>> >                <simple>url</simple>
>> >            </setProperty>
>> >            <bean ref="myPojo" method="getHtmlCode"/>
>> >            <bean ref="myPojo" method="getUrls"/>
>> >            <split>
>> >                <tokenize  token="\n"/>
>> >                <to uri="seda:theUrls"/>
>> >            </split>
>> >        </route>
>> >    <route>
>> >        <from uri="seda:theUrls?concurrentConsumers=8"/>
>> >        <bean ref="myPojo" method="setUrl"/>
>> >        <to uri="http://dummyhost"; />
>> >        <bean ref="myPojo" method="processContent"/>
>> >    </route>
>> >    </routes>
>> >
>> >
>> >
>> > As you can see, i'm declaring a bean using this:
>> >
>> >        <bean id="myPojo" class="com.mycompany.MyPojo"/>
>> >
>> > However, at the moment of running this code, i'm getting this exception:
>> >
>> >
>> > Failed to create route route1 at: >>> Bean[ref:myPojo method:
>> getHtmlCode]
>> >  because of No bean could be found in the registry for: myPojo
>> >
>> > Caused by: org.apache.camel.NoSuchBeanException: No bean could be found
>> in
>> > the registry for: myPojo
>> >        at
>> >
>> org.apache.camel.component.bean.RegistryBean.getBean(RegistryBean.java:68)
>> >        at
>> >
>> org.apache.camel.model.BeanDefinition.createProcessor(BeanDefinition.java:155)
>> >        at
>> >
>> org.apache.camel.model.ProcessorDefinition.makeProcessor(ProcessorDefinition.java:433)
>> >        at
>> >
>> org.apache.camel.model.ProcessorDefinition.addRoutes(ProcessorDefinition.java:181)
>> >        at
>> >
>> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:815)
>> >
>> >
>> >
>> > Am i missing another step on the process??
>> >
>> > --
>> > View this message in context:
>> http://camel.465427.n5.nabble.com/Injecting-data-to-routes-loaded-from-xml-file-tp4639765p4643056.html
>> > Sent from the Camel - Users mailing list archive at Nabble.com.
>> >
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> FuseSource
>> Email: cib...@fusesource.com
>> Web: http://fusesource.com
>> Twitter: davsclaus, fusenews
>> Blog: http://davsclaus.blogspot.com/
>> Author of Camel in Action: http://www.manning.com/ibsen/
>>
>



-- 
Claus Ibsen
-----------------
FuseSource
Email: cib...@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/

Reply via email to