pojo producing and consuming

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

pojo producing and consuming

claus.straube
Hi all,

I want to produce a message from a pojo and send it via activemq to an
other pojo. This works if I have something like that:

//bean
public class MyBean {
   
    @EndpointInject(uri="activemq:bar")
    protected ProducerTemplate     producer;
   
    @Produce(uri = "activemq:foo")
    protected MyListener         producer2;

    public void doSomething(String name){
         producer.sendBody("<hello>" + name + "</hello>");
    }
   
    public void doSomethingElse(String name){
        producer2.sayHello("<hello>" + name + "</hello>");
    }
   
    @Consume(uri = "activemq:bar")
    public void consumeSomething(String name){
        System.out.println(name);
    }
   
    @Consume(uri = "activemq:foo")
    public void consumeSomethingElse(String name){
        System.out.println(name);
    }
   
    public void setProducer2(MyListener producer2) {
        this.producer2 = producer2;
    }
       
}

//interface for producer proxy
public interface MyListener {
    String sayHello(String name);
}

If I call doSomething("bar") the result is "<hello>bar</hello>". But if
I call doSomethingElse("bar")  - the method without the explicit
ProducerTemplate - this exception will be thrown:

 java.lang.IllegalArgumentException: object is not an instance of
declaring class
org.apache.camel.RuntimeCamelException:
java.lang.IllegalArgumentException: object is not an instance of
declaring class
    at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1011)
    at
org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:85)
    at
org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:95)
    at
org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:83)
    at
org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:543)
    at
org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:482)
    at
org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:451)
    at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:323)
    at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:261)
    at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:982)
    at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:974)
    at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:876)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.IllegalArgumentException: object is not an instance
of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at
org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:80)
    ... 11 more
06.11.2009 14:12:45
org.springframework.jms.listener.AbstractMessageListenerContainer
handleListenerException
WARNUNG: Execution of JMS message listener failed
org.apache.camel.RuntimeCamelException:
java.lang.IllegalArgumentException: object is not an instance of
declaring class
    at
org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1011)
    at
org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:85)
    at
org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:95)
    at
org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:83)
    at
org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:543)
    at
org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:482)
    at
org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:451)
    at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:323)
    at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:261)
    at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:982)
    at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:974)
    at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:876)
    at java.lang.Thread.run(Thread.java:636)
Caused by: java.lang.IllegalArgumentException: object is not an instance
of declaring class
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at
org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:80)
    ... 11 more

What I am doing wrong here?

Thanks in advance - Claus
Reply | Threaded
Open this post in threaded view
|

Re: pojo producing and consuming

Claus Ibsen-2
Hi

What version of Camel and Spring are you using?
Can you try with latest code from trunk?
And you can enable TRACE logging at org.apache.camel.component.bean
that may help to identify what could be wrong.


And can you create a small unit test demonstrating this issue and
create a JIRA ticket and add it there.


On Fri, Nov 6, 2009 at 2:17 PM, Claus Straube <[hidden email]> wrote:

> Hi all,
>
> I want to produce a message from a pojo and send it via activemq to an other
> pojo. This works if I have something like that:
>
> //bean
> public class MyBean {
>     @EndpointInject(uri="activemq:bar")
>   protected ProducerTemplate     producer;
>     @Produce(uri = "activemq:foo")
>   protected MyListener         producer2;
>
>   public void doSomething(String name){
>        producer.sendBody("<hello>" + name + "</hello>");
>   }
>     public void doSomethingElse(String name){
>       producer2.sayHello("<hello>" + name + "</hello>");
>   }
>     @Consume(uri = "activemq:bar")
>   public void consumeSomething(String name){
>       System.out.println(name);
>   }
>     @Consume(uri = "activemq:foo")
>   public void consumeSomethingElse(String name){
>       System.out.println(name);
>   }
>     public void setProducer2(MyListener producer2) {
>       this.producer2 = producer2;
>   }
>      }
>
> //interface for producer proxy
> public interface MyListener {
>   String sayHello(String name);
> }
>
> If I call doSomething("bar") the result is "<hello>bar</hello>". But if I
> call doSomethingElse("bar")  - the method without the explicit
> ProducerTemplate - this exception will be thrown:
>
> java.lang.IllegalArgumentException: object is not an instance of declaring
> class
> org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException:
> object is not an instance of declaring class
>   at
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1011)
>   at
> org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:85)
>   at
> org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:95)
>   at
> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:83)
>   at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:543)
>   at
> org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:482)
>   at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:451)
>   at
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:323)
>   at
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:261)
>   at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:982)
>   at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:974)
>   at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:876)
>   at java.lang.Thread.run(Thread.java:636)
> Caused by: java.lang.IllegalArgumentException: object is not an instance of
> declaring class
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:616)
>   at
> org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:80)
>   ... 11 more
> 06.11.2009 14:12:45
> org.springframework.jms.listener.AbstractMessageListenerContainer
> handleListenerException
> WARNUNG: Execution of JMS message listener failed
> org.apache.camel.RuntimeCamelException: java.lang.IllegalArgumentException:
> object is not an instance of declaring class
>   at
> org.apache.camel.util.ObjectHelper.wrapRuntimeCamelException(ObjectHelper.java:1011)
>   at
> org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:85)
>   at
> org.apache.camel.component.bean.BeanProcessor.process(BeanProcessor.java:95)
>   at
> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:83)
>   at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:543)
>   at
> org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:482)
>   at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:451)
>   at
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:323)
>   at
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:261)
>   at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:982)
>   at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:974)
>   at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:876)
>   at java.lang.Thread.run(Thread.java:636)
> Caused by: java.lang.IllegalArgumentException: object is not an instance of
> declaring class
>   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>   at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>   at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>   at java.lang.reflect.Method.invoke(Method.java:616)
>   at
> org.apache.camel.component.bean.BeanInvocation.invoke(BeanInvocation.java:80)
>   ... 11 more
>
> What I am doing wrong here?
>
> Thanks in advance - Claus
>



--
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus