Camel 2.10.0 and Bindy/CSV

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

Camel 2.10.0 and Bindy/CSV

Reynald
Hi all,

I'm starting to use Camel and I'm trying to use Bindy to read a CSV File. I'm getting the error:

java.lang.IllegalArgumentException: The separator has not been defined in the annotation @CsvRecord or not instantiated during initModel. must be specified
        at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:290)
        at org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat.unmarshal(BindyCsvDataFormat.java:124)
        at org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:57)

Here is a very simple test:

            from("direct:start").marshal().bindy(BindyType.Csv, "services.billing").to("direct:middle");
            from("direct:middle").unmarshal(new BindyCsvDataFormat("services.billing.MyBillingItem")).to("direct:test");

And to test, something like this:

                MyBillingItem bill = new MyBillingItem();
                CamelContext ctx = CamelPlugin.getCamelContext();
                bill.id= 1;
                bill.number = "1234;
                ctx.createProducerTemplate().sendBody("direct:start", bill);

On MyBillingItem.class, I have set the annotations:

...
@CsvRecord(separator = ",", quote = "\"", skipFirstLine = true)
public class MyBillingItem {
...

If I'm doing something wrong, please advice.

Thanks

PS. I need to use 2.10.0 because of some features.
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Reynald
I tested this code on 2.9.2 and it does not work either.
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Charles Moulliard
Hi Reynald,

Your syntax is not correct as you must provide the package name (that bindy will scan) and not the name of the class

from("direct:middle").unmarshal(new BindyCsvDataFormat("services.billing.MyBillingItem")).to("direct:test");

should be

from("direct:middle").unmarshal(new BindyCsvDataFormat("services.billing")).to("direct:test");

Regards,
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Claus Ibsen-2
In Camel 2.10 you can provide the class itself which makes it a tad easier

 from("direct:middle")
 .unmarshal(new BindyCsvDataFormat(MyBillingItem.class))
 .to("direct:test");

And there is bindy in the DSL, so you can do

 from("direct:middle")
   .unmarshal().bindy(BindyType.Csv, MyBillingItem.class)
 .to("direct:test");

On Tue, Jul 3, 2012 at 10:04 AM, Charles Moulliard <[hidden email]> wrote:

> Hi Reynald,
>
> Your syntax is not correct as you must provide the package name (that bindy
> will scan) and not the name of the class
>
> from("direct:middle").unmarshal(new
> BindyCsvDataFormat("services.billing.MyBillingItem")).to("direct:test");
>
> should be
>
> from("direct:middle").unmarshal(new
> BindyCsvDataFormat("services.billing")).to("direct:test");
>
> Regards,
>
>
> -----
> Apache Committer / Sr. Pr. Consultant at FuseSource.com
> Email: [hidden email]
> Twitter : @cmoulliard, @fusenews
> Blog : http://cmoulliard.blogspot.com
> --
> View this message in context: http://camel.465427.n5.nabble.com/Camel-2-10-0-and-Bindy-CSV-tp5715387p5715395.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
FuseSource
Email: [hidden email]
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Reynald
I could make it work with this:

from("direct:start").unmarshal().bindy(BindyType.Csv, "services.billing").to("direct:test");

Somehow all the other combinations generated nullpointerexceptions.

Thanks!!!

PS. Camel is fantastic! It spare us days of programming and testing only with this feature and this is just the beginning :).
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Christian Mueller
Administrator
Could you please raise a JIRA for the case you got a NPE!?

Best,
Christian

Sent from a mobile device
Am 03.07.2012 17:33 schrieb "Reynald" <[hidden email]>:

> I could make it work with this:
>
> from("direct:start").unmarshal().bindy(BindyType.Csv,
> "services.billing").to("direct:test");
>
> Somehow all the other combinations generated nullpointerexceptions.
>
> Thanks!!!
>
> PS. Camel is fantastic! It spare us days of programming and testing only
> with this feature and this is just the beginning :).
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-2-10-0-and-Bindy-CSV-tp5715387p5715410.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Charles Moulliard
In reply to this post by Reynald
Reynald,

When you would like to use directly the Class instead of providing the package to be used
the syntax is  --> bindy(BindyType.Csv, services.billing.class). So the quotes should be removed and class added at the end.

Regards,


Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Charles Moulliard
In reply to this post by Christian Mueller
There is no bug. See my last response. Nevertheless, I will add unit test (CAMEL-5421)
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Email: [hidden email]
Twitter : @cmoulliard, @fusenews
Blog : http://cmoulliard.blogspot.com
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Reynald
In reply to this post by Christian Mueller
Hi Chris,

Sorry for the delay.

I just created:

https://issues.apache.org/jira/browse/CAMEL-5423

If you need anything else, let me know.

tks.
Reply | Threaded
Open this post in threaded view
|

Re: Camel 2.10.0 and Bindy/CSV

Christian Mueller
Administrator
Ok, thanks.
One of the committers (may be me) will have a look on it.

Best,
Christian

On Thu, Jul 5, 2012 at 9:05 PM, Reynald <[hidden email]> wrote:

> Hi Chris,
>
> Sorry for the delay.
>
> I just created:
>
> https://issues.apache.org/jira/browse/CAMEL-5423
>
> If you need anything else, let me know.
>
> tks.
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Camel-2-10-0-and-Bindy-CSV-tp5715387p5715565.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>