Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDATA in payload factory in WSO2 ESB

I am trying to write a sequence in ESB and populate my payload data by using payload factory as i stated below example.

  <payloadFactory>
     <format>
        <p:echoInt xmlns:p="http://echo.services.core.carbon.wso2.org">
           <in xmlns="">$1</in>
        </p:echoInt>
     </format>
     <args>
        <arg xmlns:ns="http://org.apache.synapse/xsd" expression="an-xml-formatted-string"/>
     </args>
  </payloadFactory>
 <send>
     <endpoint>
        <address uri="http://noon101:8280/services/echo" format="soap11"/>
     </endpoint>
  </send>

Because my string is formatted as xml when i send this payload to the service, the service tries to parse my xml parameter and (i do not understand what is the exact reason) my web service method is not called. in this link it says that if i use cdata than the parser will not parse my xml formatted string and there will be no problem.

But the problem is Payload Factory mediator do not accept Cdata in its content. When i write the configuration of Payload Factory as indicated below, it deletes CDATA keywords from it and problem consists.

  <payloadFactory>
     <format>
        <p:echoInt xmlns:p="http://echo.services.core.carbon.wso2.org">
           <in xmlns=""> <![CDATA[ $1 ]]> </in>
        </p:echoInt>
     </format>
     <args>
        <arg xmlns:ns="http://org.apache.synapse/xsd" expression="an-xml-formatted-string"/>
     </args>
  </payloadFactory>

What would be the solution to this problem? Any other mediator to set payload or any workaround will be appreciated.

like image 496
Alper Avatar asked Jan 13 '23 07:01

Alper


1 Answers

You can use CDATA inside payload factory mediator. The only thing you need to do is, you need to store the format in registry and use it from there. Registry Resource

Following is a sample. In this sample, I am using the response of my previous call as the input for the message I am preparing with payload factory mediator.

     <property xmlns:ns="http://org.apache.synapse/xsd"
               name="ALLRESULTS"
               expression="$body/child::*[fn:position()=1]"
               scope="default"
               type="STRING"/>

     <payloadFactory media-type="xml">
        <format key="conf:/repository/esb/myPF"/>
        <args>
           <arg evaluator="xml" expression="$ctx:ALLRESULTS"/>
           <arg value="1"/>
        </args>
     </payloadFactory>

The content of the registry resource is as follows.

                       <ns:testMethod xmlns:ns="http://example.com">
                            <xs:xmlBody xmlns:xs="http://example.com"><![CDATA[$1]]></xs:xmlBody>
                            <xs:sessionId xmlns:xs="http://example.com">$2</xs:sessionId>
                        </ns:testMethod>

With this way, you can use CDATA inside payload factory mediator.

like image 178
Shammi Jayasinghe Avatar answered Jan 16 '23 19:01

Shammi Jayasinghe