You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Pavan Naganna <pa...@outlook.com> on 2014/04/09 03:51:23 UTC

Re: Loading Camel Context from Spring XML

Hi ,

I have problems in copying the files from data/inbox to data/outbox using
Camel with Spring DSL . Below are my beans.xml and Java Programs. Also I am
not seeing processor getting added. 

Please help me on this. 

 

beans.xml

 

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="

       http://www.springframework.org/schema/beans 

       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

       http://camel.apache.org/schema/spring

       http://camel.apache.org/schema/spring/camel-spring.xsd">

 

 

 

<bean id="fileProcessor" class="com.stark.ftp2jms.FileProcessor"/>

<camelContext id="camelContext"
xmlns="http://camel.apache.org/schema/spring" autoStartup="false">

       

       <endpoint id="fromFile" uri="file://data/inbox?noop=true"/>

       <endpoint id="toFile" uri="file://data/outbox"/>

       <route>

              <from ref="fromFile"/>

              <process ref="fileProcessor"/>

              <to ref="toFile"/>

       </route>

</camelContext>

 

</beans>

 

 

FileProcessor.java

 

package com.stark.ftp2jms;

 

import org.apache.camel.Exchange;

import org.apache.camel.Processor;

 

public class FileProcessor implements Processor{

 

       public void process(Exchange exchange) throws Exception {

              System.out.println("Just got the file");

              

       }

       

 

}

 

RecieveContentJob.java: This is where I start CamelContext. Even though I do
this, the files are not getting routed from data/inbox to data/outbox. 

 

public class RecieveContentJob {

 

       public static void main(String[] args) {

              ApplicationContext context = new
ClassPathXmlApplicationContext(new String[]{"beans.xml"});

              

              

              

              try {

                     //CamelContext camelContext= scamelContext;

                     CamelContext camel =
SpringCamelContext.springCamelContext(context);

                     System.out.println(camel.getName());

                     camel.start();

                     System.out.println("Running");

                     /*for (Route route:camelContext.getRoutes())

                     {

                           route.toString();

                     }*/

                     

                     Thread.sleep(1000);

                     camel.stop();

              } catch (Exception e) {

                     // TODO Auto-generated catch block

                     e.printStackTrace();

              }

 

       }

 

 

Thanks,

Pavan Naganna

 


Re: Loading Camel Context from Spring XML

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

You have autoStartup="false">
So the routes is not started out of the box.



On Wed, Apr 9, 2014 at 3:51 AM, Pavan Naganna <pa...@outlook.com> wrote:
> Hi ,
>
> I have problems in copying the files from data/inbox to data/outbox using
> Camel with Spring DSL . Below are my beans.xml and Java Programs. Also I am
> not seeing processor getting added.
>
> Please help me on this.
>
>
>
> beans.xml
>
>
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
>        xsi:schemaLocation="
>
>        http://www.springframework.org/schema/beans
>
>        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>
>        http://camel.apache.org/schema/spring
>
>        http://camel.apache.org/schema/spring/camel-spring.xsd">
>
>
>
>
>
>
>
> <bean id="fileProcessor" class="com.stark.ftp2jms.FileProcessor"/>
>
> <camelContext id="camelContext"
> xmlns="http://camel.apache.org/schema/spring" autoStartup="false">
>
>
>
>        <endpoint id="fromFile" uri="file://data/inbox?noop=true"/>
>
>        <endpoint id="toFile" uri="file://data/outbox"/>
>
>        <route>
>
>               <from ref="fromFile"/>
>
>               <process ref="fileProcessor"/>
>
>               <to ref="toFile"/>
>
>        </route>
>
> </camelContext>
>
>
>
> </beans>
>
>
>
>
>
> FileProcessor.java
>
>
>
> package com.stark.ftp2jms;
>
>
>
> import org.apache.camel.Exchange;
>
> import org.apache.camel.Processor;
>
>
>
> public class FileProcessor implements Processor{
>
>
>
>        public void process(Exchange exchange) throws Exception {
>
>               System.out.println("Just got the file");
>
>
>
>        }
>
>
>
>
>
> }
>
>
>
> RecieveContentJob.java: This is where I start CamelContext. Even though I do
> this, the files are not getting routed from data/inbox to data/outbox.
>
>
>
> public class RecieveContentJob {
>
>
>
>        public static void main(String[] args) {
>
>               ApplicationContext context = new
> ClassPathXmlApplicationContext(new String[]{"beans.xml"});
>
>
>
>
>
>
>
>               try {
>
>                      //CamelContext camelContext= scamelContext;
>
>                      CamelContext camel =
> SpringCamelContext.springCamelContext(context);
>
>                      System.out.println(camel.getName());
>
>                      camel.start();
>
>                      System.out.println("Running");
>
>                      /*for (Route route:camelContext.getRoutes())
>
>                      {
>
>                            route.toString();
>
>                      }*/
>
>
>
>                      Thread.sleep(1000);
>
>                      camel.stop();
>
>               } catch (Exception e) {
>
>                      // TODO Auto-generated catch block
>
>                      e.printStackTrace();
>
>               }
>
>
>
>        }
>
>
>
>
>
> Thanks,
>
> Pavan Naganna
>
>
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/