I have a use cases to load JSON files and use them as templates, to create strings that I will later send as data wrapped in CloudEvents.
Is there an example somewhere that explains how to load the JSON files with Velocity and populate the template with appropriate values?
Related
I have array of test data json file in local machine. I am writing a test in postman and trying to compare the response against the test data. Instead of doing it in collection runner, is it possible to pass the test data into Tests and compare with the response?
This is not something that is currently supported in Postman:
https://github.com/postmanlabs/postman-app-support/issues/7210
Alternatively what you could do
Copy/paste content of file (assuming it's not huge) and read into a variable which you could then do a string comparison against.
Store the content of the file in an endpoint where you can request it in the pre-request script, save it to a variable then do string comparison.
Neither solution is pretty in my opinion but probably the best you can do.
Team,
I have service to register a user with certain data along with unique mail id and phone no in JSON file format as a body (for ex: registerbody.json).
Before Post call I am generating unique mail id , phone no and updating the same json file (registerbody.json) fields which is in the same folder where feature file locates. I see the file is updated with the required data during runtime.
I used read () method and performed POST request
Surprisingly read method is not taking updated JSON file instead it is reading old data in the registerbody.json file.
Do you have any idea on this, why it is picking up old data even though file is updated with the latest information?
Please assist me with this.
Karate uses the Java classpath, which is typically target/test-classes. So if you edit a file in src/test/java Karate won't see it unless it is copied. This copying is automatically done when you build / compile your code.
My suggestion is use target/ as a temp folder and then you can read using the file: prefix:
* def payload = read('file:some.json')
Before Post call I am generating unique mail id , phone no and updating the same json file (registerbody.json)
You are making a big mistake here, Karate specializes in updating JSON based on variables. I suggest you take 5 minutes and read this part of the docs VERY carefully: https://github.com/intuit/karate#reading-files
Especially the part about embedded expressions: https://github.com/intuit/karate#embedded-expressions
How to parse CCD/CDA document in adobe flex?
Is there any simple solution/Third party library to parse and show all the human readable part present in XML rather than iterating over each node and parsing it individually?
Now i am parsing it by iterating over each node and parsing meaning full data and showing it in UI.But iam not able to parse all the data for some XML document,since some of the XML have multiple children inside parent but some not,so need to check with all the scenario and need to do code accordingly? this creates lots of problem for me and issue in parser is not able fix at a time
What are the advantages of using a JSON string in the POST body as opposed to using key/value pairs in the POST body? It seems like there are a lot of API's out there that do it.
Example of what I mean: user={"username":"bob", "age":1} vs username=bob&age=1 in the POST form data.
When you use a JSON string, you just have to encode/decode your object and are ready to go. This especially useful when using multiple platforms.
Also, when you want to add new values/fields to your request, you just add it to the JSON object, instead of having to add extra validations in multiple files, possibly breaking code already works.
Another thing I can think of is that when using JSON you can code one single component with the only purpose of send/receive data, where you declare the function that will receive the decoded JSON and do whatever it wants with it. That way, you don't repeat code and let every function/class/file/whatever do the specific functionality it's meant to.
I'm trying to create a XML data feed with dotCMS. I can easily output the correct XML document structure in a .dot "page", but the http headers sent to the client are still saying that my page contains "text/html". How can I change them to "text/xml" or "application/xml"?
Apparently there's no way to do it using the administration console. The only way I found is to add this line of (velocity) code
$response.setHeader("Content-Type", "application/xml")
to the top of the page template.
Your solution is the easiest. However there are other options that are a bit more work, but that would prevent you from having to use velocity to do the XML generation, which is more robust most of the time.
DotCMS uses xstream to generate XML files (and vise versa). You could write a generic plugin to use this as well.
An JSONContentServlet exists in dotCMS that takes a query and generates json or xml (depending on your parameters). It is not mapped on a servlet by default, but that is easy to add.