DataMapper mediator : mapping failed error - json

I want to convert my XML data to JSON using data mapper. But when I have added mapper in ESB flow and provide XML input and JSON output. It says DataMapper mediator: mapping failed. Please guide me on what is wrong with XML and JSON?
My XML input as below:-
<?xml version="1.0" encoding="UTF-8"?>
<FIXMLResponse xmlns="http://www.finacle.com/fixml" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Header>
<ResponseHeader>
<RequestMessageKey>
<RequestUUID>FEBA_1553756445880</RequestUUID>
<ServiceRequestId>executeFinacleScript</ServiceRequestId>
<ServiceRequestVersion>10.2</ServiceRequestVersion>
<ChannelId>COR</ChannelId>
</RequestMessageKey>
<ResponseMessageInfo>
<BankId>04</BankId>
<TimeZone>System.CurrentSystemTimeZone</TimeZone>
<MessageDateTime>2020-02-27T20:25:13.697653+05:30</MessageDateTime>
</ResponseMessageInfo>
<UBUSTransaction>
<Id />
<Status />
</UBUSTransaction>
<HostTransaction>
<Id />
<Status>SUCCESS</Status>
</HostTransaction>
<HostParentTransaction>
<Id />
<Status />
</HostParentTransaction>
</ResponseHeader>
</Header>
<Body>
<executeFinacleScriptResponse>
<ExecuteFinacleScriptOutputVO xsi:type="xsd:string" />
<executeFinacleScript_CustomData>
<STATUS>SUCCESS</STATUS>
<ERROR>
<FIBUSINESSEXCEPTION>
<ERRORDETAIL>
<ERRORCODE>ERR0008</ERRORCODE>
<ERRORDESC>Invalid NIC Passed</ERRORDESC>
<ERRORTYPE>BE</ERRORTYPE>
</ERRORDETAIL>
</FIBUSINESSEXCEPTION>
</ERROR>
</executeFinacleScript_CustomData>
</executeFinacleScriptResponse>
</Body>
</FIXMLResponse>
My JSON Output (conversion of above XML into JSON using online tool) as below:-
{
"Header": {
"ResponseHeader": {
"RequestMessageKey": {
"RequestUUID": "FEBA_1553756445880",
"ServiceRequestId": "executeFinacleScript",
"ServiceRequestVersion": "10.2",
"ChannelId": "COR"
},
"ResponseMessageInfo": {
"BankId": "04",
"TimeZone": "System.CurrentSystemTimeZone",
"MessageDateTime": "2020-02-27T20:25:13.697653+05:30"
},
"UBUSTransaction": {
"Id": null,
"Status": null
},
"HostTransaction": {
"Id": null,
"Status": "SUCCESS"
},
"HostParentTransaction": {
"Id": null,
"Status": null
}
}
},
"Body": {
"executeFinacleScriptResponse": {
"ExecuteFinacleScriptOutputVO": {
"#type": "xsd:string"
},
"executeFinacleScript_CustomData": {
"STATUS": "SUCCESS",
"ERROR": {
"FIBUSINESSEXCEPTION": {
"ERRORDETAIL": {
"ERRORCODE": "ERR0008",
"ERRORDESC": "Invalid NIC Passed",
"ERRORTYPE": "BE"
}
}
}
}
}
}
}

If you just want to do a XML to JSON transformation without customising any values, you can use messageType property to convert and get the response. Look at the sample proxy configuration below.
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="tojson"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<respond/>
</inSequence>
</target>
<description/>
</proxy>
If you send the XML payload to this proxy, it will send a JSON response.

Related

How to combine 2 json payloads in wso2?

