Service Virtualization

  • 1.  Unable to execute a Java Code in vsm or vsi

    Posted Sep 19, 2017 12:00 PM

    Hi ,

     

    I am trying to execute a java code that add extra space on the right side, if a string is not of defined width.

    code is:

    //right padding

    HOST_PROCESS_ID = String.format("%-" + 8 + "." + 8 + "s", HOST_PROCESS_ID);

    or

    HOST_PROCESS_ID = HOST_PROCESS_ID.format("%-" + 8 + "." + 8 + "s", HOST_PROCESS_ID);

     

    this is giving me exception in vsm(data protocol) and in vsi(matchscript).

     

    Please let me know if we can handle this by some other way as well.

     

    Why this: #calisa when encounter a series of spaces before or after a string in incoming request(#lisa_vse_request) , it applies trim on the string. Hence I have to add padding exclusively to get my string of original length.

     

     

    Please help, It's urgent.

     

    Thanks,

    Dinesh Kumar



  • 2.  Re: Unable to execute a Java Code in vsm or vsi

    Posted Sep 19, 2017 12:09 PM

    Hi,

     

    More Info:

    When executed using 'Java Script Step(deprecated)' or from 'Java Script Step JSR-223' giving below error:

     

    ============================================================================
    | Error in Script
    ============================================================================
    | Step:        Execute script (JSR-223)
    ----------------------------------------------------------------------------
    | Message:     Sourced file: inline evaluation of: ``import com.ca.sv.devtest.util.GenerateString; // Right-click to insert a sample  . . . '' : Error in method invocation: Method format( java.lang.String, java.lang.String ) not found in class'java.lang.String

     

    Thanks,

    Dinesh Kumar



  • 3.  Re: Unable to execute a Java Code in vsm or vsi

    Broadcom Employee
    Posted Sep 19, 2017 12:16 PM

    The exception gives the reason why the code is failing. The String.format method takes two input arguments (java.lang.String, java.lang.Object)

     

    https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#format(java.lang.String,%20java.lang.Object...)

     

    Please retry after casting the second argument to java.lang.Object



  • 4.  Re: Unable to execute a Java Code in vsm or vsi

    Broadcom Employee
    Posted Sep 19, 2017 12:42 PM

    Hi Dinesh,

     

    Try this:

     

    HOST_PROCESS_ID = String.format("%-8.8s", HOST_PROCESS_ID);

     

    When you tried to concatenated '8' it used the character with an ASCII value of 8 - not a textual '8'.

     

    --Mike



  • 5.  Re: Unable to execute a Java Code in vsm or vsi

    Posted Sep 19, 2017 01:27 PM

    Hi Mike and Prem,

     

    I still getting exception in ca lisa, while same code is working fine in eclipse.

    code:

    Eclipse:

    String IBC_MESSAGE_FORMAT= "RNBP";

     IBC_MESSAGE_FORMAT = String.format("%-8.8s", IBC_MESSAGE_FORMAT);

     

    Please look into it. What else modification did I need to do for CA LISA.

     

    Thanks,

    Dinesh Kumar



  • 6.  Re: Unable to execute a Java Code in vsm or vsi
    Best Answer

    Broadcom Employee
    Posted Sep 19, 2017 01:36 PM

    Hello Dinesh,

     

    If you add the following lines in a JSR 223 step of DevTest 9.5, it works fine - there are no errors.

     

    String IBC_MESSAGE_FORMAT= "RNBP";

     IBC_MESSAGE_FORMAT = String.format("%-8.8s", IBC_MESSAGE_FORMAT);

    return IBC_MESSAGE_FORMAT;

     

    Can you share the complete code of your VSM/VSI ? What is the version of DevTest you are using?



  • 7.  Re: Unable to execute a Java Code in vsm or vsi

    Posted Sep 19, 2017 01:46 PM

    Yes you are right,

     

    This is working fine in 9.5.1

    but I am currently working on v8.0.1 registry. facing error in this version.

     

    Thanks,



  • 8.  Re: Unable to execute a Java Code in vsm or vsi

    Broadcom Employee
    Posted Sep 20, 2017 01:17 PM

    Hi Dinesh,

     

    In that case, I know what the problem is.  That version of DevTest uses a BeanShell library that only supports JDK v1.4.  The String.format() method was introduced in JDK v1.5.

     

    Use something like this instead:

     

    IBC_MESSAGE_FORMAT = (IBC_MESSAGE_FORMAT + "        ").substring(0,8);

     

    --Mike



  • 9.  Re: Unable to execute a Java Code in vsm or vsi

    Posted Sep 20, 2017 02:13 PM

    Hi Mike,

     

    Thank you for the workaround. I have implemented a similar solution as below:

    1- Compare the incoming string with the original defined length.

    2- Add the difference with space character(" ") using for loop.

     

     

     

    Thanks,

    Dinesh Kumar