You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by gargankur007 <ga...@gmail.com> on 2015/04/06 23:23:00 UTC

BeanIODataFormat giving exception in OSGI compliant Karaf Server Camel

I am using CAmel for one of my projects.The bundles are deployed in OSGI. I
have a usecase in which I would need to unmarshal a CSV to POJO. I am using
BeanIODataFormat for that.

Somehow I am bale to unmarshal the same in Camel Main Program but when I put
the same piece of code in OSGI I get following exception

"stackTrace=java.lang.NullPointerException at
org.apache.camel.dataformat.beanio.BeanIODataFormat.readModels(BeanIODataFormat.java:142)
at
org.apache.camel.dataformat.beanio.BeanIODataFormat.unmarshal(BeanIODataFormat.java:110)
at
com.hcentive.wig.wem.route.UnmarshallerRouteBuilder$2.process(UnmarshallerRouteBuilder.java:85)
at
org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) at
org.apache.camel.processor.Pipeline.process(Pipeline.java:80) at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
at
org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
at
org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)
at
org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)
at
org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)
at
org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)
at
org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)
at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
at
org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
at
org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1101)"



--
View this message in context: http://camel.465427.n5.nabble.com/BeanIODataFormat-giving-exception-in-OSGI-compliant-Karaf-Server-Camel-tp5765404.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: BeanIODataFormat giving exception in OSGI compliant Karaf Server Camel

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

Yeah but then you would need to use a content based router to route to
appropiate data format.

You may get it working inside the processor if you call .start on the
data format before using it. And also remember to call
.setCamelContext on it to do the initialization manually.

And then call .stop after usage.

On Wed, Apr 8, 2015 at 11:11 AM, gargankur007 <ga...@gmail.com> wrote:
> Hi Claus
>
> Is it possible if I can define the formats as Spring beans and then
> depending upon headers use a particular format to cater/handle the CSV
> payload
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/BeanIODataFormat-giving-exception-in-OSGI-compliant-Karaf-Server-Camel-tp5765404p5765474.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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/

Re: BeanIODataFormat giving exception in OSGI compliant Karaf Server Camel

Posted by gargankur007 <ga...@gmail.com>.
Hi Claus

Is it possible if I can define the formats as Spring beans and then
depending upon headers use a particular format to cater/handle the CSV
payload



--
View this message in context: http://camel.465427.n5.nabble.com/BeanIODataFormat-giving-exception-in-OSGI-compliant-Karaf-Server-Camel-tp5765404p5765474.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: BeanIODataFormat giving exception in OSGI compliant Karaf Server Camel

Posted by Claus Ibsen <cl...@gmail.com>.
Use the data format outside the processor, so it properly gets
initialized. It would need this to work in osgi with classloading
http://camel.apache.org/data-format.html



On Tue, Apr 7, 2015 at 6:41 PM, gargankur007 <ga...@gmail.com> wrote:
> Hi Claus
>
> Thanks for your interest.
> Use case is "Can we use a beaniodataformat depending upon the exchange
> filetype or file extension?"
>
> Eg
> from("file://filPath")
>                                                 // do a little logging
>
>                                                 // aggregate based on header correlation key
>                                                 // use class MyAggregationStrategy for aggregation
>                                                 // and complete when we have aggregated 14 messages
>                                                 .process(new Processor() {
>
>                                                         @Override
>                                                         public void process(Exchange exchange) throws Exception {
>
>                                                                 System.out.println("B3");
>                                                                 final DataFormat language = new BeanIODataFormat("CSVMappings.xml",
> "languageFile");
>                                                                 System.out.println("B2"
>                                                                                 + language.unmarshal(exchange,
> exchange.getIn().getBody(InputStream.class)));
>
>                                                         }
>                                                 })
>
> The above code does not work and throws runtime exceptions.
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/BeanIODataFormat-giving-exception-in-OSGI-compliant-Karaf-Server-Camel-tp5765404p5765442.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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/

Re: BeanIODataFormat giving exception in OSGI compliant Karaf Server Camel

Posted by gargankur007 <ga...@gmail.com>.
Hi Claus

Thanks for your interest.
Use case is "Can we use a beaniodataformat depending upon the exchange
filetype or file extension?"

Eg
from("file://filPath")
						// do a little logging

						// aggregate based on header correlation key
						// use class MyAggregationStrategy for aggregation
						// and complete when we have aggregated 14 messages
						.process(new Processor() {

							@Override
							public void process(Exchange exchange) throws Exception {

								System.out.println("B3");
								final DataFormat language = new BeanIODataFormat("CSVMappings.xml",
"languageFile");
								System.out.println("B2"
										+ language.unmarshal(exchange,
exchange.getIn().getBody(InputStream.class))); 

							}
						})

The above code does not work and throws runtime exceptions.



--
View this message in context: http://camel.465427.n5.nabble.com/BeanIODataFormat-giving-exception-in-OSGI-compliant-Karaf-Server-Camel-tp5765404p5765442.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: BeanIODataFormat giving exception in OSGI compliant Karaf Server Camel

Posted by gargankur007 <ga...@gmail.com>.
We are using Spring to wire beans



--
View this message in context: http://camel.465427.n5.nabble.com/BeanIODataFormat-giving-exception-in-OSGI-compliant-Karaf-Server-Camel-tp5765404p5765425.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: BeanIODataFormat giving exception in OSGI compliant Karaf Server Camel

Posted by Claus Ibsen <cl...@gmail.com>.
What versions of the software are you using? And are you using spring
or blueprint?

On Mon, Apr 6, 2015 at 11:23 PM, gargankur007 <ga...@gmail.com> wrote:
> I am using CAmel for one of my projects.The bundles are deployed in OSGI. I
> have a usecase in which I would need to unmarshal a CSV to POJO. I am using
> BeanIODataFormat for that.
>
> Somehow I am bale to unmarshal the same in Camel Main Program but when I put
> the same piece of code in OSGI I get following exception
>
> "stackTrace=java.lang.NullPointerException at
> org.apache.camel.dataformat.beanio.BeanIODataFormat.readModels(BeanIODataFormat.java:142)
> at
> org.apache.camel.dataformat.beanio.BeanIODataFormat.unmarshal(BeanIODataFormat.java:110)
> at
> com.hcentive.wig.wem.route.UnmarshallerRouteBuilder$2.process(UnmarshallerRouteBuilder.java:85)
> at
> org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63)
> at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
> at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
> at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
> at org.apache.camel.processor.Pipeline.process(Pipeline.java:118) at
> org.apache.camel.processor.Pipeline.process(Pipeline.java:80) at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
> at
> org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)
> at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)
> at
> org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103)
> at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562)
> at
> org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500)
> at
> org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468)
> at
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325)
> at
> org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263)
> at
> org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1101)"
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/BeanIODataFormat-giving-exception-in-OSGI-compliant-Karaf-Server-Camel-tp5765404.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
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/