I have a REST API that needs to produce both Fhir xml and Fhir json. I generated java classes using xsd. XML works 100%. however, the json object looks funny as it includes attributes which I'd like to suppress.
I have specified on my REST API: #Produces({"application/json+fhir",MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
XML output:
<Bundle xmlns="http://hl7.org/fhir" xmlns:ns2="http://www.w3.org/1999/xhtml">
<meta>
<versionId value="urn:uuid:b6bfc48a-7b03-4bf3-ba94-d05a3b52979a"/>
<lastUpdated value="2017-07-10T08:32:44.670+02:00"/>
</meta>
<type value="collection"/>
<entry>
<resource>
<Coverage>
<id value="47000340200"/>
<subscriber>
<display value="AB SMITH"/>
</subscriber>
<period>
<start value="2017-01-01"/>
</period>
<payor>
<display value="XXX040TXX"/>
</payor>
<grouping>
<extension url="some URL">
<valueUri value="Hyperlink goes here"/>
</extension>
<group value="XXX"/>
<groupDisplay value="XXX MEDICAL FUND"/>
<plan value="OPT1"/>
<planDisplay value="OPTION1"/>
<class value="Active"/>
</grouping>
</Coverage>
</resource>
</entry>
JSON output:
{"Bundle": {
"meta": {
"versionId": {"#value": "urn:uuid:b6bfc48a-7b03-4bf3-ba94-d05a3b52979a"},
"lastUpdated": {"#value": "2017-07-10T08:32:44.670+02:00"}
},
"type": {"#value": "collection"},
"entry": [
{"resource": {"Coverage": {
"id": {"#value": "47000340200"},
"subscriber": {"display": {"#value": "AB SMITH"}},
"period": {"start": {"#value": "2017-01-01"}},
"payor": {"display": {"#value": "XXX040TXX"}},
"grouping": {
"extension": {
"#url": "some URL",
"valueUri": {"#value": "Hyperlink goes here"}
},
"group": {"#value": "XXX"},
"groupDisplay": {"#value": "XXX MEDICAL FUND"},
"plan": {"#value": "OPT1"},
"planDisplay": {"#value": "OPTION1"}
}
}}}
]
}}
How do I get rid of the "#Value" attribute?
The FHIR XML and JSON (and TTL) syntaxes are all tuned to their syntax and thus manifest a slightly different model. If you try running an instance with extensions on a simple type (date, boolean, etc.), you'll find even more significant differences in your generated object model. If you generate your object model from the XML schema, the JSON schema or the OWL, you'll find there's a decent chunk of hand-coding you'll have to add on afterwards to generate and parse the other syntaxes correctly. The alternative is to use one of the existing reference implementations - those handle the conversion for you and provide a whole bunch of helper classes and methods that might also be helpful for you. The reference implementations can be found on the downloads page.
Related
I am using log4j2 with a JSON properties file I am naming log4j2.json and attempting to add a kafka appender. There are plenty of examples using the older formats or xml, but struggling to get the correct format in JSON. This is most likely a silly question, but I have been struggling to get this to work and can find no examples anywhere. I am tempted to abandoned configuring log4j2 in json and moving to XML, but I feel this should be rather simple.
Here is a sample kafka appender defined in XML.
'<Appenders>
<Kafka name="Kafka" topic="devglan-test">
<PatternLayout pattern="%date %message"/>
<Property name="bootstrap.servers">localhost:9092</Property>
</Kafka>
<Async name="Async">
<AppenderRef ref="Kafka"/>
</Async>
</Appenders>
How does the
'localhost:9092
entry map to JSON.
I have tried a number of styles such as the following:
'"Kafka": {
"name":"Kafka",
"topic":"FEEDPROCESSING_Dev",
"PatternLayout": {
"pattern": "%date %message"
},
"bootstrap.servers": [{"name":"localhost:9092"}]}
}
That did not work. I also tried..
'"Kafka": {
"name":"Kafka",
"topic":"FEEDPROCESSING_SYNC_Dev",
"PatternLayout": {
"pattern": "%date %message"
},
"Property": {"bootstrap.servers":"localhost:9092"}}
}
I am getting errors like:
Property contains an invalid element or attribute "bootstrap.servers"
THis configuration gives me the error "Unable to locate plugin type for bootstrap.servers":
'"Property": {"bootstrap.servers":[{"name":"localhost:9092"}]}}},
I know I have the correct maven dependencies..
What is the correct way to configure a Kafka appender, particular the bootstrap server property,using JSON and log4j2?
This is the correct format I think:
"Kafka": {
"name": "Kafka",
"topic": "FEEDPROCESSING_Dev",
"PatternLayout": {
"pattern": "%date %message"
},
"Property": {
"name": "bootstrap.servers",
"value": "localhost:9092"
}
}
I'building a proxy-service using wso2 esb. It sends a REST request to Google Books API and receives json. In this Json, there's a dynamic array which I have to parse to XML. I can't seem to figure out how can I do that.
received json payload
"items": [
{
"volumeInfo": {
"title": "Web Services",
"authors": [
"Gustavo Alonso",
"Fabio Casati",
"Harumi Kuno",
"Vijay Machiraju"
],
"publisher": "Springer Science & Business Media",
"publishedDate": "2003-09-04"
]
}
If you glance over the above received Json, it's something like this items[0].authors[i]
here authors[i] is very dynamic, as different books have different number of authors.
How can I convert this payload to XML and then send as an XML to client
<items>
<titie></title>
<authors>
<author></author>
<author></author>
<author></author>
.
.
.
</authors>
</items>
When converting from JSON to XML I almost always use this way.
First set messageType to xml, you may also set ContentType but I am not 100% sure if it is required
<property name="messageType" scope="axis2" value="application/xml"/>
<property name="ContentType" scope="axis2" value="application/xml"/>
Next use the payload factory with an enclosing root element, set the media type to XML
<payloadFactory media-type="xml">
<format>
<SomeRequest xmlns="yourXMLNamespace">
$1
</SomeRequest>
</format>
<args>
<arg evaluator="json" expression="."/>
</args>
</payloadFactory>
Now you will have something that looks like this.
<SomeRequest>
<items>
<volumeInfo></volumeInfo>
<title>Web Services</title>
<authors>Gustavo Alonso</authors>
<authors>Fabio Casati</authors>
<authors>Harumi Kuno</authors>
<authors>Vijay Machiraju</authors>
<publisher>Springer Science & Business Media</publisher>
<publishedDate>2003-09-04</publishedDate>
</items>
<items>
...
</items>
</SomeRequest>
See how it unwrapped the JSON array, it created multiple elements all using the array name. To get from here to the response format you want the easiest way to do it is using an xslt transform.
<xslt key="{name of your xslt transform file}"/>
Then you can respond to back to the client.
It may be worthwile checking out the JSON Support page in the wso2 docs. It covers how JSON is converted to and from XML
https://docs.wso2.com/display/EI620/JSON+Support
In the outsequence you can use a payload mediator to construct the xml from JSON.
https://docs.wso2.com/display/ESB500/PayloadFactory+Mediator
I need to use a Soap API and expose it as REST.
Something just like the Weather API discussed in this Apigee tutorial/doc
http://docs.apigee.com/tutorials/proxy-soap-service
However, in my case, instead of using a rest GET, I have to use a rest POST with the parameters in a json payload.
So instead of doing this
GET http://myapi.apigee.net/weatherrest/cityweatherbyzip?ZIP=07030
I need to do this:
POST http://myapi.apigee.net/weatherrest/cityweatherbyzip
{
"ZIP":07030
}
with apigee taking the parameter from the posted json payload and making the normal SOAP call with it.
At the moment, it doesn't seem to work, the call reaches the target but without the parameter. It returns:
{
"GetCityWeatherByZIPResponse":{
"GetCityWeatherByZIPResult":{
"Success":"false",
"ResponseText":"Invalid ZIP",
"State":{
},
"City":{
},
"WeatherStationCity":{
},
"WeatherID":-1,
"Description":{
},
"Temperature":{
},
"RelativeHumidity":{
},
"Wind":{
},
"Pressure":{
},
"Visibility":{
},
"WindChill":{
},
"Remarks":{
}
}
}
}
What should i do to make sure parameters are taken from my json payload and propagated to the SOAP target call? Many Thanks
Actually, this is all related to those ExtractVariable block.
See this:
http://docs.apigee.com/api-services/reference/extract-variables-policy
So in this case, something like this should be used:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="true" enabled="true" name="GetCityWeatherByZIP-extract-form-param">
<DisplayName>GetCityWeatherByZIP Extract Form Param</DisplayName>
<Source clearPayload="true|false">request</Source>
<JSONPayload>
<Variable name="ZIP" type="string">
<JSONPath>$.ZIP</JSONPath>
</Variable>
</JSONPayload>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
</ExtractVariables>
in Api > Develop > policy
(the one corresponding to the first step of your PUT)
been at this for some time now,
i have a rest service that takes some parameter that i send via the query string. other then that i need to send via the request body some fields.
the format needs to be json.
here is a successful request made from postman for example:
{
"TransactionLogId": "6e6279a3-22d9-458d-b1c9-9b03a81556be",
"CreatedDate": "2015-08-17T15:05:50.0143866Z",
"LogType": "Info",
"TransactionCode": "2831b7bc-9fc8-424d-857a-182397a5eb11",
"ServiceName": "ESBService.WCF",
"ServiceId": "8664e362-f63d-4d10-8a23-3b86b9f22cc7",
"Servers": "******************",
"Context": "EmployersSite",
"RequestIPs": "**************",
"UserId": "258a8c83-3f18-40d6-aea7-986dc0d97656",
"ActivityTime": "2015-08-17T15:05:50.0143866Z",
"LogSubType": "Info.RequestBegin",
"Title": "RequestBegin",
"Details": "",
"RequestData": "{\r\n \"Filters\": {\r\n \"Mode\": \"Automatic\",\r\n \"Type\": \"Applicant\"\r\n }\r\n}",
"EntityClass": "SavedSearch",
"EntityId": "",
"Methods": "SavedSearch_Search; SetSession",
"SourceFilePath": "*******************\\PortalService.svc.cs",
"SourceLineNum": 1025,
"RunTime": 0.015
}
here is my config. lets say that all i want right now is just to send the exception message in details field.
here is my config:
<nlog throwExceptions="true" internalLogFile="c:\\Data\\Logs\\IES\\nlog_debug.txt" internalLogLevel="Warn">
<variable name="LogBaseFolder" value="c:\\Data\\Logs\\tester" />
<targets>
<target type='WebService'
name='ws'
url='somesvc.vc/TransactionLog/Create?Context=Portal&UserToken=a441b37f-3403-43fd-8f58-d1da3024133a'
protocol='HttpPost'
encoding='UTF-8'>
<parameter name='details' type='System.String' layout=" ${message}"/>
</target>
</targets>
<rules>
<logger name="*" writeTo="ws" />
</rules>
</nlog>
and my code:
Log.Site.Error("erorrrr")
but the request never makes it it get error that the body is not right:
message=Unexpected character encountered while parsing value: M. Path
'', line 0, position 0.
this is killing me could realy use some help. thanks
don't worry it's actually something newbies encounters a lot and there is a simple solution for that! – so REST your mind :)
So basically, when you pass the JSON back in the respond you need to Super-Serialize the object prior the response.Write(), do
response.super(Object name_Object)
What it does it handles "deeper" encapsulation processes ('DIYA Encapsulation') which includes nested objects (methods and members)
But without the core functions (constructor, destructor..)
Hope it helps, and good luck.
BTW, Recommend you to read more about classes, nest objects, what is a constructor etc.
It will help you further more as you develop as a developer! Cheers :)
I was using a Mule application to get data from another system which is invoked by an HTTP endpoint, used java with jersey api to get the rest component.
Sample input data is given below, here keys and values are not fixed, it may vary based on user request. Array size will increase may be 2 to n entries. It is working fine with Mule and Java rest based component.
Input JSON data:
[
{
"Company": "BEG1",
"Account": "10011",
"Deptid": "111",
"Location": "SM1",
"Transaction Date": "2014-07-15",
"Description": "Invoice1",
"Debit": 0,
"Credit": 13.46,
"Invoice Nbr": "16824321"
},
{
"Company": "BEG92",
"Account": "10092",
"Deptid": "222",
"Location": "SL2",
"Transaction Date": "2014-07-19",
"Description": "Invoice End2",
"Debit": 13.46,
"Credit": 0,
"Invoice Nbr": "168243292"
}
]
Planning to migrate to APIkit with RAML: how can I make a RAML template for above case? Since keys are dynamic, this doesn't seem straightforward.
2) With same approach for GET, I will get the data for my get request, I am not sure what is the key and its corresponding values, only I was doing is get the data, parse it and send it to the user. How do I create RAML template on this situation.Will mule APIkit with RAML will work here?
My existing code:
#POST
#Path("/post")
#Consumes(MediaType.APPLICATION_JSON)
#Produces(MediaType.APPLICATION_JSON)
public List<GLExport> postOperation(#Payload String content) throws ParseException {
JSONParser jsonParser = new JSONParser();
Object jsonObjectInstance =null;
jsonObjectInstance = jsonParser.parse(new StringReader(content));
...
return glExportList;
<http:inbound-endpoint exchange-pattern="request-response" host="${hostname}" port="${glport}" path="QBJournalExport/QBGLRest" doc:name="HTTP"/>
<jersey:resources doc:name="REST">
<component class="com.qb.rest.GLExportService"/>
</jersey:resources>
It seems your question is more about JSON Schema than RAML. In essence, you are asking how to support unknown fields in a JSON Schema.
The answer is by adding:
"additionalProperties": true
to your JSON Schema object definition.
I strongly suggest that if there is set of fields are known, you declare them explicitly in your schema: users of your API will thank you for that.
Also, if some of these fields are guaranteed to be present, mark them as required as well.
APIkit should have no trouble dealing with additional properties.