With cars-jpa-archetype example, I am able to perform deep insert (Car and
Driver) in XML but not JSON. With my JSON 1 or 2 at below, only Car is
inserted and Driver is null. Any one can shed light on my JSON inputs? Have no issue with JSON input if I use Olingo annotations (#EdmEntityType etc).
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="
http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="
http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xml:base="
http://localhost:8080/example/MyFormula.svc/">
<category term="MyFormula.Car" scheme="
http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link href="Cars(Id=553,IdL=554L)" rel="edit" title="Car" />
<link href="Cars(Id=553,IdL=554L)/DriverDetails" rel="
http://schemas.microsoft.com/ado/2007/08/dataservices/related/DriverDetails"
title="DriverDetails" type="application/atom+xml;type=entry">
<m:inline>
<entry xml:base="http://localhost:8080/example/MyFormula.svc/">
<category term="MyFormula.Driver" scheme="
http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link href="Drivers(10L)" rel="edit" title="Driver" />
<link href="Drivers(10L)/CarDetails" rel="
http://schemas.microsoft.com/ado/2007/08/dataservices/related/CarDetails"
title="CarDetails" type="application/atom+xml;type=entry" />
<content type="application/xml">
<m:properties>
<d:Birthday>2014-12-05T14:35:11.141</d:Birthday>
<d:Id>10</d:Id>
<d:Lastname>Super</d:Lastname>
<d:Name>Speeder</d:Name>
<d:Nickname>TN</d:Nickname>
</m:properties>
</content>
</entry>
</m:inline>
</link>
<content type="application/xml">
<m:properties>
<d:Id>553</d:Id>
<d:IdL>554</d:IdL>
<d:Model>M1</d:Model>
<d:ModelYear>2014</d:ModelYear>
<d:Price>20000.0</d:Price>
<d:Updated>2014-03-20T14:35:17.075</d:Updated>
</m:properties>
</content>
</entry>
// JSON 1
{
"Id":677,
"IdL":"678",
"Model":"M1",
"ModelYear":2014,
"Price":"20000.0",
"Updated":"\/Date(1395326117075)\/",
"DriverDetails":{
"Birthday":"\/Date(1417790111141)\/",
"Id":"3",
"Lastname":"Super",
"Name":"Speeder",
"Nickname":"YZ",
"CarDetails": {
"__deferred": {
"uri": "
http://localhost:8080/example/MyFormula.svc/Drivers(3)/CarDetails"
}
}
}
}
// JSON 2
{
"d": {
"__metadata": {
"type": "MyFormula.Car"
},
"Id": 601,
"IdL": "602",
"Model": "M1",
"ModelYear": 2014,
"Price": "20000.0",
"Updated": "/Date(1395244800000)/",
"DriverDetails": {
"__metadata": {
"id": "http://localhost:8080/example/MyFormula.svc/Drivers(11L)",
"uri": "http://localhost:8080/example/MyFormula.svc/Drivers(11L)",
"type": "MyFormula.Driver"
},
"Birthday": "/Date(1417795200000)/",
"Id": "11",
"Lastname": "Super",
"Name": "Speeder",
"Nickname": "Bolt",
"CarDetails": {
"__deferred": {
"uri": "
http://localhost:8080/example/MyFormula.svc/Drivers(11L)/CarDetails"
}
}
}
}
}
Sorry for cross post here as no response from the Olingo forum.
Seems like the same issue was posted on their Jira but it should have been resolved now:
https://issues.apache.org/jira/browse/OLINGO-515
Related
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!
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.
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.
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
}
}
I am working on a medical application based on HL7 FHIR. I am trying to add new record using XML and JSON both. But all I get is the '500 Internal Server Error'.
The XML I am trying to POST is:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Patient Data</title>
<id>urn:uuid:20</id>
<updated>2015-05-21T16:33:58.030533</updated>
<entry>
<title>Patient Dummy Data</title>
<id>Other/p21-disease-activity-score-1439917023</id>
<updated>2015-08-18T18:57:03</updated>
<published>2015-08-18T18:57:03</published>
<content type="text/xml">
<Other xmlns="http://hl7.org/fhir">
<identifier>
<value value="p21-disease-activity-score-1439917023" />
</identifier>
<text>
<status value="generated" />
</text>
<subject>
<reference value="patient/21" />
<display value="4" />
</subject>
<code>
<coding>
<system value="http://hl7.org/fhir/other-resource-type" />
<code value="RA_DISEASE_ACTIVITY" />
</coding>
</code>
</Other>
</content>
</entry>
</feed>
I am posting this XML to API Server using PHP-CURL but getting 500 Internal Server Error.
I tried with JSON too but no luck. Here is the JSON:
[
{
"resourceType": "Bundle",
"title": "PatientData",
"id": "urn:uuid:21",
"updated": "2015-05-21T16:33:58.030533",
"entry": [
{
"title": "MyTitle",
"id": "Other/p007-shoulder-lt-1439220540",
"updated": "2015-08-10T11:29:00",
"published": "2015-08-10T11:29:00",
"author": {
"name": "Medtak"
},
"content": {
"resourceType": "Other",
"identifier": "007",
"text": {
"status": "generated"
},
"subject": {
"reference": "patient/007",
"display": "true"
},
"code": {
"coding": [
{
"system": "http://hl7.org/fhir/other-resource-type",
"code": "RA_DISEASE_ACTIVITY"
}
]
}
}
}
]
}
]
I have spent almost 3 days to fix this issue but couldn't find any solution. Any help would be appreciated. Thanks!
POST a resource via CURL
curl -X POST https://api.1uphealth.care/fhir/stu2/Patient \
-H "Content-Type: application/json" \
-H "Authorization: Bearer xxx_your_access_token_here_xxx" \
-d '{"resourceType": "Patient","id": "helloiamatestpatient","gender": "female"}'
If you're posting xml, use the correct xml fhir doc and change the Content-Type.
Depending on the FHIR server you're working with, you may not be able to POST resources because many do not support write access yet.
Here's some more information on using oauth to query FHIR - https://1up.health/dev/intro-fhir-api-oauth-query
You can get some idea if you following below link.
http://hl7-fhir.github.io/overview-dev.html