Search code examples
apache-camelfuseesbjbossfuse

How to use the excludePattern in camel for the remove headers?


I tried to work with the camel's remove header which works for some and does not work for other patterns

It works for the below patterns

<removeHeaders pattern="*" />
<removeHeaders pattern="CamelFile*" />

It does not work for

<removeHeaders pattern="*File*" />

Is the above expected?

Also in the exclude pattern I observe that the wildcard patterns * is not recognised at all.

        <setHeader headerName="firstCustomHeader">
            <constant>firstCustomHeader</constant>
        </setHeader>
        <setHeader headerName="secondCustomHeader">
            <constant>secondCustomHeader</constant>
        </setHeader>
        <setHeader headerName="thirdCustomHeader">
            <constant>thirdCustomHeader</constant>
        </setHeader>
        <setHeader headerName="fourthCustomHeader">
            <constant>fourthCustomHeader</constant>
        </setHeader>

         <removeHeaders pattern="*" excludePattern="fourth*|third*" />

the above removes all the header but does excludes the excludePattern value

How do I achieve the relevant above mentioned pattern?

Camel Version 2.13.1


Solution

  • Yes either use a regular expression or use a single * in the end as wildcard. So *File* is not valid, as it has two *, and therefore Camel assumes its a regular expression.

    So you should do a regular expression

    pattern=".*File.*"
    

    Where as if you have only one * its a shorthand for matching wildcards, but the * must be only once and at the end of the line, such as

    pattern="File*"
    

    The syntax is documented here