I am making use of XSLT mediator to form the following JSON payload:
{
"products": [
{
"product_id": 1,
"product_name" : "abc"
},
{
"product_id": 2,
"product_name" : "xyz"
}
]
}
Based on the response I get from the api using the above payload, I need to create another json payload(below) and append it to make another api call.
{
"amount": {
"total_amount": 0.46,
"total_tax": 0
}
}
I want the final payload to look like
{
"products": [
{
"product_id": 1,
"product_name" : "abc"
},
{
"product_id": 2,
"product_name" : "xyz"
}
],
"amount": {
"total_amount": 0.46,
"total_tax": 0
}
}
How can I achieve this on WSO2 Integration studio?
I think XSLT is an overkill for this and I don't think Datamapper is a viable option here, given we are dealing with multiple inputs. You can simply use the Enrich Mediator for this. Here is an example for your payloads. I tried to provide an example as close to your requirement, I have hardcoded the payloads, and the Payload Factory depicts your backend call response and the original PL.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/json" name="TestAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="GET">
<inSequence>
<payloadFactory description="Build JSON" media-type="json">
<format>
{
"products": [
{
"product_id": 1,
"product_name" : "abc"
},
{
"product_id": 2,
"product_name" : "xyz"
}
]
}
</format>
<args/>
</payloadFactory>
<enrich description="First save the Original PL to a property" >
<source clone="true" type="body"/>
<target property="ORIGINAL_PL" type="property"/>
</enrich>
<payloadFactory description="Build JSON second PL" media-type="json">
<format>
{
"amount": {
"total_amount": 0.46,
"total_tax": 0
}
}
</format>
<args/>
</payloadFactory>
<enrich description="Save the PL from the second request to another property">
<source clone="true" type="body"/>
<target property="SECOND_PL" type="property"/>
</enrich>
<enrich description="Restore original payload">
<source clone="false" property="ORIGINAL_PL" type="property"/>
<target type="body"/>
</enrich>
<enrich description="Now add the second PL as a Child to the original" >
<source clone="true" property="SECOND_PL" type="property"/>
<target action="child" xpath="json-eval($)"/>
</enrich>
<log level="full"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
This is the result of the above.
{
"products": [
{
"product_id": 1,
"product_name": "abc"
},
{
"product_id": 2,
"product_name": "xyz"
}
],
"amount": {
"total_amount": 0.46,
"total_tax": 0
}
}
You can use DataMapper mediator to provide input and output schema and transform the incoming payload to the way you need. Provide either JSON or XML schema that you are receiving from the 1st service as the input schema to DataMapper and provide the schema of the expected result in either JSON or XML to the DataMatter as output schema. After that, you can map both input/ output fields and at runtime, DataMapper will do the message translation for you.
For more details - https://apim.docs.wso2.com/en/latest/tutorials/integration-tutorials/transforming-message-content/
Thanks!

Send Email body and attachment content to a REST (system Email) API in Mule 4

