I've written an ESB resource which takes in a list of test cases, like the example below:
{
"tests": [
{ "type": "DSS", "url": "http://localhost:8280/testsuite/general/test" },
{ "type": "ESB", "url": "http://localhost:8280/testsuite/general/test" },
{ "type": "GREG", "url": "http://localhost:8280/testsuite/general/test" },
{ "type": "GW", "url": "http://localhost:8280/testsuite/general/test" },
{ "type": "MB", "url": "http://localhost:8280/testsuite/general/test" },
{ "type": "ID", "url": "http://localhost:8280/testsuite/general/test" },
{ "type": "BOGUS", "url": "http://localhost:8280/testsuite/general/test" }
]
}
The resource takes this in as a JSON array and loops through the elements using the XPATH expression //tests/type and generates a status message (200 if it can do anything, ERR if not).
Ideally, I'd like to be able to incrementally add the types into some sort of a global array property which would eventually become [DSS, ESB, GREG, GW, MB, ID, BOGUS] so I can write a script to run through this and produce a payload to return something like the below:
{
"results": [
{ "TYPE": "DSS", "STATUS": "200" },
{ "TYPE": "ESB", "STATUS": "200" },
{ "TYPE": "GREG", "STATUS": "200" },
{ "TYPE": "GW", "STATUS": "200" },
{ "TYPE": "MB", "STATUS": "200" },
{ "TYPE": "ID", "STATUS": "200" },
{ "TYPE": "BOGUS", "STATUS": "ERR" }
]
}
I've been searching for a way to do this for a couple of days now, to no avail so if it's simply not possible or if I've just been looking for the wrong thing, I don't know but I'd really like to avoid producing a static resource, enabling future expansion with minimal involvement for me.
You can save your payload in the gov registry with this script :
<script language="js"><![CDATA[
importPackage(Packages.org.apache.synapse.config);
mc.getConfiguration().getRegistry().newResource("gov:/trunk/Test/TestTypes",false);
mc.getConfiguration().getRegistry().updateResource("gov:/trunk/Test/TestTypes",mc.getPayloadXML().toString());
]]></script>
newResource create the resource if it does not exist
you can use
mc.getPayloadJSON() instead of mc.getPayloadXML()
A sample with a resource 'TESTSOF' like this :
<root>
<value><child>1</child></value>
<value><child>2</child></value>
<value><child>3</child></value>
</root>
You can iter all "value" with :
<property name="TESTSOF" expression="get-property('registry','gov:/trunk/TESTSOF')" type="OM"/>
<iterate continueParent="true" sequential="false" preservePayload="false" expression="$ctx:TESTSOF//value">
<target>
<sequence>
<log level="full"/>
</sequence>
</target>
</iterate>
A sample with JSON :
Load JSON as the current message :
<payloadFactory media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('registry','gov:/trunk/Test/TestTypes')"/>
</args>
</payloadFactory>
Iterate :
<iterate continueParent="true" sequential="false" preservePayload="false" expression="//tests">
<target>
<sequence>
<log level="full"/>
</sequence>
</target>
</iterate>
Related
My team is building a health app and thus using Asymmetrik FHIR API Server. We need to save a bundle consisting of Condition, Observation and Procedure. The bundle should create each individual object in their respective tables. But when we are using postman to hit the base URL with a very simple bundle object it is giving Invalid URL. Each service is individually working fine and able to create respective objects. How can we enable the root URL of this FHIR server?
POST URL: http://localhost:3000/4_0_0/
POST Object:
{
"resourceType": "Bundle",
"id": "f001",
"type": "transaction",
"entry": [
{
"resource": {
"resourceType": "Observation",
"status": "registered"
},
"request": {
"method": "POST",
"url": "Observation"
}
},
{
"resource": {
"resourceType": "Condition",
"code": {
"coding": {
"system": "http://hl7.org/fhir/ValueSet/condition-code",
"code": "",
"display": ""
}
}
},
"request": {
"method": "POST",
"url": "Condition"
}
}
]
}
ERROR:
{
"resourceType": "OperationOutcome",
"issue": [
{
"severity": "error",
"code": "not-found",
"details": {
"text": "Invalid url: /4_0_0/"
}
}
]
}
Following up on this question, I don't understand why I can't get what I look for: the image of a Wikipedia Article, that of Le Monde.
This request gives me the claims I expect:
https://www.wikidata.org/w/api.php?action=wbgetclaims&entity=Q12461&property=P154
{
"claims": {
"P154": [
{
"mainsnak": {
"snaktype": "value",
"property": "P154",
"hash": "5566a330c25e15b3997363b88367fbf3e2fda8b1",
"datavalue": {
"value": "Le Monde.svg",
"type": "string"
},
"datatype": "commonsMedia"
},
"type": "statement",
"id": "q12461$FFF271FE-B26C-4A90-B787-9115024C7F21",
"rank": "normal"
}
]
}
}
With http://www.md5.cz/ I can get the md5 checksum of Le Monde.svg which is 92c8a6c9e4755bd38fb7b9c8ac8fcdb6
However, https://upload.wikimedia.org/wikipedia/commons/9/92/Le%20Monde.svg returns an error:
File not found: /v1/AUTH_mw/wikipedia-commons-local-public.92/9/92/Le%20Monde.svg.svg
Any idea what I'm doing wrong here?
I am trying to upload my intent everything is working fine, i am writing script in V2 and everything works but for parameter webhookState data type is enum ( [here] ) and we have to enter following of the three values ( [here][1]) now when i enter any one and try to upload it shows.
" Unable to load file: SyntaxError: Unexpected token W in JSON at position 98 "
now when I pass WEBHOOK_STATE_ENABLED(or any one) in quotes code uploads successfully (because as per my knowledge it treats it as string and gets executed) and intent is created for my agent but webhook remains off and also training phrases are not there, i am certain that the parameter webhookState is not being activated when i pass in quotes(because of above mentioned reason) Same is the case with rest, like when i try to put in type of training phrases.
{
"name": "Warehouse_Management",
"displayName": "Warehouse_Management",
"webhookState": "WEBHOOK_STATE_ENABLED_FOR_SLOT_FILLING" ,
"priority": 50000,
"isFallback": false,
"mlDisabled": false,
"trainingPhrases": [
{
"name":"Try1" ,
"type": "EXAMPLE",
"parts": [
{
"text": "for",
"userDefined": true
},
{
"text": "warehouse",
"entityType": "#Properties",
"alias": "Properties",
"userDefined": true
},
{
"text": "management",
"userDefined": true
}
]
},
{
"name":"Try2" ,
"type": "EXAMPLE",
"parts": [
{
"text": "i want app for ",
"userDefined": true
},
{
"text": "warehouse",
"alias": "Properties",
"entityType": "#Properties",
"userDefined": true
}
]
}
],
"outputContexts": [
{
"name": "Yes",
"lifespanCount": 2
},
{
"name": "No",
"lifespanCount": 2
},
{
"name": "Device_Integration",
"lifespanCount": 2
}
],
"resetContexts": false,
"parameters": [
{
"name": "Properties",
"displayName": "Properties",
"value": "$parameter_name",
"entityTypeDisplayName": "#Properties",
"mandatory": false,
"isList": true
}
],
"messages": [
{
"text":"This is sample response"
}
],
"rootFollowupIntentName": "root",
"parentFollowupIntentName": "parent"
}
Please NOTE that in the attached Json i have put it in quotes so it would get successfully executed and will create intent.
In order for it to be valid JSON, the enum value should be wrapped in quotes. It's expecting the enum value as a String.
Question:
Is there a plain or native javascript way to validate a JSON script against a JSON schema?
I have found lots of libraries on Github, but no native/plain solution. Does EcmaScript not have a specification for this? and do none of the browsers (or nodejs) have a way to validate JSON natively?
Context of Question:
I have a very complex schema that I developed.
It is supposed to work along with a script that requires that the JSON data passed into it to comply with the schema.
Simply, no.
There was something called JSON Schema, which was an Internet Draft which expired in 2013. Internet Drafts are the first stage to producing an Internet Standard. See more about it at the official site, as it seems to potentially still be actively developed, although it is not (to my knowledge) in widespread use.
An example of the schema:
{
"$schema": "http://json-schema.org/schema#",
"title": "Product",
"type": "object",
"required": ["id", "name", "price"],
"properties": {
"id": {
"type": "number",
"description": "Product identifier"
},
"name": {
"type": "string",
"description": "Name of the product"
},
"price": {
"type": "number",
"minimum": 0
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"stock": {
"type": "object",
"properties": {
"warehouse": {
"type": "number"
},
"retail": {
"type": "number"
}
}
}
}
}
will validate this example JSON:
{
"id": 1,
"name": "Foo",
"price": 123,
"tags": [
"Bar",
"Eek"
],
"stock": {
"warehouse": 300,
"retail": 20
}
}
There seems to be at least one pure JS solution now (https://github.com/tdegrunt/jsonschema) available via npm (https://www.npmjs.com/package/jsonschema). I am not a contributor, although I appreciate their work.
I've tried 100 different things, and spend days looking through Google and Stackoverflow, but I can't find a solution to this problem. Everything I call after the body of this API response returns undefined!
The response from Facebook SDK looks like this:
[
{
"body": "[
"data": [
{
"name": "Larry Syid Wright",
"administrator": false,
"id": "xxx"
}, {
"name": "Melissa Long Jackson",
"administrator": false,
"id": "xxx"
}, {
"name": "Charlotte Masson",
"administrator": false,
"id": "xxx"
}
],
"paging": {
"next": "url"
}
]"
},{
"body": "{
"data": [
{
"id": "xxx_xxx",
"message": "In honor of Halloween, how many of you have your own ghost stories? Who believes in ghosts and who doesn't?",
"type": "status",
"created_time": "2014-10-31T20:02:01+0000",
"updated_time": "2014-11-01T02:52:51+0000",
"likes": {
"data": [
{
"id": "xxx",
"name": "Joe HerBatman Owenby Jr."
}
],
}
"paging": {
"cursors":
{
"after": "xxx",
"before": "xxx"
}
}
}
},{
"id": "xxx_xxx",
"from": {
"id": "xxx",
"name": "Jessica Starling"
},
"message": "Watching the "Campaign" and I can't help but notice what a fantastic job they did (Will ferrell and all) with that North Carolina accent! Ya'll know we sound different than other southern states ;)",
"type": "status",
"created_time": "2014-11-01T02:36:21+0000",
"updated_time": "2014-11-01T02:36:21+0000",
"likes": {
"data": [
{
"id": "xxx",
"name": "Scott Williams"n
}
]
}
}
],
"paging": {
"previous": "xxx",
"next": "xxx"
}
}"
}
]
This response is from a batch call. If I call them separately, I can easily iterate through the responses, and get everything from them. When I call them in the batch though, I can't get past "body", and I need to use a batch call.
console.log(response[0].body); will return the object inside the body of the first part of the response, but console.log(response[0].body.data); returns undefined. I just don't get it. This should be simple but it's like there's a lock on the door and I don't have the right key.
I normally have no issue iterating through objects, so I don't need a generalized answer. I need help seeing whatever it is here that I don't see. Why does the console show undefined when I call anything after the body, and what do I need to be doing to get any of these values?
That JSON contains nested JSON. body seems to be a string. Use
var body = JSON.parse(response[0].body);
The values from the body are just strings.which are embedded as json.So firstly you would need to parse them using JSON.parse.
The code would be like
var body = JSON.parse(response[0].body);