You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by kapoor <bo...@gmail.com> on 2012/02/14 21:16:08 UTC

routing inside xml file

hi I am new user to camel.

I have tried an example by loading router from xml file. I have done it
successfully. My code is here.


        JAXBContext jaxb =
JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
        Unmarshaller unmarshaller = jaxb.createUnmarshaller();
 
        Resource rs = new ClassPathResource("cameltest.xml");
        Object value = unmarshaller.unmarshal(rs.getInputStream());
        RoutesDefinition routes = (RoutesDefinition) value;
       
        context.addRouteDefinitions(routes.getRoutes());

Instead of doing unmarshalling it in java file. I need to pass the jaxb
object to the xml and should done the routing using unmarshalling inside xml
file itself.

help me....


--
View this message in context: http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5483745.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: routing inside xml file

Posted by Willem Jiang <wi...@gmail.com>.
Are you writing some code in your service class to manage the camel routes?
My question is what's your service looks like.

If so, you'd better do the work yourself instead create another camel 
context in the spring configure file.

On 2/20/12 5:56 PM, Samruben wrote:
> I want the full flow should be in xml not in java file. So only I am trying
> to use Spring concept.
> I have seen some jaxb example in the camelinaction source code. I have
> created a project using jaxb.
> I need to JAXB object which is in my method(jaxb annotated class) should
> directly be used to trigger off the flow defined in the XML. for this
> purpose.I have created a xml like this. whether its the right approach?
>
> <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-2.5.xsd
>         http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
>      ">
> <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
>      <property name="connectionFactory">
>        <bean class="org.apache.activemq.ActiveMQConnectionFactory">
>          <property name="brokerURL" value="tcp://localhost:61616" />
>        </bean>
>      </property>
>    </bean>
>
>      <camelContext id="camel" trace="true"
> xmlns="http://camel.apache.org/schema/spring">
>
>          <dataFormats>
>              <jaxb id="jaxb"
> contextPath="org.ebayopensource.turmeric.demo.v1.services"/>
>          </dataFormats>
>
>          <route>
>              <from uri="direct:services"/>
>              <marshal ref="jaxb"/>
>              <to uri="jms:test.queue"/>
>          </route>
>
>          <route>
>              <from uri="jms:test.queue"/>
>              <unmarshal ref="jaxb"/>
>              <to uri="mock:servicetest"/>
>          </route>
>
>      </camelContext>
>
> </beans>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5498594.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: routing inside xml file

Posted by Christian Müller <ch...@gmail.com>.
I didn't understood what you mean.
Your XML route looks good so far. The code sniped I shared the last time
described how to load this route definition in a standalone java
application.

Best,
Christian

On Mon, Feb 20, 2012 at 10:56 AM, Samruben <ra...@gmail.com> wrote:

> I want the full flow should be in xml not in java file. So only I am trying
> to use Spring concept.
> I have seen some jaxb example in the camelinaction source code. I have
> created a project using jaxb.
> I need to JAXB object which is in my method(jaxb annotated class) should
> directly be used to trigger off the flow defined in the XML. for this
> purpose.I have created a xml like this. whether its the right approach?
>
> <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-2.5.xsd
>       http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd
>    ">
> <bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
>     <property name="connectionFactory">
>      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
>        <property name="brokerURL" value="tcp://localhost:61616" />
>      </bean>
>    </property>
>  </bean>
>
>     <camelContext id="camel" trace="true"
> xmlns="http://camel.apache.org/schema/spring">
>
>        <dataFormats>
>            <jaxb id="jaxb"
> contextPath="org.ebayopensource.turmeric.demo.v1.services"/>
>        </dataFormats>
>
>        <route>
>            <from uri="direct:services"/>
>            <marshal ref="jaxb"/>
>            <to uri="jms:test.queue"/>
>        </route>
>
>        <route>
>            <from uri="jms:test.queue"/>
>            <unmarshal ref="jaxb"/>
>            <to uri="mock:servicetest"/>
>        </route>
>
>    </camelContext>
>
> </beans>
>
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5498594.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: routing inside xml file

Posted by Samruben <ra...@gmail.com>.
I want the full flow should be in xml not in java file. So only I am trying
to use Spring concept.
I have seen some jaxb example in the camelinaction source code. I have
created a project using jaxb.
I need to JAXB object which is in my method(jaxb annotated class) should
directly be used to trigger off the flow defined in the XML. for this
purpose.I have created a xml like this. whether its the right approach?