I am trying to implement a Rest API to send any type of email (with or without attachments) using SMTP connector. I want the system-email API to get the email content dynamically from a request body.
In my client application I am constructing the json structure as below.
%dw 2.0
import toBase64 from dw::core::Binaries
output application/json
---
{
"body": {
"fromAddress": "abcmule01#outlook.com",
"toAddress": Mule::p('email.to') splitBy ",",
"subject": Mule::p('email.subject'),
"content": payload,
"contentType": "text/html",
"encoding": "UTF-8",
"contentTransferEncoding": "Base64",
"attachments": {
"txtAttachment": vars.textPlain,
"csvAttachment": vars.csvPayload
},
"smtpHost": Mule::p('smtp.host'),
"smtpPort": Mule::p('smtp.port'),
"smtpUser": Mule::p('smtp.username'),
"smtpPassword": Mule::p('smtp.password')
},
"header": {
"apiName": "test-email-flow",
"apiVersion": "1.0",
"transactionId": "test-12345",
"correlationId": "test-12345"
}
}
The functionality is working fine only for sending text attachments However, if I try to send CSV content, the content is not displaying correctly in the email attachment.
Just for testing, I am reading a CSV file and constructing the CSV content (vars.csvPayload) as below.
application/csv; charset=UTF-8; header="false"
Belinda Jameson,2017,Cushing House,148,3.52
Jeff Smith,2018,Prescott House,17-D,3.20
Sandy Allen,2019,Oliver House,108,3.48
And the request structure for attachment is coming as below after the transformation.
"attachments": {
"txtAttachment": "This is the email text attachment",
"csvAttachment": [
{
"column_0": "Belinda Jameson",
"column_1": "2017",
"column_2": "Cushing House",
"column_3": "148",
"column_4": "3.52"
},
{
"column_0": "Jeff Smith",
"column_1": "2018",
"column_2": "Prescott House",
"column_3": "17-D",
"column_4": "3.20"
},
{
"column_0": "Sandy Allen",
"column_1": "2019",
"column_2": "Oliver House",
"column_3": "108",
"column_4": "3.48"
}
]
}
However when I pass the 'attachments' to email send component in system-email API it is not showing the csv content in correct format. Can you please help me constructing the request structure for the attachment?
Below is the xml config file for send email sub flow
<sub-flow name="sapi-core-email-send-mail-implementation" doc:id="177de084-c73b-4be1-ab10-90479ca98d5d" >
<ee:transform doc:name="Transform Message" doc:id="207cdb76-fc5e-47b1-bebd-1cc75f50a5d0" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="emailTo" ><![CDATA[%dw 2.0
output application/json
---
"deeps.test#test.net.au,deeps2#test.net.au" splitBy ","]]></ee:set-variable>
<ee:set-variable variableName="port" ><![CDATA[%dw 2.0
output application/java
---
payload.body.smtpPort]]></ee:set-variable>
<ee:set-variable variableName="username" ><![CDATA[%dw 2.0
output application/java
---
payload.body.smtpUser]]></ee:set-variable>
<ee:set-variable variableName="password" ><![CDATA[%dw 2.0
output application/java
---
payload.body.smtpPassword]]></ee:set-variable>
<ee:set-variable variableName="host" ><![CDATA[%dw 2.0
output application/java
---
payload.body.smtpHost]]></ee:set-variable>
</ee:variables>
</ee:transform>
<set-payload value='#[payload.body.content replace /([\r,\t,\n,"\"])/ with ""]' doc:name="Set Payload" doc:id="98c98bac-da72-4b9f-9207-5bab35ac228c" mimeType="text/html" encoding="UTF-8"/>
<email:send doc:name="Send" doc:id="b3318d9e-e0ca-4750-9cb5-3bd7cb9ccdca" fromAddress="#[vars.requestBody.fromAddress]" toAddresses="#[vars.requestBody.toAddress]" subject="#[vars.requestBody.subject]" ccAddresses="#[vars.requestBody.ccAddress]" bccAddresses="#[vars.requestBody.bccAddress]" replyToAddresses="#[vars.requestBody.replyToAddress]" config-ref="Email_SMTP_Sapi_Core_Email">
<email:body contentType="#[vars.requestBody.contentType]" encoding="#[vars.requestBody.encoding]" contentTransferEncoding="#[vars.requestBody.contentTransferEncoding]" >
</email:body>
<email:attachments ><![CDATA[#[vars.requestBody.attachments]]]></email:attachments>
</email:send>
<logger level="INFO" doc:name="Logger" doc:id="7a8d82aa-a23e-4bf9-bbad-26deb046c92f" message="Email has been successfully sent"/>
</sub-flow>
And the csv attachment content is coming as below in the email attachment
¬í sr java.util.ArrayListxÒ™Ça I sizexp w sr java.util.LinkedHashMap4ÀN\lÀû Z accessOrderxr java.util.HashMapÚÁÃ`Ñ F
loadFactorI thresholdxp?# w t column_0t Belinda Jamesont column_1t 2017t column_2t
Cushing Houset column_3t 148t column_4t 3.52x sq ~ ?# w t column_0t
Jeff Smitht column_1t 2018t column_2t Prescott Houset column_3t 17-Dt column_4t 3.20x sq ~ ?# w t column_0t Sandy Allent column_1t 2019t column_2t Oliver Houset column_3t 108t column_4t 3.48x x
csvPayload
test.csv
Built a quick sample flow for you.. Substitute the mail SMTP info and try with the configuration below.
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:email="http://www.mulesoft.org/schema/mule/email"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/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/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.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/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd">
<file:config name="File_Config" doc:name="File Config" doc:id="6c465807-159c-4d17-94e5-8882f8baa1dc" >
<file:connection />
</file:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="d0708665-5ac5-4bd1-80fd-cf83b7c2da9d" >
<http:listener-connection host="0.0.0.0" port="9191" />
</http:listener-config>
<email:smtp-config name="Email_SMTP" doc:name="Email SMTP" doc:id="9d7e5139-1aed-4a4e-9cc7-1b8d0297d7c2" from="from#email.com">
<email:smtps-connection host="smtp.gmail.com" user="yourgmailaddress" password="yourpwd" port="465" connectionTimeout="30" readTimeout="30" writeTimeout="30">
<tls:context>
<tls:trust-store insecure="true" />
</tls:context>
</email:smtps-connection>
</email:smtp-config>
<flow name="test-send-emailFlow" doc:id="462b24c4-f53b-4483-b9f4-609c4190e28c" >
<http:listener doc:name="Listener" doc:id="e764fbc7-fd3e-4121-bdb5-94eb9819184e" config-ref="HTTP_Listener_config" path="/sm"/>
<file:read doc:name="Read" doc:id="ca92561e-1dfa-44d4-a962-59b1493c198d" config-ref="File_Config" path="path/to/file/test.csv"/>
<ee:transform doc:name="Transform Message" doc:id="5d7da7cd-1951-4607-ac82-e2f9002716f2" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="attachFile" ><![CDATA[%dw 2.0
output application/java
---
{
"message": write(payload,"application/csv")
}
]]></ee:set-variable>
</ee:variables>
</ee:transform>
<email:send doc:name="Send" doc:id="c2ab4dd1-5401-4b64-abe3-9a95af371a31" config-ref="Email_SMTP" subject="CSV File">
<email:to-addresses >
<email:to-address value='"toemail"' />
</email:to-addresses>
<email:body contentType="text/plain" encoding="UTF-8">
<email:content ><![CDATA[#["Hello"]]]></email:content>
</email:body>
<email:attachments ><![CDATA[#[vars.attachFile]]]></email:attachments>
</email:send>
</flow>
</mule>
I was able to test your sample csv file just fine with this config.
======================================================================
Input to the flow below
{
"attachments": {
"txtAttachment": "This is the email text attachment",
"csvAttachment": [{
"column_0": "Belinda Jameson",
"column_1": "2017",
"column_2": "Cushing House",
"column_3": "148",
"column_4": "3.52"
},
{
"column_0": "Jeff Smith",
"column_1": "2018",
"column_2": "Prescott House",
"column_3": "17-D",
"column_4": "3.20"
},
{
"column_0": "Sandy Allen",
"column_1": "2019",
"column_2": "Oliver House",
"column_3": "108",
"column_4": "3.48"
}
]
}
}
Updated Flow processes the incoming JSON
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:email="http://www.mulesoft.org/schema/mule/email"
xmlns:file="http://www.mulesoft.org/schema/mule/file"
xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/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/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.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/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd
http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd">
<file:config name="File_Config" doc:name="File Config" doc:id="6c465807-159c-4d17-94e5-8882f8baa1dc" >
<file:connection />
</file:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="d0708665-5ac5-4bd1-80fd-cf83b7c2da9d" >
<http:listener-connection host="0.0.0.0" port="9191" />
</http:listener-config>
<email:smtp-config name="Email_SMTP" doc:name="Email SMTP" doc:id="9d7e5139-1aed-4a4e-9cc7-1b8d0297d7c2" from="fromemail">
<email:smtps-connection host="smtp.gmail.com" user="youremailId" password="yourpasswd" port="465" connectionTimeout="30" readTimeout="30" writeTimeout="30">
<tls:context>
<tls:trust-store insecure="true" />
</tls:context>
</email:smtps-connection>
</email:smtp-config>
<flow name="test-send-emailFlow" doc:id="462b24c4-f53b-4483-b9f4-609c4190e28c" >
<http:listener doc:name="Listener" doc:id="e764fbc7-fd3e-4121-bdb5-94eb9819184e" config-ref="HTTP_Listener_config" path="/sm"/>
<ee:transform doc:name="Transform Message" doc:id="5d7da7cd-1951-4607-ac82-e2f9002716f2" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="attachFile" ><![CDATA[%dw 2.0
output application/java
---
{
"message": write((payload.attachments.csvAttachment map {
($ mapObject {
("column_$$"): $
})
}),"application/csv", {"header":false})
}
]]></ee:set-variable>
</ee:variables>
</ee:transform>
<email:send doc:name="Send" doc:id="c2ab4dd1-5401-4b64-abe3-9a95af371a31" config-ref="Email_SMTP" subject="CSV File">
<email:to-addresses >
<email:to-address value='"youremailaddress"' />
</email:to-addresses>
<email:body contentType="text/plain" encoding="UTF-8">
<email:content ><![CDATA[#["Hello"]]]></email:content>
</email:body>
<email:attachments ><![CDATA[#[vars.attachFile]]]></email:attachments>
</email:send>
</flow>
</mule>

How can i get Element Value in Json payload with out Square brackets around element value?

I am using a payload mediator in the workflow to Update my JSON payload. I have successfully updated the payload with incoming request values and return output in JSON only. But in my JSON response payload after payload mediator, I am getting [ Value ] for the JSON element against which I have updated values.
I did not want my JSON element value enclosed within [] braces. I want a simple output like element: "Value".
Below is my JSON Response I receive after using the Payload mediator. Please guide me on how can I achieve the required output.
{
"FIXML": {
"Header": {
"RequestHeader": {
"MessageKey": {
"RequestUUID": [
"FEBA_1553756445880"
],
"ServiceRequestId": "executeFinacleScript",
"ServiceRequestVersion": "10.2",
"ChannelId": "COR"
},
"RequestMessageInfo": {
"BankId": [
"04"
],
"TimeZone": "GMT+05:00",
"EntityId": "",
"EntityType": "",
"ArmCorrelationId": "",
"MessageDateTime": 2020-03-03T16: 59: 10.000
},
"Security": {
"Token": {
"PasswordToken": {
"UserId": "11111",
"Password": ""
}
},
"FICertToken": "",
"RealUserLoginSessionId": "",
"RealUser": "",
"RealUserPwd": "",
"SSOTransferToken": ""
}
}
},
"Body": {
"executeFinacleScriptRequest": {
"ExecuteFinacleScriptInputVO": {
"requestId": [
"validateAcct.scr"
]
},
"executeFinacleScript_CustomData": {
"ACCT_NUM": [
"01122507578"
],
"PHONE_NUM": [
"59887834"
],
"NIC": [
"G2105493001653"
]
}
}
}
}
}
Conversion of Above JSON into XML as below.
<?xml version="1.0" encoding="UTF-8"?>
<FIXML>
<Body>
<executeFinacleScriptRequest>
<ExecuteFinacleScriptInputVO>
<requestId>
<element>validateAcct.scr</element>
</requestId>
</ExecuteFinacleScriptInputVO>
<executeFinacleScript_CustomData>
<ACCT_NUM>
<element>01122507578</element>
</ACCT_NUM>
<NIC>
<element>G2105493001653</element>
</NIC>
<PHONE_NUM>
<element>59887834</element>
</PHONE_NUM>
</executeFinacleScript_CustomData>
</executeFinacleScriptRequest>
</Body>
<Header>
<RequestHeader>
<MessageKey>
<ChannelId>COR</ChannelId>
<RequestUUID>
<element>FEBA_1553756445880</element>
</RequestUUID>
<ServiceRequestId>executeFinacleScript</ServiceRequestId>
<ServiceRequestVersion>10.2</ServiceRequestVersion>
</MessageKey>
<RequestMessageInfo>
<ArmCorrelationId />
<BankId>
<element>04</element>
</BankId>
<EntityId />
<EntityType />
<MessageDateTime>2020-03-03T18:31:48.000</MessageDateTime>
<TimeZone>GMT+05:00</TimeZone>
</RequestMessageInfo>
<Security>
<FICertToken />
<RealUser />
<RealUserLoginSessionId />
<RealUserPwd />
<SSOTransferToken />
<Token>
<PasswordToken>
<Password />
<UserId>11111</UserId>
</PasswordToken>
</Token>
</Security>
</RequestHeader>
</Header>
</FIXML>
Both JSON and XML files are used as Input and Output to Data mapper. But After data when I logged the message I get empty XML as below.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<FIXML>
<Body>
<executeFinacleScriptRequest>
<ExecuteFinacleScriptInputVO>
<requestId>
<element />
</requestId>
</ExecuteFinacleScriptInputVO>
<executeFinacleScript_CustomData>
<ACCT_NUM>
<element />
</ACCT_NUM>
<NIC>
<element />
</NIC>
<PHONE_NUM>
<element />
</PHONE_NUM>
</executeFinacleScript_CustomData>
</executeFinacleScriptRequest>
</Body>
<Header>
<RequestHeader>
<MessageKey>
<ChannelId />
<RequestUUID>
<element />
</RequestUUID>
<ServiceRequestId />
<ServiceRequestVersion />
</MessageKey>
<RequestMessageInfo>
<ArmCorrelationId />
<BankId>
<element />
</BankId>
<EntityId />
<EntityType />
<MessageDateTime />
<TimeZone />
</RequestMessageInfo>
<Security>
<FICertToken />
<RealUser />
<RealUserLoginSessionId />
<RealUserPwd />
<SSOTransferToken />
<Token>
<PasswordToken>
<Password />
<UserId />
</PasswordToken>
</Token>
</Security>
</RequestHeader>
</Header>
</FIXML>
</soapenv:Body>
</soapenv:Envelope>
Please Guide me here. How this conversion is properly done.

WSO2 Identity Server XACML JSON Request results in "Indeterminate" [Couldn't find AttributeDesignator attribute]

I am try to send a JSON request to wso2 entitlement endpoint using POSTMAN
Here is my published policy in the identity server:
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="samplePolicy" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1.0">
<Target>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">
read
</AttributeValue>
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"/>
</Match>
</AllOf>
</AnyOf>
</Target>
<Rule Effect="Permit" RuleId="permit"/>
Here is JSON request I send:
{
"Request": {
"Action": {
"Attribute": [
{
"AttributeId": "urn:oasis:names:tc:xacml:1.0:action:action-id",
"Value": "read"
}
]
},
"Resource": {
"Attribute": [
{
"AttributeId": "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
"Value": "http://127.0.0.1/service/very_secure/"
}
]
}
}
}
Both blocks of the code came from this blog
https://medium.com/#gdrdabarera/how-entitlement-management-works-with-rest-api-via-xacml-in-wso2-identity-server-5-3-0-7a60940d040c#.4lxgiw6tn
But no matter what I tried it always give me "Indeterminate" response
Postman response screenshot
I also try my own policy and request but I always get the same response
What is going on?
Fixed with: Remove any white space before and after the "read" attribute value in the xml policy:
<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" PolicyId="samplePolicyforJSON" RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:deny-overrides" Version="1.0">
<Target>
<AnyOf>
<AllOf>
<Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
<AttributeDesignator AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action" DataType="http://www.w3.org/2001/XMLSchema#string" MustBePresent="true"></AttributeDesignator>
</Match>
</AllOf>
</AnyOf>
</Target>
<Rule Effect="Permit" RuleId="permit"></Rule>
</Policy>
Tested with:
XACML Request:
{
"Request": {
"Action": {
"Attribute": [
{
"AttributeId": "urn:oasis:names:tc:xacml:1.0:action:action-id",
"Value": "read"
}
]
},
"Resource": {
"Attribute": [
{
"AttributeId": "urn:oasis:names:tc:xacml:1.0:resource:resource-id",
"Value": "http://127.0.0.1/service/very_secure/"
}
]
}
}
}
XACML Response:
{
"Response": [
{
"Decision": "Permit",
"Status": {
"StatusCode": {
"Value": "urn:oasis:names:tc:xacml:1.0:status:ok"
}
}
}
]
}
And with:
XACML Request:
<Request xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17" CombinedDecision="false" ReturnPolicyIdList="false">
<Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:resource:resource-id" IncludeInResult="false">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">http://localhost/secureAccess/resource</AttributeValue>
</Attribute>
</Attributes>
<Attributes Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action">
<Attribute AttributeId="urn:oasis:names:tc:xacml:1.0:action:action-id" IncludeInResult="false">
<AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">read</AttributeValue>
</Attribute>
</Attributes>
</Request>
XACML Response:
<Response xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17">
<Result>
<Decision>Permit</Decision>
<Status>
<StatusCode Value="urn:oasis:names:tc:xacml:1.0:status:ok"/>
</Status>
</Result>
</Response>
If you followed all the steps correctly, It should work.
After adding the policy, please check whether the policy is correctly added.
eg. Remove unnecessary spaces in the policy
Publish it to the PDP correctly and try. You can also try in "try" option in the policy window in IS 5.3.0. Use only xml request because it does not works for JSON

Custom YQL table for Tumblr likes

I'm trying to make a custom YQL table to access a user's likes through the Tumblr API. I made the following table in the YQL editor and saved it as tumblr.likes:
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>nonphoto</author>
<documentationURL>http://www.tumblr.com/docs/api</documentationURL>
<sampleQuery>select * from {table} where username='XXX' api_key='XXX'</sampleQuery>
</meta>
<bindings>
<select itemPath="response.liked_posts" produces="JSON">
<urls>
<url>http://api.tumblr.com/v2/blog/{username}.tumblr.com/likes</url>
</urls>
<inputs>
<key id="username" type="xs:string" paramType="path" required="true" />
<key id="api_key" type="xs:string" paramType="query" required="true" />
</inputs>
</select>
</bindings>
</table>
If this is correct then I should be able to type this query into the YQL console and get a JSON response back from Tumblr:
use "XXX" as tumblr.likes;
select * from tumblr.likes where username='XXX' and api_key='XXX';
But null appears in the results entry of the response, even if debug and diagnostics are checked to prevent caching. The response even shows the correct URL, which works if I just copy and paste it into my browser. Am I missing something? Here's an example response:
{
"query": {
"count": 0,
"created": "2016-01-15T21:44:36Z",
"lang": "en-US",
"diagnostics": {
"url": [
{
"execution-start-time": "2",
"execution-stop-time": "8",
"execution-time": "6",
"id": "579e13ad-a7c3-4eea-81d9-41fda5caf243",
"content": "http://sherpa-bcp5903.dht.yahoo.com:4080/YDHTWebService/V1/get/yql.global/store%3A%2F%2FoSSGByQMlFLQhMqNCwUcp1"
},
{
"execution-start-time": "14",
"execution-stop-time": "1137",
"execution-time": "1123",
"id": "ffab25db-521f-4795-9220-a82e2ac33a9d",
"content": "http://api.tumblr.com/v2/blog/XXX.tumblr.com/likes?api_key=XXX"
}
],
"publiclyCallable": "true",
"user-time": "1146",
"service-time": "1129",
"build-version": "0.2.942"
},
"results": null
}
}