简体   繁体   中英

Camel split CSV file on regex

I am working on one case where I have csv file with below data

100| Some Delimited Data
200| Some Delimited Data
100| Some Delimited Data
400| Some Delimited Data
400| Some Delimited Data
200| Some Delimited Data

I am trying to make camel route where

when 100
  marshal csv & send to Bean
when 200
  marshal csv & send to bean

I am trying to route it with camel. Example when I do in XML I can parse XML in route

I cannot use Camel-Bindy as I don't have fixed delimiters in row

example

Row 1 can have 10 '|' (pipes / delimiter)
Row 2 can have 20 '|' (pipes / delimiter)
Row 3 can have 16 '|' (pipes / delimiter)

They are variable in length which I have handled in bean. Is there any way where I can parse or use any regex?

Since you are always using | as a delimiter, you can use the default CSV support to load the content as a list of lists, then split the body to get each row as a list and then process that list (row) in your bean:

<unmarshal>
    <csv delimiter="|"/>
</unmarshal>
<split>
    <simple>${body}</simple> <!-- Body will be a list of lists -->
    <choice>
        <when>
            <simple>${body[0]} == '100'</simple>
            <to uri="bean:processor100"/>
        </when>         
        <when>
            <simple>${body[0]} == '200'</simple>
            <to uri="bean:processor200"/>
        </when>
    </choice>
</split>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM