3

I've flow like this and my problem is that I'm getting the wrong value on 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 syntax cause the second value should be 9999, but I see that substring is making on (class java...) Could you tell me where I made a mistake? I need to compare this substring value with property value in some logic statement in Camel.

1 Answer 1

5

You should use below syntax:

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

because XPath substring takes

fn:substring(sourceString, startingLoc, length)

So if you want to have 4 digits, you need to specify starting position (3) and how many chars you want (4).

Also comparison should be changed to:

<simple>${headers.subNrbPE} == ${headers.kod}</simple>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.