Service Virtualization

 View Only
  • 1.  DevTest 10.1 - JSON DPH not available on response side ?

    Posted Nov 27, 2017 05:21 AM

    Hello,

     

    I'm trying to virtualize a json service.

    With DevTest 8.1, I have JSON DPH available on response side.

    Not with DevTest 10.1. Anybody knows why ?

     

    Benoit



  • 2.  Re: DevTest 10.1 - JSON DPH not available on response side ?

    Posted Nov 27, 2017 10:04 AM

    I am assuming the response in your VSI is in JSON format. What do you anticipate the Response-side JSON DPH is going to do for you?  

    The request-side JSON DPH is a helper for creating the input argument list that you see in the VSI. It works similar to the Soap and XML DPHs. About the only time one uses a response side DPH is when the response payload needs to be translated into a format different from what is in the VSI. (e.g., mapping an XML representation of a copybook back into the actual copybook format)  



  • 3.  Re: DevTest 10.1 - JSON DPH not available on response side ?

    Posted Nov 27, 2017 10:56 AM

    I was using the response side JSON DPH in order to translate the payload to XML.

    With XML payload, in vsi file, data content can be formated. 

    With JSON, the "format" action does not work...



  • 4.  Re: DevTest 10.1 - JSON DPH not available on response side ?

    Posted Nov 27, 2017 11:55 AM

    Ah, OK, I see.  

    If the VSI contains XML, perhaps you could add a Scriptable DPH to the response side to convert the XML back into JSON format. Based on the json-20140107.jar located in LISA_HOME\lib\shared, the code would use something like the following (pardon typos) :

     

    import org.json.JSONObject;

    import org.json.XML;
    int INDENT_FACTOR = 4;
    try {
    JSONObject xmlJSONObj = XML.toJSONObject( lisa_vse_response.get(0).getBodyAsString() );
    String jsonPrettyPrintString = xmlJSONObj.toString( INDENT_FACTOR );
    lisa_vse_response.get(0).setBodyText( jsonPrettyPrintString );
    } catch (JSONException je) {
    // leave response as XML and write exception info into the VSE log file
    _logger.info( "<<<" );
    _logger.info( "<<< Error Converting XML to JSON. Msg is:\r\n{}", je.toString() );
    _logger.info( "<<<");
    }

    Additionally, the code may need to cater for the VSI's HTML-based Stateful / Stateless Service Image Not Found responses. An SI Not Found response, might throw an exception since it is not XML-based unless you changed it in the VSI.



  • 5.  Re: DevTest 10.1 - JSON DPH not available on response side ?
    Best Answer

    Broadcom Employee
    Posted Nov 27, 2017 04:31 PM

    Side note...

     

    Here's why "format" on a JSON response sometimes doesn't work: If the response has a magic string of a numeric value - in other words the {{ }} notation - the document becomes invalid JSON (because double curly braces are illegal).  This behavior doesn't affect XML since double curly braces are legal.

     

    I recommend opening a support ticket.  Not being able to format JSON is a pain.

     

    --Mike



  • 6.  Re: DevTest 10.1 - JSON DPH not available on response side ?

    Posted Nov 27, 2017 05:16 PM

    Good point. If you were to use the code fragment you would need to call testExec.parseInState( ) passing the response to substitute the magic strings and dates.



  • 7.  Re: DevTest 10.1 - JSON DPH not available on response side ?

    Posted Nov 28, 2017 03:34 AM

    Case 00902683 opened.

     

    Thanks for the answers

     

    Benoit