You can read more on HTTP Perms in DOORS DXL Reference
Reading Cloudant documents
We know DOORS integration is not only outgoing to outside World, sometimes we need to get data into DOORS. Today I will show you a very short DXL script which will let you get data from external database. Because of ease of use and simple connectivity I decided to connect to Cloudant.
If you are not familiar with Cloudant, have a quick look at its Learning Center. In short Cloudant is a NoSQL database-as-a-service (DaaS) widely used with Bluemix Mobile and Cloud applications. But let's not jump into my future post and let me show you how can you read Cloudant documents from DOORS DXL.
Buffer getData(string username, password, account, db, doc) { Buffer buf = create buf = "https://" username ":" password "@" account ".cloudant.com/" db "/" doc HttpHeader h = create HttpResponse resp = HttpRequest(HttpGet, tempStringOf buf, null, h) delete h delete buf if (!null resp && resp.isOk) { HttpBody b = resp.body Buffer respBuf = create respBuf += b.value delete resp return respBuf } else { if (!null resp) { print "error getting response " resp.code"" delete resp } else { print "connection error" } } return null } Buffer b = getData("", "", "ae4582eb-c21f-4c1a-92b3-8da8589eea0c-bluemix", "doors9test", "aee5f8c1be606328ddedef1a546cb7ca") if (!null b) { print tempStringOf b delete b }I set read permissions on this Database so everyone should be able to get following JSON:
{"_id":"aee5f8c1be606328ddedef1a546cb7ca","_rev":"1-f44612cc036915a9f12f1afb7ba2fc37","title":"DOORS 9 connection test","description":"You shall read this ;)"}
Writing documents back to Cloudant
HttpHeader h = create add(h, "Content-Type", "application/json") // minimum required header add(h, "Accept", "application/json")
setValue perm is used to set HTTP body:
HttpBody body = create Buffer buf = create buf = {"_id":"aee5f8c1be606328ddedef1a546cb7ca","_rev":"1-f44612cc036915a9f12f1afb7ba2fc37"} setValue(body, buf) HttpResponse resp = HttpRequest(HttpPut, url, body, h)
That's how you can simply put and get data from the Cloudant!
Soon I will do some more fun stuff with DXL, Bluemix and IoT but for now...
Soon I will do some more fun stuff with DXL, Bluemix and IoT but for now...
Happy Halloween!
No comments:
Post a Comment
Note: only a member of this blog may post a comment.