Please let me know the complete JAVA code which we can use in the VSM to convert JSON request to XML, for LISA 7.5.2
I am glad to hear that your problem has been resolved. If possible I would highly recommend to upgrade to the current latest version DevTest 9.0. That way you can avail not only this feature which is supported out-of-the box plus many additional new features and enhancements.
If your question has been answered to the satisfaction then please go ahead and mark this question as answered
FYI - Product has been renamed to DevTest starting version 8.0
If you visit json.org you may find multiple implementation of JSON. You can use the org.json one of the Google project for this purpose.
Download the compiled binaries from here
Java documentation on the usage of the library can be found here
In the VSM you can leverage Scriptable data protocol handler to do the translation from JSON to XML using the above library. Make sure the org.json jar file is copied to "hotDeploy" directory.
Sample pseudo code that you can use in Scriptable DPH
// Retrieve the request body
String jsonTxt = lisa_vse_request.getBodyText();
Construct a JSONObject from a source JSON text string.
JSONObject o = new JSONObject(jsonTxt);
//You can optionally add an additional root-element
String xmlResult = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><JSON2XML>";
//Translate JSON to XML
xmlResult += org.json.XML.toString(o) + "</JSON2XML>";
You will have to do DPH chaining by adding further either Generic XML Payload parser or XML Data Protocol to generate request arguments in the VSI.
Thanks Ashutosh. I will look into it and let you know in case of any issues!!
I kept the jar file in the hot deploy and used the below mentioned code in Scriptable Data Protocol
// Manipulate request body text
String theBody = lisa_vse_request.getBodyText();
JSONObject o = new JSONObject(theBody);
I ran the VSM in IT mode by hitting request from SOAP UI, but there was no property named vinit was created which should have the XML.
I got the warning stating as:-
Did not get a valid Request object so we ignore processing this transaction.
java.lang.RuntimeException: Exception evaluating script: Sourced file: inline evaluation of: ``import com.itko.util.ParameterList; import java.lang.String; // Manipulate req . . . '' : Typed variable declaration : Class: JSONObject not found in namespace : at Line: 10 : in file: inline evaluation of: ``import com.itko.util.ParameterList; import java.lang.String; // Manipulate req . . . '' : JSONObject
Please make sure you also import JSONObject.
It may also be good idea to restart LISA components just to be sure that this class is being loaded.
Thanks alot Mate. It is working fine. Your jar file made things very simple.
I have marked it as correct, which comes under Actions list. Is that you were saying to get it marked as answered?
If I want to run the same code in my test case and I am using scriptable data protocol, it doesnt convert JSON to XML. Is it that jar file will run only in VSM? Because when I am running in ITR, it not even runs that filter
Retrieving data ...