Lucifer
Lucifer

Reputation: 842

Getting Filename without extension : camel

I have header with filename with extension like this

<setHeader> <simple>Test.txt</simple> </setHeader>

I need to fetch only filename ie. Test alone in another header. Can anyone help me to achieve this.

Thanks.

Upvotes: 0

Views: 514

Answers (1)

burki
burki

Reputation: 7005

You have multiple options. The examples take the full filename from a header and write the filename without extension into another header.

You write a Java Bean to use full Java power (for example Apache Commons FilenameUtils.getBaseName) and call it from your route. See this Camel documentation how to inject header values into your bean methods. In the route you call the bean like this

.setHeader("filename", method(beanReference, "methodName"))

Or you add camel-groovy to your dependencies to get more scripting power than with Camel Simple. Then you can do it directly in the Camel route

setHeader("filename").groovy("request.headers.get('fullFilename')
    .take(request.headers.get('fullFilename').lastIndexOf('.'))")

Upvotes: 1

Related Questions