I'm trying to embed a literal CDATA value in a Mulesoft flow and cannot figure out how to do so.
My desired output (in an HTTP request body) is:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<query xmlns="http://autotask.net/ATWS/v1_5/">
<sXML>
<![CDATA[<queryxml><entity>ticket</entity><query><condition><field>id<expression op="equals">12345</expression></field></condition></query></queryxml>]]>
</sXML>
</query>
</soap:Body>
</soap:Envelope>
My Dataweave transformation looks as follows:
%dw 1.0
%output application/xml
%namespace soap http://schemas.xmlsoap.org/soap/envelope
---
{
soap#Envelope #(version: "1.0") : {
soap#Header: {},
soap#Body: {
query: {
sXML: "<queryxml><entity>ticket</entity><query><condition><field>id<expression op=\"equals\">12345</expression></field></condition></query></queryxml>"
}
}
}
}
But when I send this request to requestb.in (to inspect the contents), I can see it's coming through like this (focus on the sXML entity):
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope" version="1.0">
<soap:Header/>
<soap:Body>
<query>
<sXML><queryxml><entity>ticket</entity><query><condition><field>id<expression op="equals">12345</expression></field></condition></query></queryxml></sXML>
</query>
</soap:Body>
</soap:Envelope>
How can I get a literal CDATA value in there via dataweave / MEL?
Thank you.
I would try:
sXML: "<queryxml> .... </queryxml>" as :cdata
See https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-formats#custom-types-2 for more information.
handleInteractiveOrder:
write(vars.subm.soap#Envelope.soap#Body.cp#handleInteractiveOrder,"application/xml")
as CData
in mule 4 we can do like this. I kept my XML in subm variable.
Related
I'm trying to create an order & an address on Xentral using POSTMAN service. I'm using AddresseCreate, AuftragCreate APIs. But when I tried to create an Address, it is giving 200 OK status, but an empty address is generating.
I'm hitting this URL: https://my_domain.xentral.biz/index.php?module=api&action=AdresseCreate&hash=**********&api_id=1
Request Body ->>
<?xml version="1.0" encoding="UTF-8"?>
<request>
<status>
<function>AdresseCreate</function>
</status>
<xml>
<name>somename</name>
<land>USA</land>
<strasse>new york 5</strasse>
<hausnummer>49</hausnummer>
<typ>co</typ>
<sprache>english</sprache>
<plz>22041</plz>
<ort>new york</ort>
<telefon>0821123456789</telefon>
<telefax>0821123456790</telefax>
<email>somename#name.com</email>
<projekt>SHOPIFY.USA</projekt>
<anrede>firma</anrede>
<firma>company</firma>
<vorname>LB</vorname>
<kundennummer>NEW</kundennummer>
<lieferantennummer>NEW</lieferantennummer>
</xml>
</request>
Response Body -->
<?xml version="1.0" encoding="UTF-8"?>
<response>
<status>
<action>AdresseCreate</action>
<message>OK</message>
<messageCode>1</messageCode>
</status>
<xml>
<id>5487</id>
<kundennummer></kundennummer>
</xml>
</response>
Can Anyone tell me what I'm doing wrong? Or is this some fault from Xentral's side?
When I print response of the SOAP which has CDATA, it contains gt and lt as shown bellow. Can you please help to convert this to proper xml or can you help me to validate some of the value of the response.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:processRequestResponse xmlns:ns="http://controller.core.xxx.xxxxx.xxxx.xxxxxx.com">
<return><?xml version="1.0" encoding="UTF-8"?>
<xxx:xxxxxxxxxxxx xmlns:xxx="http://xxxxx.com/xxxx/xxxx/xxx/response/xyz/abc">
<Header><destinationId>ABC</destinationId>
..............
..............
...............
</Body>
</xxx:xxxxxxxxxxxxxResponse></return>
</ns:processRequestResponse>
</soapenv:Body>
</soapenv:Envelope>
I think one line will do the trick for you, try this:
* xml temp = $response//return
Please tell me how to integrate TCS Api in Odoo . I have some nominal code but i don't know this is a APi or not . If this is a Api then please tell me how i use this Code
The following is a sample SOAP 1.1 request and response. The placeholders shown need to be replaced with actual values.
POST /Service1.asmx HTTP/1.1
Host: 202.61.51.93
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://202.61.51.93:6265/GetAllCountries"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetAllCountries xmlns="http://202.61.51.93:6265/" />
</soap:Body>
</soap:Envelope>
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<GetAllCountriesResponse xmlns="http://202.61.51.93:6265/">
<GetAllCountriesResult>xmlxml</GetAllCountriesResult>
</GetAllCountriesResponse>
</soap:Body>
</soap:Envelope>
I am facing one issue while xml format conversion in mule transform message.
I am having one input xml file.
and I have to convert the input xml to output xml where the node structure is different and node names are different.
I used data transform message for this conversion, But at one point, it is showing expected format is object and found string.
Can any one please help me for the same.
"Type mismatch
found :name, :string
required :name, :object (com.mulesoft.weave.mule.exception.WeaveExecutionException). Message payload is of type: WeaveMessageProcessor$WeaveOutputHandler"
input payload
<?xml version="1.0" encoding="utf-8"?>
<AGREEMENT>
<details>
<newTransaction>N</newTransaction>
<type>ddd</type>
</details>
</AGREEMENT>
output Payload
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<TestHeader xmlns="TestWebService">
<Username>aaa</Username>
<Password>aaa</Password>
</TestHeader>
</soap:Header>
<soap:Body>
<AGRMNT>
<testId>
<_-Test_Agrmnt- SEGMENT="1">
<transaction>N</transaction>
</__-Test_Agrmnt->
</testId>
</AGRMNT>
</soap:Body>
</soap:Envelope>
DataWeave code
%dw 1.0
%output application/xml
%namespace soap http://schemas.xmlsoap.org/soap/envelope/
{
soap#Envelope: {
soap#Body: {
AGREEMENT: {
testId: {
'_-Test_Agrmnt-': {
transaction: payload.AGREEMENT.details.newTransaction as :string
}
}
}
}}
I have got following output with your input and script
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AGREEMENT>
<testId>
<_-Test_Agrmnt->
<transaction>N</transaction>
</_-Test_Agrmnt->
</testId>
</AGREEMENT>
</soap:Body>
</soap:Envelope>
The only change is adding --- in script
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace soap http://schemas.xmlsoap.org/soap/envelope/
---
{
soap#Envelope: {
soap#Body: {
AGREEMENT: {
testId: {
'_-Test_Agrmnt-': {
transaction: payload.AGREEMENT.details.newTransaction as :string
}
}
}
}}}]]>
</dw:set-payload>
</dw:transform-message>
I'm trying to do some calls to webservices, but when I change the method the sessionId is different from the last method called. So I want to hold the session. I've tried many ways with no result. I am almost sure that I have to pass the session in SoapHeader method, like this:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://xxx">
<soap:Header>
<SessionHeader xmlns='http://xxx'>
<sessionId>jsessionid=ABCDEFGHI:-1</sessionId>
</SessionHeader>
</soap:Header>
With no Result...
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p118:method1:p118="http://xxx">
In the second method, the sessionId is a new session:
<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<p118:method2 xmlns:p118="http://xxx">
How can i do this? Thank you very much!