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/20 11:15:24 UTC

error while using direct:order

Hi I have done a sample test to send object to queue.

 PurchaseOrder order = new PurchaseOrder();
        order.setName("Camel in Action");
        order.setPrice(4995);
        order.setAmount(1);
        ProducerTemplate template = context.createProducerTemplate();
        template.sendBody("test-jms:queue:order.queue", order);

it works fine.
but when i use direct insted of jms.

 template.sendBody("direct:order", order);

I am getting this error. I guess am missing some basic point.

Exception in thread "main" org.apache.camel.CamelExecutionException:
Exception occurred during execution on the exchange: Exchange[Message:
org.apache.camel.example.jmstofile.PurchaseOrder@1c6f579]
	at
org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1212)

--
View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5498624.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error while using direct:order

Posted by kapoor <bo...@gmail.com>.
yes,
 its in my camel.xml.

camel.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-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="camelinaction"/>
        </dataFormats>

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

          </camelContext>

-------------------------------------

direct:order works only when the router is present? 

--
View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5500167.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error while using direct:order

Posted by Reuben Garrett <re...@gmail.com>.
kapoor,

CamelContext.loadRoutesDefinition(…) receives a standard
java.io.InputStream - you don't have to obtain it from a classpath
resource.  it sounds like you want a java.io.FileInputStream.  try this:

InputStream is = new java.io.FileInputStream("E://cameltest.xml");
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());

note that the String argument to the FileInputStream constructor is
"system-dependent" - so if this is Windows, you might actually want:
new FileInputStream("E:\\cameltest.xml")

http://camel.apache.org/maven/current/camel-core/apidocs/org/apache/camel/CamelContext.html#loadRoutesDefinition%28java.io.InputStream%29
http://docs.oracle.com/javase/6/docs/api/java/io/FileInputStream.html

~ RNPG

Re: error while using direct:order

Posted by kapoor <bo...@gmail.com>.
Hi thank you,
I just need to load the xml outside project: example if the example is in E
folder of my filesystem

I tried like this:

InputStream is = getClass().getResourceAsStream("E://cameltest.xml");

but it throws me

Exception in thread "main" java.lang.IllegalArgumentException: is parameter
must not be null
	at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(Unknown
Source).

how do i have to do it?


--
View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5502825.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error while using direct:order

Posted by Reuben Garrett <re...@gmail.com>.
kapoor, 

is this helpful?  

http://camel.apache.org/loading-routes-from-xml-files.html

// load route from XML and add them to the existing camel 
contextInputStream is = getClass().getResourceAsStream("barRoute.xml"); 
RoutesDefinition routes = context.loadRoutesDefinition(is); 
context.addRouteDefinitions(routes.getRoutes()); 

~ RNPG 

On Feb 21, 2012, at 1:41, kapoor <bo...@gmail.com> wrote:

> Hi thank you. I have a question.
> 
> I have my xml route like this,
> 
> camelcontext.xml:
> 
> <camelContext id="camel" trace="true" 
> xmlns="http://camel.apache.org/schema/spring"> 
> 
>          <dataFormats> 
>              <jaxb id="jaxb" contextPath="camelinaction"/> 
>          </dataFormats> 
> 
>          <route> 
>              <from uri="direct:order"/> 
>              <marshal ref="jaxb"/> 
>              <to uri="jms:queue:test.queue"/> 
>          </route> 
> 
>           </camelContext> 
> 
> in my service method:
> 
> public void jmstoroute()
> {
> 
> /**need to load xml at this point camelcontext.xml before sending object to
> direct:order */
> 
> PurchaseOrder order = new PurchaseOrder(); 
>        order.setName("Camel in Action"); 
>        order.setPrice(4995); 
>        order.setAmount(1); 
>        template.sendBody("direct:order", order); 
> 
> 
> }
> 
> My question:
> 
> In order to send it to direct:order first i need to load the my
> camelcontext.xml file. Am i right?
> How will i load the xml before sending object it to direct:order? My
> camelcontext.xml is located somewhere in my file system(outside project)
> mean?
> 
> 
> 
> 
> --
> View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5501470.html
> Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error while using direct:order

Posted by kapoor <bo...@gmail.com>.
Hi thank you. I have a question.

I have my xml route like this,

camelcontext.xml:

<camelContext id="camel" trace="true" 
 xmlns="http://camel.apache.org/schema/spring"> 
 
          <dataFormats> 
              <jaxb id="jaxb" contextPath="camelinaction"/> 
          </dataFormats> 
 
          <route> 
              <from uri="direct:order"/> 
              <marshal ref="jaxb"/> 
              <to uri="jms:queue:test.queue"/> 
          </route> 
 
           </camelContext> 

in my service method:
 
public void jmstoroute()
{

/**need to load xml at this point camelcontext.xml before sending object to
direct:order */

PurchaseOrder order = new PurchaseOrder(); 
        order.setName("Camel in Action"); 
        order.setPrice(4995); 
        order.setAmount(1); 
        template.sendBody("direct:order", order); 


}

My question:

In order to send it to direct:order first i need to load the my
camelcontext.xml file. Am i right?
How will i load the xml before sending object it to direct:order? My
camelcontext.xml is located somewhere in my file system(outside project)
mean?




--
View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5501470.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error while using direct:order

Posted by Willem Jiang <wi...@gmail.com>.
The answer is Yes.
When the camel context is starting, it will load the route and register 
the consumer to direct:order. When you use the template to send the 
message to direct:order, camel direct endpoint will check if the 
consumer is activated.

On 2/20/12 11:17 PM, Samruben wrote:
> yes,
>   its in my camel.xml.
>
> camel.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-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="camelinaction"/>
>          </dataFormats>
>
>          <route>
>              <from uri="direct:order"/>
>              <marshal ref="jaxb"/>
>              <to uri="jms:queue:test.queue"/>
>          </route>
>
>            </camelContext>
>
> -------------------------------------
>
> direct:order works only when the router is present?
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5499359.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: error while using direct:order

Posted by Samruben <ra...@gmail.com>.
yes,
 its in my camel.xml. 

camel.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-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="camelinaction"/>
        </dataFormats>

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

          </camelContext>

-------------------------------------

direct:order works only when the router is present?

--
View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5499359.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: error while using direct:order

Posted by Willem Jiang <wi...@gmail.com>.
Hi
Did you have any route that consumer the message from the 
"direct:order" ?
Like this
from("direct:order").xxxx

On Mon Feb 20 18:15:24 2012, kapoor wrote:
> Hi I have done a sample test to send object to queue.
>
>   PurchaseOrder order = new PurchaseOrder();
>          order.setName("Camel in Action");
>          order.setPrice(4995);
>          order.setAmount(1);
>          ProducerTemplate template = context.createProducerTemplate();
>          template.sendBody("test-jms:queue:order.queue", order);
>
> it works fine.
> but when i use direct insted of jms.
>
>   template.sendBody("direct:order", order);
>
> I am getting this error. I guess am missing some basic point.
>
> Exception in thread "main" org.apache.camel.CamelExecutionException:
> Exception occurred during execution on the exchange: Exchange[Message:
> org.apache.camel.example.jmstofile.PurchaseOrder@1c6f579]
> 	at
> org.apache.camel.util.ObjectHelper.wrapCamelExecutionException(ObjectHelper.java:1212)
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/error-while-using-direct-order-tp5498624p5498624.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