Hi,

I try to figure out How we can share together util function with Camel that
we can use from DSL language (Spring, Java, ...).

Here is an example : For my project, I need to extract from CamelFileName
header property the last occurence of the folder (= parent folder) from the
file path. To get this information, I have created a bean = function

 public String getFolderName(@Header(value = "CamelFileParent") String
camelFileName, @Body File file) {

        LinkedList<String> folders = new LinkedList<String>();
        String parentFolder = "";

        if ( camelFileName != null ) {
            // Split path

folders.addAll(Arrays.asList(camelFileName.split(file.separator)));

            if ( folders != null ) {
            // Get last occurrence containing the parent folder
                parentFolder = folders.getLast();
            }
        }
        return parentFolder;
    }

>From my route, I will call it to get the folderName like this

<from uri=""/>
<bean name="UtilHelper" method="getFolderName" />
<to uri=""/>

Proposition

(1) What I propose is to have an UtilHelper class in Camel that every user
can have access to use methods that we share together ?

(2) It should be interesting that we can call this bean within setHeader
function like this

                <camel:setHeader headerName="messageType">
                    <camel:bean name="ServiceHelper"
method="getParentFolderName"/>
                </camel:setHeader>

Regards,

Charles Moulliard
Senior Enterprise Architect
Apache Camel Committer

*****************************
blog : http://cmoulliard.blogspot.com

Reply via email to