Unknown Payload in transform message Anypoint Studio - mule

I have a problem with transform message. I need to recieve messages in SOAP/WSDL sistem. In my case i have this structure for process the responses.
This is my flow and in trnasform message component i have this problem:
Y put credentials in transform message but if i see the web service component, say that payload is unknown.
The problem is the sem for two transform message. I don't know how can i do to put the credentials good for doing a reception message aplication with SOAP/WSDL sistem.
Thanks for help.

Please try to log the payload as [message.payloadAs(java.lang.String)]
If you can see the actual payload in XML or JSON format whatever you are POSTing, then extract the specific elements.
If your GET then in query params retrieve them using [message.inboundProperties.'httpqueryparams']
Extract the specfic elements into flowvars and set them to Webservice consumer add [flowVars.userid] and [flowVars.pwd]
That will echo back as response.
I hope this is going to help.

Bit of a guess here because you haven't shown exactly what your WSDL is expecting:
I think you may want a transform a bit like this
%dw 1.0
%output application/xml encoding="UTF-8"
---
{
gdspHeader #(xmlns: "http://ws.gdsp.vf.gdspcustomer.com/" ) :{
gsdpCredentials: {
password: "Mule",
userId: "Monty"
}
}
}
Which transforms to
<?xml version='1.0' encoding='UTF-8'?>
<gdspHeader xmlns="http://ws.gdsp.vf.gdspcustomer.com/">
<gsdpCredentials>
<password>Mule</password>
<userId>Monty</userId>
</gsdpCredentials>
</gdspHeader>

Related

Mule 4.4 convert Binary payload into JSON

