According to the test example SpringConsumerTemplateTest and doc page,
here is how I have configured spring / bean

Bean

public class ReportingConsumer {
        
        @Autowired
        private ConsumerTemplate consumer;
        
        @EndpointInject(name = "queueReportingEndpoint")
        private Endpoint endpoint;

        ...
        List<Map<String, Object>> received = new ArrayList<Map<String,
Object>>();
        received = consumer.receiveBody(endpoint, List.class);

Spring

        <camel:camelContext id="Reporting" trace="true"
xmlns="http://camel.apache.org/schema/osgi";>
                
           <!-- define a consumer template -->
           <camel:consumerTemplate id="consumer"/>



Unfortunately, NPE is generated at the line : received =
consumer.receiveBody(endpoint, List.class);

I suppose that consumerTemplate has not been initialized. So I don't
undertsand why the unit test work and not when we work with a POJO.




Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer

*****************************
blog : http://cmoulliard.blogspot.com



On Mon, Sep 21, 2009 at 4:26 PM, Claus Ibsen <[email protected]> wrote:
> Hi
>
> Yeah use the spring / JSR standard annotations for that @Service or
> whatever it was called
> And then you can refer to the consumer template from the camel context
>
> <camelContext ...>
>  <consumerTemplate id="myFoo"/>
> <..>
>
> @Service or whatever its named ("myFoo")
> ConsumerTemplate consumer;
>
>
> On Mon, Sep 21, 2009 at 4:22 PM, Charles Moulliard <[email protected]> 
> wrote:
>> Concerning the point 2)
>>
>> it does not work too with this syntax :
>>
>>       �...@endpointinject()
>>        private ConsumerTemplate consumer;
>>
>>       �...@endpointinject(name = "queueReportingEndpoint")
>>        private Endpoint endpoint;
>>
>>
>> the following error is generated :
>>
>> 16:16:33,796 | ERROR | xtenderThread-56 | ContextLoaderListener
>>    | BundleApplicationContextListener   50 | Application context
>> refresh failed 
>> (OsgiBundleXmlApplicationContext(bundle=com.xpectis.x3s.x3s-core,
>> config=osgibundle:/META-INF/spring/*.xml))
>> org.springframework.beans.factory.BeanCreationException: Error
>> creating bean with name 'reportingConsumer' defined in URL
>> [bundle://208.0:0/META-INF/spring/core-reporting.xml]: Initialization
>> of bean failed; nested exception is
>> java.lang.IllegalArgumentException: registry entry called consumer of
>> type org.apache.camel.Endpoint must be specified
>>        at 
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
>>        at 
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
>>        at java.security.AccessController.doPrivileged(Native Method)
>>        at 
>> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
>>        at 
>> org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
>>        at 
>> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
>>        at 
>> org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
>>        at 
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
>>        at 
>> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
>>        at 
>> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
>>        at 
>> org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
>>        at 
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)
>>        at 
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)
>>        at 
>> org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
>>        at 
>> org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)
>>        at 
>> org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:136)
>>        at java.lang.Thread.run(Thread.java:595)
>> Caused by: java.lang.IllegalArgumentException: registry entry called
>> consumer of type org.apache.camel.Endpoint must be specified
>>        at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:242)
>>        at 
>> org.apache.camel.util.CamelContextHelper.mandatoryLookup(CamelContextHelper.java:168)
>>        at 
>> org.apache.camel.util.CamelContextHelper.getEndpointInjection(CamelContextHelper.java:213)
>>        at 
>> org.apache.camel.impl.CamelPostProcessorHelper.getEndpointInjection(CamelPostProcessorHelper.java:121)
>>        at 
>> org.apache.camel.impl.CamelPostProcessorHelper.getInjectionValue(CamelPostProcessorHelper.java:131)
>>        at 
>> org.apache.camel.spring.CamelBeanPostProcessor.injectField(CamelBeanPostProcessor.java:215)
>>        at 
>> org.apache.camel.spring.CamelBeanPostProcessor$2.doWith(CamelBeanPostProcessor.java:203)
>>        at 
>> org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:523)
>>        at 
>> org.springframework.util.ReflectionUtils.doWithFields(ReflectionUtils.java:500)
>>        at 
>> org.apache.camel.spring.CamelBeanPostProcessor.injectFields(CamelBeanPostProcessor.java:199)
>>        at 
>> org.apache.camel.spring.CamelBeanPostProcessor.postProcessBeforeInitialization(CamelBeanPostProcessor.java:91)
>>
>> -2€/paypall account
>>
>>
>> Charles Moulliard
>> Senior Enterprise Architect
>> Apache Camel Committer
>>
>> *****************************
>> blog : http://cmoulliard.blogspot.com
>>
>>
>>
>> On Mon, Sep 21, 2009 at 3:54 PM, Claus Ibsen <[email protected]> wrote:
>>> On Mon, Sep 21, 2009 at 3:46 PM, Charles Moulliard <[email protected]> 
>>> wrote:
>>>> It works now except that I have the following error (btw, the objects
>>>> posted in the JMS queue are serializable) .
>>>>
>>>> CaughtExceptionType:java.io.NotSerializableException,
>>>> CaughtExceptionMessage:org.apache.camel.component.jms.JmsQueueEndpoint,
>>>> StackTrace:java.io.NotSerializableException:
>>>> org.apache.camel.component.jms.JmsQueueEndpoint
>>>>        at 
>>>> java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
>>>>        at 
>>>> java.io.ObjectOutputStream.writeArray(ObjectOutputStream.java:1251)
>>>>        at 
>>>> java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
>>>>        at 
>>>> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
>>>>        at 
>>>> org.apache.camel.component.bean.BeanInvocation.writeExternal(BeanInvocation.java:104)
>>>>        at 
>>>> java.io.ObjectOutputStream.writeExternalData(ObjectOutputStream.java:1310)
>>>>        at 
>>>> java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1288)
>>>>        at 
>>>> java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079)
>>>>        at 
>>>> java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
>>>>        at 
>>>> org.apache.activemq.command.ActiveMQObjectMessage.storeContent(ActiveMQObjectMessage.java:98)
>>>>
>>>> Why do we have to inject two times the reference of the uri, this is
>>>> not so very logic   ?
>>>
>>> You do not need to.
>>>
>>>>
>>>>       �...@endpointinject(name = "queueReportingEndpoint")
>>>>        private ConsumerTemplate consumer;
>>>>
>>>>       �...@endpointinject(name = "queueReportingEndpoint")
>>>>        private Endpoint endpoint;
>>>>
>>>
>>> You can do this in a single line
>>>
>>>       �...@endpointinject(name = "queueReportingEndpoint")
>>>        private ConsumerTemplate consumer;
>>>
>>> And then just as it then knows which endpoint to consume from as you
>>> specified it in the annotation
>>> Exchange e = consumer.receive();
>>>
>>> 2)
>>> But if you want to have Endpoint and ConsumerTemplate then you can do
>>>
>>>       �...@endpointinject()
>>>        private ConsumerTemplate consumer;
>>>
>>>       �...@endpointinject(name = "queueReportingEndpoint")
>>>        private Endpoint endpoint;
>>>
>>> But then you need to tell the consumer template which endpoint to use
>>> Exchange e = consumer.receive(endpoint);
>>>
>>>
>>> Deposit 5$ to my pay pall account for support :)
>>>
>>>
>>>
>>>> Regards,
>>>>
>>>> Charles Moulliard
>>>> Senior Enterprise Architect
>>>> Apache Camel Committer
>>>>
>>>> *****************************
>>>> blog : http://cmoulliard.blogspot.com
>>>>
>>>>
>>>>
>>>> On Mon, Sep 21, 2009 at 3:14 PM, Claus Ibsen <[email protected]> wrote:
>>>>> Charles you do post your problems to soon.
>>>>>
>>>>> The NPE is of course because ConsumerTemplate is never initialized.
>>>>>
>>>>> Just add @EndpointInject to it as well
>>>>>
>>>>> @EndpointInject
>>>>> private ConsumerTemplate consumer;
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Sep 21, 2009 at 3:06 PM, Charles Moulliard <[email protected]> 
>>>>> wrote:
>>>>>> There is something strange. I receive a NPE exception at the line
>>>>>> where I create an exchange from consumer :
>>>>>>
>>>>>>       �...@endpointinject(name = "queueReportingEndpoint")
>>>>>>        private Endpoint endpoint;
>>>>>>
>>>>>>        private ConsumerTemplate consumer;
>>>>>>
>>>>>>        public List<Map<String, Object>> collectMessages() {
>>>>>>
>>>>>>        Log.info("Endpoint : " + endpoint.getEndpointUri());
>>>>>>
>>>>>>        Exchange exch = consumer.receive(endpoint);
>>>>>>
>>>>>> If I call directly consumer.receiveBody(endpoint, List.class); I have
>>>>>> the same error. I tough that the problem come from the endpoint
>>>>>> injection, but I have also a NPE if I use the uri of the endpoint in
>>>>>> the receiveBody method
>>>>>>
>>>>>> Here is the trace :
>>>>>>
>>>>>> Time=Mon Sep 21 15:00:00 CEST 2009, calendar=null,
>>>>>> previousFireTime=Mon Sep 21 14:58:00 CEST 2009,
>>>>>> CamelBeanMethodName=null}, BodyType:org.quartz.JobDetail,
>>>>>> Body:JobDetail 
>>>>>> 'DEFAULT.quartz://x3sReporting/clientError?cron=0+0%2F2+9-18+%3F+*+MON-FRI':
>>>>>>  jobClass: 'org.apache.camel.component.quartz.CamelJob isStateful:
>>>>>> false isVolatile: false isDurable: false requestsRecovers: false
>>>>>> 15:00:00,000 | INFO  | heduler_Worker-2 | x3s
>>>>>>    | rg.apache.camel.processor.Logger   88 | Exchange[
>>>>>> , BodyType:org.quartz.JobDetail
>>>>>> , Body:JobDetail
>>>>>> 'DEFAULT.quartz://x3sReporting/clientError?cron=0+0%2F2+9-18+%3F+*+MON-FRI':
>>>>>>  jobClass: 'org.apache.camel.component.quartz.CamelJob isStateful:
>>>>>> false isVolatile: false isDurable: false requestsRecovers: false
>>>>>> , CaughtExceptionType:java.lang.NullPointerException,
>>>>>> CaughtExceptionMessage:null, StackTrace:java.lang.NullPointerException
>>>>>>        at 
>>>>>> com.xpectis.x3s.core.util.ReportingConsumer.collectMessages(ReportingConsumer.java:27)
>>>>>>
>>>>>>
>>>>>> Charles Moulliard
>>>>>> Senior Enterprise Architect
>>>>>> Apache Camel Committer
>>>>>>
>>>>>> *****************************
>>>>>> blog : http://cmoulliard.blogspot.com
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Mon, Sep 21, 2009 at 2:12 PM, Claus Ibsen <[email protected]> 
>>>>>> wrote:
>>>>>>> On Mon, Sep 21, 2009 at 2:05 PM, Charles Moulliard 
>>>>>>> <[email protected]> wrote:
>>>>>>>> @EndpointInject(uri="") only accepts as parameter an uri / name or
>>>>>>>> context but not a reference to a spring bean
>>>>>>>>
>>>>>>>
>>>>>>> Its the name attribute that is the ref, maybe we should rename it :)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>> Charles Moulliard
>>>>>>>> Senior Enterprise Architect
>>>>>>>> Apache Camel Committer
>>>>>>>>
>>>>>>>> *****************************
>>>>>>>> blog : http://cmoulliard.blogspot.com
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On Mon, Sep 21, 2009 at 1:59 PM, Claus Ibsen <[email protected]> 
>>>>>>>> wrote:
>>>>>>>>> On Mon, Sep 21, 2009 at 1:55 PM, Charles Moulliard 
>>>>>>>>> <[email protected]> wrote:
>>>>>>>>>> Sorry for my mistake.
>>>>>>>>>>
>>>>>>>>>> I have used @consume because it was possible to pass as a parameter
>>>>>>>>>> the name of the endpoint to consume. Is there a way to do this with a
>>>>>>>>>> consumer template ?
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> You can IoC the endpoint in the bean
>>>>>>>>>
>>>>>>>>> @EndpointInjected(ref = "foo")
>>>>>>>>> private Endpoint foo;
>>>>>>>>>
>>>>>>>>> but I would assume consumer template also works like producer 
>>>>>>>>> template with IoC
>>>>>>>>> ( if not we should add it)
>>>>>>>>>
>>>>>>>>> @EndpointInjected(ref = "foo")
>>>>>>>>> private ConsumerTemplate consumer;
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> See more
>>>>>>>>> http://camel.apache.org/bean-injection.html
>>>>>>>>>
>>>>>>>>>> regards,
>>>>>>>>>>
>>>>>>>>>> Charles Moulliard
>>>>>>>>>> Senior Enterprise Architect
>>>>>>>>>> Apache Camel Committer
>>>>>>>>>>
>>>>>>>>>> *****************************
>>>>>>>>>> blog : http://cmoulliard.blogspot.com
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Mon, Sep 21, 2009 at 1:50 PM, Claus Ibsen <[email protected]> 
>>>>>>>>>> wrote:
>>>>>>>>>>> On Mon, Sep 21, 2009 at 1:46 PM, Charles Moulliard 
>>>>>>>>>>> <[email protected]> wrote:
>>>>>>>>>>>> The POJO defined in the following route consumes immediately 
>>>>>>>>>>>> messages
>>>>>>>>>>>> posted on a queue and in consequence is not triggered by the Quartz
>>>>>>>>>>>> timer
>>>>>>>>>>>>
>>>>>>>>>>>>                        <camel:from 
>>>>>>>>>>>> uri="quartz://x3sReporting/clientError?cron=0+0/5+9-18+?+*+MON-FRI"/>
>>>>>>>>>>>>                                <camel:doTry>
>>>>>>>>>>>>                                    <camel:bean 
>>>>>>>>>>>> ref="reportingConsumer" method="collectMessages"/>
>>>>>>>>>>>>                                    ...
>>>>>>>>>>>>
>>>>>>>>>>>> public class ReportingConsumer {
>>>>>>>>>>>>
>>>>>>>>>>>>   �...@consume(ref = "queueReportingEndpoint") // = x3s:report 
>>>>>>>>>>>> queue
>>>>>>>>>>>>        public List<Map<String, Object>> 
>>>>>>>>>>>> collectMessages(List<Map<String,
>>>>>>>>>>>> Object>> received) {
>>>>>>>>>>>>
>>>>>>>>>>>>        List<Map<String, Object>> result = new 
>>>>>>>>>>>> ArrayList<Map<String, Object>>();
>>>>>>>>>>>>
>>>>>>>>>>>>                if (received != null) {
>>>>>>>>>>>>
>>>>>>>>>>>>                        Log.info("Received exchange : " + 
>>>>>>>>>>>> received.size());
>>>>>>>>>>>>                        for(Map<String, Object> model : received) {
>>>>>>>>>>>>
>>>>>>>>>>>>                                Log.info("Map received : " + 
>>>>>>>>>>>> model.toString());
>>>>>>>>>>>>                                // Add model received into the 
>>>>>>>>>>>> result output list
>>>>>>>>>>>>                                result.add( model );
>>>>>>>>>>>>                        }
>>>>>>>>>>>>                }
>>>>>>>>>>>>
>>>>>>>>>>>>                return result;
>>>>>>>>>>>>        }
>>>>>>>>>>>>
>>>>>>>>>>>> Question : How can I avoid that the bean consumes immediately 
>>>>>>>>>>>> messages
>>>>>>>>>>>> from the queue and wait quartz triggering ?
>>>>>>>>>>>
>>>>>>>>>>> You cannot as @Consume(ref = "queueReportingEndpoint") has 
>>>>>>>>>>> ABSOLUTELY
>>>>>>>>>>> nothing to do with quartz.
>>>>>>>>>>> It creates a new event driven consumer which listen on new messages
>>>>>>>>>>> arriving on that JMS queue.
>>>>>>>>>>>
>>>>>>>>>>> You can remove the @Consume and then let quartz invoke it from the 
>>>>>>>>>>> Camel route.
>>>>>>>>>>>
>>>>>>>>>>> And then you can in your bean use a consumer template to read 
>>>>>>>>>>> messages
>>>>>>>>>>> from the JMS queue.
>>>>>>>>>>> Now you bean is only invoked when quartz triggers.
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> Charles Moulliard
>>>>>>>>>>>> Senior Enterprise Architect
>>>>>>>>>>>> Apache Camel Committer
>>>>>>>>>>>>
>>>>>>>>>>>> *****************************
>>>>>>>>>>>> blog : http://cmoulliard.blogspot.com
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> --
>>>>>>>>>>> Claus Ibsen
>>>>>>>>>>> Apache Camel Committer
>>>>>>>>>>>
>>>>>>>>>>> Open Source Integration: http://fusesource.com
>>>>>>>>>>> Blog: http://davsclaus.blogspot.com/
>>>>>>>>>>> Twitter: http://twitter.com/davsclaus
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> --
>>>>>>>>> Claus Ibsen
>>>>>>>>> Apache Camel Committer
>>>>>>>>>
>>>>>>>>> Open Source Integration: http://fusesource.com
>>>>>>>>> Blog: http://davsclaus.blogspot.com/
>>>>>>>>> Twitter: http://twitter.com/davsclaus
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --
>>>>>>> Claus Ibsen
>>>>>>> Apache Camel Committer
>>>>>>>
>>>>>>> Open Source Integration: http://fusesource.com
>>>>>>> Blog: http://davsclaus.blogspot.com/
>>>>>>> Twitter: http://twitter.com/davsclaus
>>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Claus Ibsen
>>>>> Apache Camel Committer
>>>>>
>>>>> Open Source Integration: http://fusesource.com
>>>>> Blog: http://davsclaus.blogspot.com/
>>>>> Twitter: http://twitter.com/davsclaus
>>>>>
>>>>
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> Apache Camel Committer
>>>
>>> Open Source Integration: http://fusesource.com
>>> Blog: http://davsclaus.blogspot.com/
>>> Twitter: http://twitter.com/davsclaus
>>>
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>

Reply via email to