Please find my request having tag <Date xsi:nil="true"/> when it crosses the Multipart/form-data dataweave it is removing the xsi:nil="true part which is not expected in my scenario. I wanted that to be out as the same.
Also it is removing the namespace which is not the expected case. If i trying declaring ns xsi http://www.w3.org/2001/XMLSchema-instance in the first dataweave. In the response root element it is prefixing xsi:Locations.
Im struggling with this.
Wanted the response as mentioned below, whatever the input is same should come out without altering.
Using writeNilOnNull=true is putting nill on all the fields which i dont want either, wanted only for date.
Could anyone help on this. Thank you.
Input:
<Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Location>
<Id>2</Id>
<CarId>78</CarId>
<Packages>1</Packages>
<Date xsi:nil="true"/>
</Location>
</Locations>
Expected Response:
<Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Location>
<Id>2</Id>
<CarId>78</CarId>
<Packages/>
<Date xsi:nil="true"/>
</Location>
</Locations>
Flow:
<flow name="question" doc:id="8c836a85-9d0a-47a8-8e5a-f670b16f91eb" >
<http:listener doc:name="Listener" doc:id="52ffdb08-9587-4cb2-8232-9467e85ea0dc" config-ref="HTTP_Listener_config" path="/question"/>
<ee:transform doc:name="Transform Message" doc:id="da995adf-196b-4c7b-a265-874f059ed1bb" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>
<ee:transform doc:name="Transform Message" doc:id="75e5d876-855e-4d38-8468-3484c859f36e" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output multipart/form-data
---
{
"parts": {
"file": {
"headers": {
"Content-Disposition": {
"name": "file",
"filename": "",
"subtype": "form-data"
},
"Content-Type": "application/xml"
},
"content": payload
}
}
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
Add writeNilOnNull=true on your transformation. Like this
%dw 2.0
var x=read('<Locations xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Location>
<Id>2</Id>
<CarId>78</CarId>
<Packages>1</Packages>
<Date xsi:nil="true"/>
</Location>
</Locations>','application/xml')
output application/xml writeNilOnNull=true
---
x
Related
I am trying to set the payload with a soap envelope, header, and body.
then substring payload by payload.indexOf("?>")+2
Based on the following expression:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://decisionresearch.com/RateMaker">
<soapenv:Header/>
<soapenv:Body>
#[payload.substring(payload.indexOf("?>")+2)]
</soapenv:Body>
</soapenv:Envelope>
Input Request: https://github.com/Manikandan99/Map_request/blob/main/Request_map.xml
Expected output: https://github.com/Manikandan99/Map_request/blob/main/Response_map.xml
Mule FLow:
<flow name="map_requestFlow" doc:id="21d0d652-3766-47ed-95aa-a451f62c5776" >
<http:listener doc:name="Listener" doc:id="7312114b-2857-40b3-98cd-f52b628b3a28" config-ref="HTTP_Listener_config" path="/map"/>
<ee:transform doc:name="Transform Message" doc:id="7f061325-473b-4f63-8e95-990827b03259" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/xml
---
payload]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="21051f39-bb9f-412c-af73-f65051317757" message="#[payload]"/>
<set-payload value='#[<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns0="http://decisionresearch.com/RateMaker">
<soapenv:Header/>
<soapenv:Body>
#[payload.substring(payload.indexOf("?>")+2)]
</soapenv:Body>
</soapenv:Envelope>]' doc:name="Set Payload" doc:id="faf2bc3b-e7a3-4708-910b-daeb05bb5f6e" />
</flow>
Error message : https://github.com/Manikandan99/Map_request/blob/main/Error.txt
How to encapsulate soap with current payload?
That's wrong because of several reasons. First you can not use an expression inside an expression. Second you are trying to generate XML with strings, when DataWeave already does generates valid XML. Using strings directly is very very error prone. Whenever you see string manipulation to generate or parse XML, you should be questioning the reason.
Instead use DataWeave to generate the XML completely in a simple transform:
%dw 2.0
output application/xml
ns soapenv http://schemas.xmlsoap.org/soap/envelope/
---
{
soapenv#Envelop: {
soapenv#Header: null,
soapenv#Body: payload
}
}
Output (assuming the input has format application/xml):
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelop xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<ns0:rate xmlns:ns0="http://decisionresearch.com/RateMaker">
<ns0:BrokerData>
<ns0:taxa>TOPA/CISG01/ALL</ns0:taxa>
<ns0:effectiveMode>effective</ns0:effectiveMode>
<ns0:requestDate>20190101</ns0:requestDate>
<ns0:function>rate</ns0:function>
</ns0:BrokerData>
<ns0:RateRequest>
<ns0:Policy>
<PolType>CNPK</PolType>
<ClassCode>CANDIS</ClassCode>
<Zip>80003</Zip>
<State>CO</State>
<EffDate>20211117</EffDate>
<ExpDate>20221117</ExpDate>
<Payroll>1200</Payroll>
<OHPayroll/>
<WAPayroll/>
<FTE>5</FTE>
<OccAgg>1000000/2000000</OccAgg>
<DmgPrem>500000</DmgPrem>
<MedPay>10000</MedPay>
<EmpBen>Yes</EmpBen>
<StopGap>None</StopGap>
<OHStopGap>None</OHStopGap>
<WAStopGap>None</WAStopGap>
<HNO>1000000</HNO>
<AssBat>100000/200000</AssBat>
<PerLocAgg>Yes</PerLocAgg>
<NumLoc>1</NumLoc>
<WSUB>0</WSUB>
<PICO>No</PICO>
<AIML>0</AIML>
<AIVS>0</AIVS>
<AIPA>0</AIPA>
<AIMA>0</AIMA>
<AILL>0</AILL>
<LLEA>0</LLEA>
<AIDP>0</AIDP>
<BAIV>No</BAIV>
<WACombo>No</WACombo>
<IRPMGL>2</IRPMGL>
<LPDPGL>1.00</LPDPGL>
</ns0:Policy>
<ns0:Location>
<LocationRef>Location-465697646-800339871</LocationRef>
<State>CO</State>
<Zip>80003</Zip>
</ns0:Location>
<ns0:Class>
<Id>Risk-1296379588-1802098261</Id>
<Number>1</Number>
<ClassCode>CANDIS</ClassCode>
<Exposure>2000000</Exposure>
<GLBR>25</GLBR>
<IsPrimary>Yes</IsPrimary>
</ns0:Class>
</ns0:RateRequest>
</ns0:rate>
</soapenv:Body>
</soapenv:Envelop>
Basically i have a curl command (which uploads a file to an API)which i want to execute this curl command through mule.I am reading the file from read connector. Then using multipart/form data to convert curl command.and then passing it to the HTTP requestor.
BUt while running the application. The API returns the error as 'Input file is missing'.
error message
* - - + APPLICATION + - - * - - + DOMAIN + - - * - - + STATUS + - - *
*******************************************************************************************************
* mule_mediaupload * default * DEPLOYED *
*******************************************************************************************************
INFO 2020-05-25 19:56:16,835 [[MuleRuntime].io.04: [mule_mediaupload].so-file-http-request-sendFlow.BLOCKING #9753a94] [event: b17cd1f0-9e93-11ea-95ae-681401007098] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: Provider Name Date
Planetearth,2015-05-01
RockMusic,2017-09-01
INFO 2020-05-25 19:56:17,082 [[MuleRuntime].cpuIntensive.01: [mule_mediaupload].so-file-http-request-sendFlow.CPU_INTENSIVE #1fea2bb] [event: b17cd1f0-9e93-11ea-95ae-681401007098] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: ------=_Part_2583_1939156918.1590416776933
Content-Type: text/plain
Content-Disposition: form-data; name="params"
{Type:Import}
------=_Part_2583_1939156918.1590416776933--
INFO 2020-05-25 19:56:20,781 [[MuleRuntime].cpuLight.02: [mule_mediaupload].so-file-http-request-sendFlow.CPU_LITE #15368f21] [event: b17cd1f0-9e93-11ea-95ae-681401007098] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: {
"success" : false,
"processId" : "CA410762B598945B",
"reasons" : [ {
"code" : 57040122,
"message" : "Input file is missing."
} ]
}
below is the XML
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<file:config name="File_Config" doc:name="File Config" doc:id="0272f407-da7b-46e7-a0e1-8f4edda4e3f9" >
<file:connection workingDir="C:\Files\" />
</file:config>
<http:request-config name="HTTP_Request_configuration" doc:name="HTTP Request configuration" doc:id="00b795c8-285e-445c-9bb0-8001f2ffdaf8" />
<http:request-connection protocol="HTTPS" host=" http://mysuperserver/" />
</http:request-config>
<flow name="so-file-http-request-sendFlow">
<scheduler doc:name="Scheduler" doc:id="d6b797dd-7f26-41eb-8bb9-74456a4606fc" >
<scheduling-strategy >
<fixed-frequency frequency="1" timeUnit="DAYS"/>
</scheduling-strategy>
</scheduler>
<file:read doc:name="Read" config-ref="File_Config" path="medialist.csv"/>
<logger level="INFO" doc:name="Logger" doc:id="2c9bb06a-e935-4469-8282-cef67adc5926" message="#[payload]"/>
<ee:transform doc:name="Transform Message" doc:id="7cc45c6a-9326-49de-bea1-d4c9a29a6b26">
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output multipart/form-data
---
{
parts : {
params : {
headers : {
"Content-Type": "text/plain"
},
content : "{actionType:Import}"
},
file : {
headers : {
"Content-Disposition" : {
"name": "file",
"filename": ",medialist.csv"
},
"Content-Type" : "application/csv"
}
}
}
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="c5a60159-e14f-436b-8952-efabc3bc07ac" message="#[payload]"/>
<http:request method="POST" doc:name="Request" config-ref="HTTP_Request_configuration1" path="/media/upload/" doc:id="79ccd374-155d-40ca-b848-7e766337f5d3">
<http:headers ><![CDATA[#[output application/java
---
{
Accept : "application/json",
apiAccessKeyId : "username,
apiSecretAccessKey : "Password"
}]]]></http:headers>
</http:request>
<logger level="INFO" doc:name="Logger" doc:id="f2f8ffc4-3520-42d8-bca8-d45100adb144" message="#[payload]"/>
</flow>
</mule>
You are missing the content definition on the file part. Try this:
<ee:transform doc:name="Transform Message" doc:id="7cc45c6a-9326-49de-bea1-d4c9a29a6b26">
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output multipart/form-data
---
{
parts : {
params : {
headers : {
"Content-Type": "text/plain"
},
content : "{actionType:Import}"
},
file : {
headers : {
"Content-Disposition" : {
"name": "file",
"filename": "medialist.csv"
},
"Content-Type" : "application/csv"
},
content: payload
}
}
}]]></ee:set-payload>
</ee:message>
</ee:transform>
I already read the documentation about the new way to create soap web service using newest mule (https://docs.mulesoft.com/apikit/4.x/apikit-4-soap-prerequisites-task), but it doesn't really help.
Because I try to do following, using that tutorial as example, when user enter the name, the size, the email and send the request in OrderTshirt function, my flow will call method in a java class, probably int OrderTShirt.order(String input) where input concat all the name, size, and email information, and return back the orderId, and submit back to the response to user. How I can approach this?
Here is the code that what I have right now, but I don't know how to use that datawave component really well, can someone give me an example for that?
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mule xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:apikit-soap="http://www.mulesoft.org/schema/mule/apikit-soap" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/apikit-soap http://www.mulesoft.org/schema/mule/apikit-soap/current/mule-apikit-soap.xsd http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<http:listener-config name="api-httpListenerConfig">
<http:listener-connection host="0.0.0.0" port="9999"/>
</http:listener-config>
<apikit-soap:config name="soapkit-config" port="TshirtServicePort" service="TshirtService" wsdlLocation="Tshirt2.wsdl"/>
<flow name="api-main">
<http:listener config-ref="api-httpListenerConfig" path="/TshirtService/TshirtServicePort">
<http:response>
<http:body>#[payload]</http:body>
<http:headers>#[attributes.protocolHeaders default {}]</http:headers>
</http:response>
<http:error-response>
<http:body>#[payload]</http:body>
<http:headers>#[attributes.protocolHeaders default {}]</http:headers>
</http:error-response>
</http:listener>
<apikit-soap:router config-ref="soapkit-config">
<apikit-soap:message>#[payload]</apikit-soap:message>
<apikit-soap:attributes>#[
%dw 2.0
output application/java
---
{
headers: attributes.headers,
method: attributes.method,
queryString: attributes.queryString
}]</apikit-soap:attributes>
</apikit-soap:router>
</flow>
<flow name="OrderTshirt:\soapkit-config" doc:id="969489c2-709c-43b7-915c-cc92d9f3c8c9">
<ee:transform doc:name="Transform Message" doc:id="5771f4b9-0060-4658-aa8a-fee10efc02c5" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/java
ns ns0 http://schemas.xmlsoap.org/soap/envelope
---
{
body:{
ns0#orderTshirtResponse:{
orderId:"10"
}
} write "application/xml"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
<flow name="ListInventory:\soapkit-config">
<ee:transform doc:id="431ad9c7-f0bf-4b32-88bc-bbe8c6815317">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
ns soap http://schemas.xmlsoap.org/soap/envelope
---
{
body: {
soap#Fault: {
faultcode: "soap:Server",
faultstring: "Operation [ListInventory:\soapkit-config] not implemented"
}
} write "application/xml"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
<flow name="TrackOrder:\soapkit-config">
<ee:transform doc:id="a09a0cc3-f28a-49aa-bb32-77368340a522">
<ee:message>
<ee:set-payload><![CDATA[%dw 2.0
output application/java
ns soap http://schemas.xmlsoap.org/soap/envelope
---
{
body: {
soap#Fault: {
faultcode: "soap:Server",
faultstring: "Operation [TrackOrder:\soapkit-config] not implemented"
}
} write "application/xml"
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
I am trying to pass the http header value as the web service consumer,
httpHeader
I use this property as web service input,
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 namespace
---
{
ns0#GetProject: {
ns0#projectId: inboundProperties."http.query.params".projectId,
ns0#upi: inboundProperties.sm_user
}
}]]></dw:set-payload>
</dw:transform-message>
I have also tried setting the sm_user to a variable and trying to access the variable in TransformMessage as below, but the same error,
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 namespace
---
{
ns0#GetProject: {
ns0#projectId: inboundProperties."http.query.params".projectId,
ns0#upi: flowVars.setUPI
}
}]]></dw:set-payload>
</dw:transform-message>
Error:
Server was unable to read request. ---> There is an error in XML document (3, 32). ---> Input string was not in a correct format.. Message payload is of type: ElementNSImpl
Transform XML using the SM_USER header:
<?xml version='1.0' encoding='windows-1252'?>
<ns0:GetProject xmlns:ns0="namespace">
<ns0:projectId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<ns0:upi xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</ns0:GetProject>
Flow XML:
<flow name="ProjectEC">
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace ns0 namespace
---
{
ns0#GetProject: {
ns0#projectId: inboundProperties."http.query.params".projectId ,
ns0#upi: inboundProperties.SM_USER
}
}]]></dw:set-payload>
</dw:transform-message>
<ws:consumer config-ref="ECDataService_Consumer" operation="GetProject" doc:name="ECWebServiceConsumer"/>
<mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
<set-variable variableName="extractJsondata" value="#[json:GetProjectResponse/GetProjectResult]" mimeType="application/json" doc:name="Variable"/>
<set-payload value="#[flowVars.extractJsondata]" doc:name="Set Payload"/>
<json:xml-to-json-transformer doc:name="XML to JSON"/>
</flow>
Can someone tell me if I am missing something.
Thanks
Few checks
Check whether your xml is the exact format which your webservice is really looking for. or
Change the encoding from encoding='windows-1252' to UTF-8. Follow the url Output Encoding issue in mule esb. or
As trial and error version directly use the xml in postman to hit webservice ( without making dataweave to do the transformation). or
Make sure you have no space <?xml version='1.0' encoding="UTF-8"?> before starting of xml greater sysmbol tag.
Check the above 4 steps anyone of this might cause issue. Step 3 will be helpful for testing.
I have a response xml as below which comes from web service consumer. I want to extract the Response node, into a variable and use it in another sub-flow (Transform message input to add cdata tag to it). The request part of the response xml will be used in the same flow for some transformations using dataweave. The variable is empty when retrieved with xpath (#[xpath3('//GetTransactionResponse/GetTransactionResult/Response')]), since its a node with xml struture in it. Highly appreciate any solution with this please.
<?xml version="1.0" encoding="UTF-8"?>
<GetTransactionResponse xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<GetTransactionResult>
<Request>
<Security>
<SystemUsername>53A5949A</SystemUsername>
<SystemPassword/>
<SystemID/>
</Security>
</Request>
<Response>
<Scheme>
<Ins>
<InsReference>200</InsReference>
<InsNumber>200</InsNumber>
<InsName/>
</Ins>
</Scheme>
</Response>
</GetTransactionResult>
</GetTransactionResponse>
Thank you for your time!
The other way to get response in variable by using additional target in your dataweave. And use following script
%dw 1.0
%output application/xml
---
Response : payload.GetTransactionResponse.GetTransactionResult.Response
Your XML contains is not a valid XML as it's starting and end tags doesn't match... example :-
<InsReference>200</InsurerReference>
<InsNumber>200</InsurerNumber>
However, if you make the expression will work as follows #[xpath3('/GetTransactionResponse/GetTransactionResult/Response')]
You can transform the response to json and set variables via json expression.
<flow name="xmlparserFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/xml" allowedMethods="POST" doc:name="HTTP"/>
<dw:transform-message metadata:id="864f45d9-f193-4e82-8f9f-f689a2e13450" doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%var response=payload.GetTransactionResponse.GetTransactionResult.Response.Scheme.Ins
%output application/json
---
{
reference: response.InsReference,
number: response.InsNumber,
name: response.InsName
}]]></dw:set-payload>
</dw:transform-message>
<set-variable variableName="reference" value="#[json:reference]" doc:name="Set Variable"/>
<logger message="#[message]" level="INFO" doc:name="Logger"/>
<object-to-string-transformer doc:name="Object to String"/>
</flow>
hope this helps.
I was able to achieve finally by setting the Response and Request variables in the dataweave as below:
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
---
payload]]></dw:set-payload>
<dw:set-variable variableName="Request"><![CDATA[%dw 1.0
%output application/xml
---
{
Request: payload.GetTransactionResponse.GetTransactionResult.Request
}]]></dw:set-variable>
<dw:set-variable variableName="Response"><![CDATA[%dw 1.0
%output application/xml
---
{
Response: payload.GetTransactionResponse.GetTransactionResult.Response
}]]></dw:set-variable>
</dw:transform-message>
Appreciate all for your time.Thanks!