Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Message Object Output

rvmseng
rvmseng Posts: 89
edited May 2018 in Virtualize

Hi every body,

Message Object Output does not exist for virtualization incoming request, I need convert input to BytesMessage, but I have faced with error (String cannot be cast to BytesMessage).

Note: I can use Message Object Output in SOATest but it does not exist in Parasoft virtualization, please refer to below link :
https://docs.parasoft.com/display/SOAVIRT9103/JMS#JMS-MessageObjectOutputsforClientsUsingJMS

please refer to my scenario:

Comments

  • keegan_chan
    keegan_chan Posts: 59 ✭✭

    Internally, Virtualize converts the message into a string. You can try using the String.getBytes(charsetName) method to get it as a byte array.

  • rvmseng
    rvmseng Posts: 89
    edited May 2018

    Dear Keegen,

    I used following code, but I still have error (java.lang.RuntimeException: javax.crypto.BadPaddingException: Decryption error)

    My Code:

     public String decrypt(Object input) throws JMSException {
       CryptographyUtil c = new CryptographyUtil();
       Charset charset = StandardCharsets.ISO_8859_1;
       byte[] bytes = ((String)input).getBytes(charset);
       return new String(c.decryptToByte(bytes));
     }
    

    I sure this error is belong to following line:
    byte[] bytes = ((String)input).getBytes(charset);

  • rvmseng
    rvmseng Posts: 89
    edited May 2018

    Also I tried utf8 and utf16 but issue exist yet
    My input request body was increapted by RSA
    And i have to decrypt it befor extracting data

    Please give me a solution

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    The exception you are seeing, javax.crypto.BadPaddingException, is most likely coming from the call to "decryptToByte" this may be due to the bytes not being correctly created using to proper charset. If you monitor the virtual asset you should be able to look at the incoming request to see what the actual charset of the message was. Then use that same charset in your script.

  • rvmseng
    rvmseng Posts: 89

    Dear williammccusker,

    I checked your solution but it isn't work.
    also I find that when I use "Message Object Output" request body length is 128 byte (fix), but when I convert input (Object) to "Sting" request body length changed dynamically and not fixed 128 byte.

    please help me.

  • rvmseng
    rvmseng Posts: 89

    When parasoft virtualization convert input to string it lost incoming request body data
    Please give me a solution
    Thanks

  • jakubiak
    jakubiak Posts: 795 admin

    I suspect that you are correct that the conversion to string is corrupting the bytes. You may be able to work around this by setting the default encoding in the preferences to ISO-8859-1, which would encode the bytes to String the same way that you are decoding them in your script. Doing this should preserve the bytes. You can set the character encoding in the Misc tab of the Parasoft preferences.

  • rvmseng
    rvmseng Posts: 89

    Dear jakubiak,

    I checked your solution but unfortunately it does not work, I don't understand why Parasoft virtualization don't have "Message Object Output"? or why it convert Object to String?

    please help me.

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi
    It looks like what happens is that for jms we default to using "UTF-8" as the encoding and it doesn't consider what was set in the preferences. This causes use to convert the bytes into a string for the extension tool.

    I am attaching a java example of using internal api to get the raw bytes from the incoming request. Could you try it out and let us know if that resolves the issue?

  • rvmseng
    rvmseng Posts: 89
    edited May 2018

    Dear Williammccusker,

    I have received "null pointer exception" for following line:

    Application.showMessage("--- StubBatchContext = " + sbctx.getClass().getName());
            Method getIncomingMessage = sbctx.getClass().getMethod("getIncomingMessage");
    

    I suppose this object "sbctx" is null.
    I print map value and it return following:

    {TEST_EXECUTION_LISTENER=[webtool.test.EventLoggerListener@1cebf1c]}

  • williammccusker
    williammccusker Posts: 642 ✭✭✭

    Hi, I just confirmed it works for 9.10.3 when I send a JMS message to the asset. How are you invoking that asset? JMS? Or some other protocol?

  • rvmseng
    rvmseng Posts: 89

    Dear williammccusker,

    Thank you so much, It is solved.
    you are very good supporter.

    thank you.