You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Ujeen <uj...@ujeen.com> on 2012/03/16 07:37:01 UTC

CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Hi colleagues,

I'm trying to use csv marshalling and faced the following issue
cvc-complex-type.3.2.2: Attribute 'AutogenColumns' is not allowed to appear
in element 'csv'
This happens when I try to switch off the autogen columns feature:
<camel:csv autogenColumns="false"/>

It looks like the issue is nested in the
http://camel.apache.org/schema/spring/camel-spring-2.9.0.xsd (2.9.1 as well)
schema. 
The <xs:complexType name="csvDataFormat"> type just doesn't describe the
autogenColumns attribute.
Could you please take a look is that a reason of the error message I get?

Thank you
P.S. And one more important thing - thank you for your brilliant Camel. Now
I can't even imagine how would I live without it :)


--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5570066.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Posted by Ujeen <uj...@ujeen.com>.
Ok, it looks like I managed to fix it (this flag works when marshalling only) 
I changed the org.apache.camel.dataformat.csv.CsvDataFormat.
1. Removed the if(autogenColumns) condition in the doMarhshalRecord. So now
it looks like this:
private void doMarshalRecord(Exchange exchange, Map row, Writer out,
CSVWriter csv) throws Exception {
	Set set = row.keySet();
	updateFieldsInConfig(set, exchange);
	csv.writeRecord(row);
}
2. put the following snipped into the marshal method making it the very
first there
public void marshal(Exchange exchange, Object object, OutputStream
outputStream) throws Exception {
     if(!autogenColumns) {
	config = new CSVConfig();
     }
      ....

So it works for me but I didn't run any tests (don't have time to perform
all the checks atm)

--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5571741.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Posted by Ujeen <uj...@ujeen.com>.
Thank you, Babak! This is great improvement I'll give it a try! 
(in meanwhile I did some "dirty hack" in the CsvDataFormat class which
solves my particular problem and put it locally into my classpath as
workaround)


--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5574757.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

O.K. I did log a second JIRA for this as well [1] to provide the same power
of expression inside the XML DSL as well as in Java.

@Ujeen
Now in addition to the new 'autogenColumns' option there're also both the
'configRef' as well as the 'strategyRef' options you can make use of. Take a
look at XML DSL [2] as well as the corresponding unit test [3].

This will be part of the upcomming 2.9.2 and 2.10.0 releases.

[1] https://issues.apache.org/jira/browse/CAMEL-5105
[2]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-csv/src/test/resources/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest-context.xml
[3]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest.java

Babak

--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5574290.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Posted by Babak Vahdat <ba...@swissonline.ch>.
That's indeed true. If we provide a new option for autogenColumns then we
should additionally provide some ways of specifying CSVConfig or CSVField
inside XML DSL to be considered as well. Also note that autogenColumns
default value is true.

@Claus, As you see by [1] the best we get out of the new
autogenColumns="false" is just a bunch of line feed characters as no new
column gets added any more!

As now the autogenColumns has been already provided we should also provide a
way inside XML DSL so that the user can specify which columns should be
added. Maybe through CSVFieldRefs (Refs to XML Beans), list of Strings, etc.
which we would then add to CsvDataFormat's CSVConfig.

What do you think?

[1]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvMarshalAutogenColumnsSpringTest.java

Babak

--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5572575.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Posted by Ujeen <uj...@ujeen.com>.
Thank you very much for this hint. Yeah I figured that out. 
And therefore it looks like reporting above is pointless as it doesn't make
sense to bring the autogenColumns flag into the xml because there is no way
to set all the fields inside the <cvs/> tag 


--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5572111.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi

If you want to make use of AutogenColumns == false you should first
explicitly specify the columns you're interested in otherwise nothing will
be appended into the output other than "\n"s. See the test method
testPresetConfig() by [1] to see how to correctly specify the columns
beforehand.

Also note that the *order* of the output values will be the same as the
*order* you do "addField(CSVField)" by "CSVConfig".

[1]
https://svn.apache.org/repos/asf/camel/trunk/components/camel-csv/src/test/java/org/apache/camel/dataformat/csv/CsvRouteTest.java

Babak

--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5571945.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

Posted by Ujeen <uj...@ujeen.com>.
Thank you, but you know it looks like the entire autogenColumns feature
doesn't work. 
At least it doesn't work for me (the 2.9.0-RC1 version)
I change the scheme so the org.apache.camel.dataformat.csv.CsvDataFormat
accepts it but if I set autogenColumns flag to false it stops generating
everything.
I'm still struggling with this atm, digging the Camel sources and
apache.common.csv. I hope to fix it by passing some proper Config. The trick
is that I don't know what properties to put there as there is lack
documentation on that :)

My initial task was to print out three different tables with data to the
same csv file so user could open in in Excel and see them as three separate
and not related peace of data. 
That autogenColumns flag corrupts the entire idea as it adds ton of empty
lines here and there. In theory the flag promises to stop messing the data
:)

--
View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5571650.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: CSV dateformat bug? Attribute 'AutogenColumns' is not allowed to appear in element 'camel:csv'

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

Thanks for reporting. I have logged a JIRA
https://issues.apache.org/jira/browse/CAMEL-5100


On Fri, Mar 16, 2012 at 7:37 AM, Ujeen <uj...@ujeen.com> wrote:
> Hi colleagues,
>
> I'm trying to use csv marshalling and faced the following issue
> cvc-complex-type.3.2.2: Attribute 'AutogenColumns' is not allowed to appear
> in element 'csv'
> This happens when I try to switch off the autogen columns feature:
> <camel:csv autogenColumns="false"/>
>
> It looks like the issue is nested in the
> http://camel.apache.org/schema/spring/camel-spring-2.9.0.xsd (2.9.1 as well)
> schema.
> The <xs:complexType name="csvDataFormat"> type just doesn't describe the
> autogenColumns attribute.
> Could you please take a look is that a reason of the error message I get?
>
> Thank you
> P.S. And one more important thing - thank you for your brilliant Camel. Now
> I can't even imagine how would I live without it :)
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/CSV-dateformat-bug-Attribute-AutogenColumns-is-not-allowed-to-appear-in-element-camel-csv-tp5570066p5570066.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
CamelOne 2012 Conference, May 15-16, 2012: http://camelone.com
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/