Substring inside xpath for header value in Apache Camel / Spring DSL

I have a thread like this and my problem is that I am getting the wrong value in the second header:

                           <when>                       
                           <xpath>//kred:assigment_GetRq/nrb</xpath>
                            <setHeader headerName="nrbPE">
                                <xpath resultType="java.lang.String">//kred:assigment_GetRq/nrb/text()</xpath>
                            </setHeader>
                            <setHeader headerName="subNrbPE">
                                <xpath resultType="java.lang.String">substring(${headers.nrbPE}, 3, 6)</xpath>
                            </setHeader>
                            <setHeader headerName="kod">
                                <simple>${properties:apiEsb.assigment.bpCode}</simple>
                            </setHeader>
                            <log loggingLevel="INFO" message="header nrb: ${headers.nrbPE}"/>
                            <log loggingLevel="INFO" message="header subNrb: ${headers.subNrbPE}"/>
                            <log loggingLevel="INFO" message="Property: ${headers.kod}"/>
                            <choice>
                                <when>
                                    <xpath>${headers.subNrbPE} = ${headers.kod}</xpath>
                                    <process ref="createDetailSectionProc" />
                                </when>
                                <otherwise>
                                    <log loggingLevel="INFO" message="otherwise"/>
                                </otherwise>
                                </choice>
                            </when> 

      

Logs:

08:26:47,067 | INFO  | Esb| Assigment_Get    |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | header nrb: 99999999
08:26:47,067 | INFO  | Esb| Assigfment_Get    |  | 68 - org.apache.camel.camel-core - 2.6.0.fuse-03-01 | header subNrb: ass ja

      

I don't understand what is wrong with the syntax because the second value should be 9999, but I can see what the substring does (java class ...) Could you tell me where I went wrong? I need to compare this substring value with the property value in some boolean expression in Camel.

+3


source to share


1 answer


You must use the syntax below:

<setHeader headerName="subNrbPE">
   <xpath resultType="java.lang.String">substring($in:nrbPE, 3, 4)</xpath>
</setHeader>

      

because XPath substring takes

fn: substring (sourceString, startLoc, length)



So, if you want to have 4 digits, you need to specify the starting position (3) and the number of characters you want (4).

Also the comparison should be changed to:

<simple>${headers.subNrbPE} == ${headers.kod}</simple>

      

+4


source







All Articles