camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ravi Gupta 7 <rgupt...@sapient.com>
Subject RE: CSV Parsing
Date Thu, 11 Sep 2014 06:37:18 GMT
You can try using 
<unmarshal>
<bindy packages="org.fusesource.camel" type="Csv" />.
</unmarshal>

Thanks 
RG
-----Original Message-----
From: Claus Ibsen [mailto:claus.ibsen@gmail.com] 
Sent: Thursday, September 11, 2014 11:10 AM
To: users@camel.apache.org
Subject: Re: CSV Parsing

Hi

You can also use the splitter eip

On Thu, Sep 11, 2014 at 1:44 AM, Matt Raible <matt@raibledesigns.com> wrote:
> I have a String that's delimited by ~. This string is returned from a
> database query. I'm able to parse it with the following code in my route:
>
> @Override
> public void configure() throws Exception {
> CsvDataFormat csv = new CsvDataFormat();
> csv.setDelimiter("~");
>                 ...
>
> .to("bean:myStoredProcedure")
>
> .process(myJdbcProcessor)
>
> .unmarshal(csv)
>
> .process(mySearchCsvProcessor)
>
> Today, I encountered a use case where not one string would be returned, but
> multiple strings. To handle this, I've changed myJdbcProcessor to have the
> following:
>
>
> List<String> results = jdbcTemplate.queryForList("...", String.class);
>
> if (results.size() == 1) {
> exchange.getIn().setBody(results.get(0), String.class);
> } else {
> exchange.getIn().setBody(results, List.class);
> }
>
> When the result size is 1, everything works as expected. However, when
> there are multiple results, the csv unmarshal blows up with the following
> error:
>
> org.apache.camel.InvalidPayloadException: No body available of type:
> java.io.InputStream
>
> Is it possible to parse multiple lines with unmarshal(csv)?
>
> I tried the following, but that didn't work b/c it only gets the first line:
>
> exchange.getIn().setBody(StringUtils.collectionToCommaDelimitedString(results),
> String.class);
>
>
> Thanks,
>
> Matt



-- 
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/
Mime
View raw message