0
votes

I want to modify file with groovy using:

 <from uri="file:/data/inbox?delete=true" />
    <transform>
    <groovy>
        body =  body[1..3]
    </groovy>
    </transform>
<to uri="file:/data/outbox"/>

I get an error:

groovy.lang.MissingMethodException: No signature of method: org.apache.camel.component.file.GenericFile.getAt() is applicable for argument types: (groovy.lang.IntRange) values: [1..3]

What am I doing wrong?

1
The body variable you receiving is a GenericFile which does not contain a getAt method. What are you trying to do? - Namphibian
What do you want to do with this body = body[1..3] ? In this case the original body is a GenericFile instance but the groovy script body[1..3] tries to invoke its getAt() method with an unsupported IntRange argument. - Tadayoshi Sato

1 Answers

1
votes

Yes the input is file based and you attempt to use a groovy function that works on a list to grab the 1st to 3rd elements. You cannot do that. If you want to grab only the first 3 lines of a file, then you need to convert the message first to a list etc, or use the splitter eip to split the file line by line and group them together in a list which you can then afterwards do the groovy script