Search code examples
citrus-framework

How to send complex message headers using citrus test frame work


As of now according to the information mentioned in the citrus documentation we can send header using element tag .I have a header like this

<usr><scenarioname>xx</scenarionname><instanceID>xx<<instanceID><usr>  

I am sending the above header using follwing send action

   <send endpoint="helloServiceEndpoint">
        <message>
            <payload>
                <TestMessage>
                    <Text>Hello!</Text>
                </TestMessage>
            </payload>
        </message>
        <header>
            <element name="scenarioname" value="xx"/>
        <element name="instanceID" value="xx"/>
        </header>
    </receive>

But I want to post a complex header which not just like name value pairs but the header contains nested xml elements. how can i achieve this using citrus

example of complex header

     <usr>
<scenarioname>xx</scenarionname>
<instanceID>xx<<instanceID>
<parameters>
<basicauthentication>
<username>xxxxx</username>
<password>xxxx</password>
</basicauthentication>
.
.
.
.
.

</parameters>
</usr>

Solution

  • The element is for name-value pairs only. You need to use the data element in the header section in order to add a complex header fragment.

    <send endpoint="helloServiceEndpoint">
        <message>
          <payload>
            <TestMessage>
                <Text>Hello!</Text>
            </TestMessage>
          </payload>
        </message>
        <header>
          <data>
            <![CDATA[
            <usr>
              <scenarioname>xx</scenarionname>
              <instanceID>xx</instanceID>
            </usr>  
            ]]>
          </data>
        </header>
      </send>