So I have gone through a number of questions related to this topic and tried the various options but none of them seem to work .
Environment - Mule runtime 4.4 , Anypoint Studio 7.11.1
Our limitation is we are not using Enterprise edition only community edition
So cannot use Transform component . However can use dataweave in setPayload / set Variable
I am receiving payload as Binary : see below :
Data appears as JSON but is Binary
I tried changing to JSON in 'setPayload' :
%dw 2.0
import * from dw::core::Binaries
output application/json
---
fromBase64(payload)
However I get this exception :
""Unexpected character 'ÿ' at payload#[1:30] (line:column), expected
Expecting end of input but got `ÿ, while reading `payload` as Json.
1| {"Employee":{"EName":"abcd"}}
^" evaluating expression: "%dw 2.0 import * from dw::core::Binaries output application/json
--- fromBase64(payload)"."
Note - also tried to check datatype of payload using :
typeOf(payload)
This too gave the same exception as above ...
Please help
Update 1:
Based on comments from #aled few additional details :
I am making a GET request to my api endpoint which is reading data from an ERP system which returns data in XML
Then I use a custom component that is being used to transform the XML data to JSON
The o/p of this custom component is what is generating binary data which I am unable to parse
I agree regarding Base64 that was useless
I later even tried with Transform component and all of the below attempts failed with the same exception :
Attempt#1:
%dw 2.0
output application/json
---
if (isEmpty(payload.^raw)) {
"payload": "No payload!!"
}
else {
"payload": payload
}
Attempt#2:
%dw 2.0
output application/json
---
payload
The above XML payload is a short excerpt received from ERP
I need to parse the payload and identify if there is an error present in the payload .
NOTE : if I simply log the payload it all shows up fine in the logs.
is it not possible to convert binary data to json ? do you think there is something wrong in the data received either from ERP or in the XML to JSON Transformer ?
Update#2
So based on earlier comments from #aled ( thanks ! ) started focusing on payload o/p of the ERP component ( which is XML ) BEFORE it is fed to our custom transformer ( which is generating binary data )
Attaching screen print for clarity and will also paste non proprietary code :
Now when I inspect the payload I can see it as :
<?xml version = "1.0" encoding="utf-8" ?>
<Output>
<ErrorDetails>
<Status>1</Status>
<Details>Invalid user or organisation</Details>
</ErrorDetails>
<Employee>
<EName>abcd</EName>
</Employee>
</Output>
and in debug mode I can see that payload is String and NOT Binary
Now I can access individual elements of the payload .
Example:
<set-variable value="#[output application/java --- payload[0].ErrorDetails['Status']]"
doc:name="extract status" variableName="status"/>
So this gives me the value 1 which is expected and good .
Conclusions:
1 The component that interacts with ERP is generating Non Binary / stream data
2 This data as expected is parseable - all good here
3 AFTER this data is fed to our custom component - the o/p payload is now binary and am running into issues parsing it ...
Question:
I know this being a custom component i cannot share code details here and thereby cannot expect inputs BUT regarding #aled comments about hexdump do you think I should try and use it against the output of the custom component ?
Once again a big thanks for your patience and help
Using function fromBase64() is just wrong. The value is not a Base64 string. It doesn't makes sense to try it. Using toBase64() would be useless because you would not be able to do anything with it, other than sending it somewhere else.
Your payload seems to be a JSON, and the media type is application/json in your screenshot, but it contains an UNICODE character at the end at least. You need. What are you trying to do with that payload exactly?
If the payload is truly a binary there is nothing you can do about that in the application. If you are receiving it from somewhere else check with the source. You didn't provide details of the source. Also ensure it is not your application corrupting the payload somehow.

Mulesoft_ passing client id and Client_secret under HTTP header

I have a requirement where I need to add both client id and client_secret under HTTP headers(under attribute,headers)
I tried to use the below code and unfortunately, it is not working, so please check and guide us to get the expected code.
Transform message create an attribute and applied the below DataWeave code:
output application/java
---
{
headers: {
client_id: '68eee04d10774836b6e5c40189ed3efb',
client_secret: '149541B02E23487EBE517708496a2920'
}
And in the consume connector header part, I have added the below line code.
Attributes.headers
It is difficult to say without seeing exactly what the application is doing but I suspect you are mixing SOAP headers with HTTP headers. HTTP Headers go into the transport headers element.
Example assuming both kind of headers in different variables. Note that you can set each header individually or pass an object which contains them all:
<wsc:consume doc:name="Consume" config-ref="Web_Service_Consumer_Config" operation="GetContent">
<wsc:message>
<wsc:headers><![CDATA[#[vars.soapHeaders]]]></wsc:headers>
</wsc:message>
<wsc:transport-headers>
<wsc:transport-header key="client_id" value="#[vars.httpHeaders.client_id]" />
<wsc:transport-header key="client_secret" value="#[vars.httpHeaders.client_secret]" />
</wsc:transport-headers>
</wsc:consume>

payload changing to com.mulesoft.weave.reader.DefaultSeekableStream (Mule 3)

Payload in muleflow is getting converted in com.mulesoft.weave.reader.DefaultSeekableStream from org.glassfish.grizzly.utils.BufferInputStream. I am not sure why and due to this the subsequent activities (dw transformer) is failed. Anyone have any idea what could be the reason and how to overcome this.
The payload is pretty simple and I am trying to use two transformation activity, In first activity I parse the payload and create a flowVariable and in second transformation is to add values in payload. However, after first transformation the payload is changed to DefaultSeekableStream.
Thanks,
Abhi
Error message:

how to add extra column from an existing .text file in wso2 esb?

I have Input.text file which has following values
**SNO|FIRSTNAME|LASTNAME|EMAIL|PHONE|ADDRESS|SELLING_DEALER**
**51|chris|clark|cpar#hotmail.com|0406-755789|Australia|MB MacGregor**
I have done some operation like phone validation or email validation.After performing that,need to write output file which has following values if phonevalidation gets successed.
**SNO|FIRSTNAME|LASTNAME|EMAIL|PHONE|ADDRESS|SELLING_DEALER|PHONEVALIDATION**
**51|chris|clark|cpar#hotmail.com|0406-755789|Australia|MB MacGregor|yes**
Otherwise(if phonevalidation gets failed)
**SNO|FIRSTNAME|LASTNAME|EMAIL|PHONE|ADDRESS|SELLING_DEALER|PHONEVALIDATION**
**51|chris|clark|cpar#hotmail.com|0406-755789|Australia|MB MacGregor|No**
Hope you understood my question!
Anyone please help me out to find solution,
Awaiting for your response
Try this. Depending on PHONEVALIDATION, you can route the payload using Router Mediator and later on enrich youy payload using Enrich Mediator.
How to enrich payload take a look this post (https://dzone.com/articles/wso2-esb-enrich-mediator-fast)
Hope this helps

How to get payload mime type in Mule 4

I am trying to find out what is the payload type by printing it out using logger. I am aware that in Mule 3 you could use this #[payload.getClass().getSimpleName()] or #[message.dataType.type].
How to achieve this in Mule 4? I did my google search but could not find any solution.
You can use:
#[payload.^class]
Try logging:
#[payload.^]
Should print:
{class=java.util.ArrayList, encoding=UTF-8, mimeType=application/java, raw=[{}]}
But if your payload is not application/java mime/type but json or something instead it won't have class attribute.
Get payload media type: #[payload.^mediaType]
Reference: https://docs.mulesoft.com/dataweave/2.4/dataweave-cookbook-extract-data