Service Virtualization

 View Only
  • 1.  Variable Substitution in binary JMS Payload

    Posted Jul 17, 2017 10:51 AM

    Hi

     

    We are using DevTest 9.1.0 for service virtualization. The use case here is asynchronous messaging (JMS).

    The model and the image of our VS are self-made (not using the recording option), based on RR data (XML files).

     

    What our VS has to do is the following:

    1) Receive JMS request message from input-queue

    2) Parse some (custom) JMS header properties from the request

    3) Identify the response XML file that corresponds to the request message (match style: operation)

    4) Substitute the {{…}} placeholders in the response XML payload by some of the parsed values

    5) Set some JMS header properties for the response (using some other parsed values)

    6) Send the response to an output-queue

     

    This is working all fine, we already managed to set up several VS this way.

     

    In the current use case we want to do the exact same thing, but the response message from the VS needs to be a BytesMessages now, instead of a TextMessage as before.

     

    So we started the same way we would for TextMessages, but now in the transactions tab of the image, we changed the content type of the body of the response to be “General=>Binary” instead of “XML=>XML Document”. Additionally, for the meta data of the response we changed the field “msg.type” from javax.jms.TextMessage to javax.jms.BytesMessage.

     

    This basically works, and the VS is responding with the binary equivalent of the response XML, as desired. However, the {{…}} placeholders in the XML payload are no longer replaced by content, but left as is in the response.

     

    We know the problem can’t be related to the variables and/or the values within the variables. This is because even if we take the exact same variable for a meta data field and within the payload, only the meta data one gets substituted. The one in the payload works for TextMessages, and stops working when we switch to Bytes (leaving all as is apart from the two modifications mentioned above).

     

    Our model is rather simple and (besides some irrelevant intermediate steps) basically just includes the steps Listen => VS Image Response Selection => Respond.

    Please note that we use the VSE Listen step instead of the JMS Send Receive step due to some external tools used in the automatic generation/deployment process of VS. Therefore the values that should be injected in the response payload typically come from lisa.jms.Recv.PropertyMap.<PropertyName>. But as mentioned above, the replacement works fine in the meta data and for TextMessages payload, so this should not be relevant to the problem.

     

    We really think that the problem is simply the fact that DevTest is unable to substitute variables in binary payload. Is this possible?

     

    Any suggestions how to fix this?

     

    The perfect solution for us would be to build the VS exactly the same way as we do for TextMessages and to then (probably in an additional step) explicitly transform the payload from XML to Binary and to overwrite the msg.type to javax.jms.BytesMessages just before actually sending the response (but after the substitution took place ofc). Is there a way to do this?

     

    Any other solution would be highly appreciated as well...

     

    Thank you very much!



  • 2.  Re: Variable Substitution in binary JMS Payload
    Best Answer

    Posted Jul 17, 2017 01:20 PM

    The short answer is we don't support that.  VSE generally treats binary responses as opaque and doesn't try to perform substitutions in them, so BytesMessage support was written with that in mind.

     

    You can work around this in two ways:

     

    1. Generate your VSM using the 'More Flexible' option.  This adds a 'Prepare Response' step that will take care of the substitutions.

     

    2. Inserting an 'Execute Script' step just before the 'Respond' step, containing the following code:

     

    list = testExec.getStateObject("lisa.vse.response");
    rsp = list.get(0);
    body = rsp.getBodyAsString();
    body = testExec.parseInState(body);
    rsp.setBody(body);

     

    The longer answer is I would have to think about how to modify our BytesMessage support to handle both text and binary.



  • 3.  Re: Variable Substitution in binary JMS Payload

    Posted Jul 18, 2017 03:50 AM

    Dear Kevin

     

    We just tried the second suggestion you made, and it works like a charm.

    And actually, this is exactly the “perfect” solution we were looking for, as we can work with the same base model for JMS-based VS and simply add the script step where needed.

     

    Thank you very much for the quick response and the useful insights!



  • 4.  Re: Variable Substitution in binary JMS Payload

    Posted Sep 28, 2017 07:59 PM

    Greetings Carine,

     

    I am also in the same situation, as stated above in your response I too added the script provided by Kevin after "VS Image Response Selection" and before "Respond" step .

     

    However I am getting the below error is displayed

     

    Any help would be highly appreciated.

     

    Thanks in advance.

     

    DevTest Server Console

    ============================================================================ | Error in Script ============================================================================ | Step:        Execute script (JSR-223) ---------------------------------------------------------------------------- | Message:     bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4 ---------------------------------------------------------------------------- | Trapped Exception: bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4 | Trapped Message:   javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4 ---------------------------------------------------------------------------- STACK TRACE javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4      at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:97)      at bsh.BshScriptEngine.eval(BshScriptEngine.java:61)      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)      at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:670)      at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:427)      at com.itko.lisa.test.UserScriptNode._execute(UserScriptNode.java:210)      at com.itko.lisa.test.UserScriptNode.execute(UserScriptNode.java:175)      at com.itko.lisa.test.TestNode.executeNode(TestNode.java:981)      at com.itko.lisa.test.TestCase.execute(TestCase.java:1283)      at com.itko.lisa.test.TestCase.execute(TestCase.java:1198)      at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1183)      at com.itko.lisa.test.TestCase.executeTest(TestCase.java:1127)      at com.itko.lisa.coordinator.Instance.run(Instance.java:204) Caused by: java.lang.NullPointerException      at java.lang.StringBuilder.<init>(StringBuilder.java:125)      at com.itko.lisa.test.TestExec.parseInState(TestExec.java:1967)      at com.itko.lisa.test.TestExec.parseInState(TestExec.java:1947)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:497)      at bsh.Reflect.invokeMethod(Reflect.java:166)      at bsh.Reflect.invokeObjectMethod(Reflect.java:99)      at bsh.Name.invokeMethod(Name.java:858)      at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)      at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)      at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)      at bsh.BSHAssignment.eval(BSHAssignment.java:77)      at bsh.Interpreter.eval(Interpreter.java:664)      at bsh.Interpreter.eval(Interpreter.java:758)      at bsh.Interpreter.eval(Interpreter.java:747)      at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:89)      ... 12 more ============================================================================

     

    VSM snapshot



  • 5.  Re: Variable Substitution in binary JMS Payload

    Posted Sep 28, 2017 08:01 PM

    Greetings Kevin,

     

     

    I am also in the same situation, as stated above in your response I too added the script after "VS Image Response Selection" and before "Respond" step .

     

    However I am getting the below error is displayed

     

    DevTest Server Console

    ============================================================================ | Error in Script ============================================================================ | Step:        Execute script (JSR-223) ---------------------------------------------------------------------------- | Message:     bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4 ---------------------------------------------------------------------------- | Trapped Exception: bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4 | Trapped Message:   javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4 ---------------------------------------------------------------------------- STACK TRACE javax.script.ScriptException: bsh.TargetError: Sourced file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : Method Invocation testExec.parseInState : at Line: 4 : in file: inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' : testExec .parseInState ( body )   Target exception: java.lang.NullPointerException  in inline evaluation of: ``list = testExec.getStateObject("lisa.vse.response");  rsp = list.get(0);  body = . . . '' at line number 4      at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:97)      at bsh.BshScriptEngine.eval(BshScriptEngine.java:61)      at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)      at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:670)      at com.itko.lisa.test.ScriptExecHandler.executeScript(ScriptExecHandler.java:427)      at com.itko.lisa.test.UserScriptNode._execute(UserScriptNode.java:210)      at com.itko.lisa.test.UserScriptNode.execute(UserScriptNode.java:175)      at com.itko.lisa.test.TestNode.executeNode(TestNode.java:981)      at com.itko.lisa.test.TestCase.execute(TestCase.java:1283)      at com.itko.lisa.test.TestCase.execute(TestCase.java:1198)      at com.itko.lisa.test.TestCase.executeNextNode(TestCase.java:1183)      at com.itko.lisa.test.TestCase.executeTest(TestCase.java:1127)      at com.itko.lisa.coordinator.Instance.run(Instance.java:204) Caused by: java.lang.NullPointerException      at java.lang.StringBuilder.<init>(StringBuilder.java:125)      at com.itko.lisa.test.TestExec.parseInState(TestExec.java:1967)      at com.itko.lisa.test.TestExec.parseInState(TestExec.java:1947)      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)      at java.lang.reflect.Method.invoke(Method.java:497)      at bsh.Reflect.invokeMethod(Reflect.java:166)      at bsh.Reflect.invokeObjectMethod(Reflect.java:99)      at bsh.Name.invokeMethod(Name.java:858)      at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)      at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)      at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)      at bsh.BSHAssignment.eval(BSHAssignment.java:77)      at bsh.Interpreter.eval(Interpreter.java:664)      at bsh.Interpreter.eval(Interpreter.java:758)      at bsh.Interpreter.eval(Interpreter.java:747)      at bsh.BshScriptEngine.evalSource(BshScriptEngine.java:89)      ... 12 more ============================================================================

     

    Any help would be highly appreciated.

     

    Thanks in advance.

     

     



  • 6.  Re: Variable Substitution in binary JMS Payload

    Posted Oct 02, 2017 06:35 AM

    Greetings Kevin,

     

    Any guidance would be of great help.

     

    Thanks in advance.



  • 7.  Re: Variable Substitution in binary JMS Payload

    Posted Oct 02, 2017 01:08 PM

    Greetings Kevin,

     

    Any guidance or help would be highly appreciated.

     

    Thanks in advance.