<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-2.5.xsd
       http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd
    ">
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory">
      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://localhost:61616" />
      </bean>
    </property>
  </bean>

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

        <dataFormats>
            <jaxb id="jaxb"
contextPath="org.ebayopensource.turmeric.demo.v1.services"/>
        </dataFormats>

        <route>
            <from uri="direct:services"/>
            <marshal ref="jaxb"/>
            <to uri="jms:test.queue"/>
        </route>

        <route>
            <from uri="jms:test.queue"/>
            <unmarshal ref="jaxb"/>
            <to uri="mock:servicetest"/>
        </route>

    </camelContext>

</beans>




--
View this message in context: http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5498594.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: routing inside xml file

Posted by Willem Jiang <wi...@gmail.com>.
+1 for this approach.
It could save lots of time for you to wire the components with the camel 
context with the help of Spring.
If you just want to play with routes not the camel context, you may 
still need to use the old API that you just tested.

Willem

On 2/18/12 8:52 PM, Christian Müller wrote:
> Did you had a look at [1] and [2]?
> There is no need to do it so complicated by converting the XML into a JAXB
> object...
>
> You only need something like this:
>
> public class InventoryMain {
>    public static void main(String[] args) throws Exception {
>      Main main = new Main();
>      main.setApplicationContextUri("META-INF/spring/camel-context.xml");
>      main.enableHangupSupport();
>      main.start();
>    }
> }
>
> Source borrowed by Claus/Jonathan book - Camel in Action
>
> [1]
> http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
> [2] http://camel.apache.org/running-camel-standalone.html
>
> Best,
> Christian
>
> On Tue, Feb 14, 2012 at 9:16 PM, kapoor<bo...@gmail.com>  wrote:
>
>> hi I am new user to camel.
>>
>> I have tried an example by loading router from xml file. I have done it
>> successfully. My code is here.
>>
>>
>>         JAXBContext jaxb =
>> JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
>>         Unmarshaller unmarshaller = jaxb.createUnmarshaller();
>>
>>         Resource rs = new ClassPathResource("cameltest.xml");
>>         Object value = unmarshaller.unmarshal(rs.getInputStream());
>>         RoutesDefinition routes = (RoutesDefinition) value;
>>
>>         context.addRouteDefinitions(routes.getRoutes());
>>
>> Instead of doing unmarshalling it in java file. I need to pass the jaxb
>> object to the xml and should done the routing using unmarshalling inside
>> xml
>> file itself.
>>
>> help me....
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5483745.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>


-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang
Weibo: willemjiang

Re: routing inside xml file

Posted by Christian Müller <ch...@gmail.com>.
It would be helpful if you post your code and the complete stack trace...
May be Spring didn't found your Spring file?

However, checkout the Camel in Action code and have a look at [1]. This
code sniped works.

[1]
http://code.google.com/p/camelinaction/source/browse/trunk/chapter13/standalone/src/main/java/camelinaction/InventoryMain.java

Best,
Christian

On Sun, Feb 19, 2012 at 10:52 PM, Samruben <ra...@gmail.com> wrote:

> Hi
>
> I am also facing the same issue. I have tried you idea. But I am getting
> this error. I have tried with routing with file://test to file://test2, am
> not getting error. only when i use jms
>
> error:
> Exception in thread "main"
> org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected
> exception parsing XML document from class path resource [cameltest.xml];
> nested exception is java.lang.NullPointerException
>        at
>
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)
>
> my cameltest.xml:
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <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="jmstest" class="org.apache.camel.component.jms.JmsComponent">
>    <property name="connectionFactory">
>      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
>        <property name="brokerURL" value="tcp://localhost:61616" />
>      </bean>
>    </property>
>  </bean>
>
>  <bean id="jmstest2" class="org.apache.camel.component.jms.JmsComponent">
>    <property name="connectionFactory">
>      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
>        <property name="brokerURL" value="tcp://localhost:61616" />
>      </bean>
>    </property>
>  </bean>
>
>    <bean id="downloadLogger" class="camel.JmsToFileRoute"/>
>
>
>  <camelContext xmlns="http://camel.apache.org/schema/spring">
>    <route>
>      <from uri="jmstest:test.queue"/>
>      <process ref="downloadLogger"/>
>      <to uri="jmstest2:test2.queue"/>
>    </route>
>  </camelContext>
>
> </beans>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5497609.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: routing inside xml file

Posted by Samruben <ra...@gmail.com>.
Hi 

I am also facing the same issue. I have tried you idea. But I am getting
this error. I have tried with routing with file://test to file://test2, am
not getting error. only when i use jms

error:
Exception in thread "main"
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected
exception parsing XML document from class path resource [cameltest.xml];
nested exception is java.lang.NullPointerException
	at
org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412)

my cameltest.xml:

<?xml version="1.0" encoding="UTF-8"?>

<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="jmstest" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory">
      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://localhost:61616" />
      </bean>
    </property>
  </bean>
  
 <bean id="jmstest2" class="org.apache.camel.component.jms.JmsComponent">
    <property name="connectionFactory">
      <bean class="org.apache.activemq.ActiveMQConnectionFactory">
        <property name="brokerURL" value="tcp://localhost:61616" />
      </bean>
    </property>
  </bean>  
  
    <bean id="downloadLogger" class="camel.JmsToFileRoute"/> 

  
  <camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
      <from uri="jmstest:test.queue"/>
      <process ref="downloadLogger"/>
      <to uri="jmstest2:test2.queue"/>
    </route>
  </camelContext> 

</beans>


--
View this message in context: http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5497609.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: routing inside xml file

Posted by Christian Müller <ch...@gmail.com>.
I should mention that the Main class comes from camel-spring
(org.apache.camel.spring.Main).

Best,
Christian

On Sat, Feb 18, 2012 at 1:52 PM, Christian Müller <
christian.mueller@gmail.com> wrote:

> Did you had a look at [1] and [2]?
> There is no need to do it so complicated by converting the XML into a JAXB
> object...
>
> You only need something like this:
>
> public class InventoryMain {
>   public static void main(String[] args) throws Exception {
>     Main main = new Main();
>     main.setApplicationContextUri("META-INF/spring/camel-context.xml");
>     main.enableHangupSupport();
>     main.start();
>   }
> }
>
> Source borrowed by Claus/Jonathan book - Camel in Action
>
> [1]
> http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
> [2] http://camel.apache.org/running-camel-standalone.html
>
> Best,
> Christian
>
>
> On Tue, Feb 14, 2012 at 9:16 PM, kapoor <bo...@gmail.com> wrote:
>
>> hi I am new user to camel.
>>
>> I have tried an example by loading router from xml file. I have done it
>> successfully. My code is here.
>>
>>
>>        JAXBContext jaxb =
>> JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
>>        Unmarshaller unmarshaller = jaxb.createUnmarshaller();
>>
>>        Resource rs = new ClassPathResource("cameltest.xml");
>>        Object value = unmarshaller.unmarshal(rs.getInputStream());
>>        RoutesDefinition routes = (RoutesDefinition) value;
>>
>>        context.addRouteDefinitions(routes.getRoutes());
>>
>> Instead of doing unmarshalling it in java file. I need to pass the jaxb
>> object to the xml and should done the routing using unmarshalling inside
>> xml
>> file itself.
>>
>> help me....
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5483745.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>

Re: routing inside xml file

Posted by Christian Müller <ch...@gmail.com>.
Did you had a look at [1] and [2]?
There is no need to do it so complicated by converting the XML into a JAXB
object...

You only need something like this:

public class InventoryMain {
  public static void main(String[] args) throws Exception {
    Main main = new Main();
    main.setApplicationContextUri("META-INF/spring/camel-context.xml");
    main.enableHangupSupport();
    main.start();
  }
}

Source borrowed by Claus/Jonathan book - Camel in Action

[1]
http://camel.apache.org/running-camel-standalone-and-have-it-keep-running.html
[2] http://camel.apache.org/running-camel-standalone.html

Best,
Christian

On Tue, Feb 14, 2012 at 9:16 PM, kapoor <bo...@gmail.com> wrote:

> hi I am new user to camel.
>
> I have tried an example by loading router from xml file. I have done it
> successfully. My code is here.
>
>
>        JAXBContext jaxb =
> JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
>        Unmarshaller unmarshaller = jaxb.createUnmarshaller();
>
>        Resource rs = new ClassPathResource("cameltest.xml");
>        Object value = unmarshaller.unmarshal(rs.getInputStream());
>        RoutesDefinition routes = (RoutesDefinition) value;
>
>        context.addRouteDefinitions(routes.getRoutes());
>
> Instead of doing unmarshalling it in java file. I need to pass the jaxb
> object to the xml and should done the routing using unmarshalling inside
> xml
> file itself.
>
> help me....
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/routing-inside-xml-file-tp5483745p5483745.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>