Service Virtualization

Expand all | Collapse all

Help! With DevTest 9.1, getting java.lang.ClassCastException:

  • 1.  Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 06-30-2016 04:32 PM


    Hi all,

     

    I have been using the previous versions of DevTest/LISA 7.5 and 8 with no problems whenever I write a custom Java Script Step. Usually it's because I want to grab some value from a Web Services request (usually SOAP). Here is my simple code below:

     

    import com.itko.lisa.vse.stateful.model.Request;

    import com.itko.util.ParameterList;

    import com.itko.lisa.VSE;

    try

    {

         //testExec.setStateValue("newRefID", "blah blah");

     

        Request reqRequest = (Request) testExec.getStateValue("lisa.vse.request");

        ParameterList plArguments = reqRequest.getArguments();

        String PermID =  plArguments.getParameterValue("CustId_CustPermId");

      

        testExec.setStateValue("newRefID", PermID);

        return true;

      

    }

    catch (Exception err) {

        testExec.log("Exception occurred while trying to retrieve service request", "Details ::: " + err.toString());

        return false; 

    }

     

    Please note the first line is commented out, I used it previously for testing and it will work perfectly fine when un-commented out. (   {{newRefID}} is successfully replaced with "blah blah" in the response ).

    Currently, when I run ITR, there will be a response, but my {{newRefID}} remains unchanged and is displayed as {{newRefID}} instead of the request parameter. When I check the test events in the Java Script I see the error message below:

     

    Details ::: java.lang.ClassCastException: Cannot cast java.lang.String to com.itko.lisa.vse.stateful.model.Request

     

    I believe that once I have "Request reqRequest = (Request) testExec.getStateValue("lisa.vse.request");" it actually just throws an exception and gets caught internally, not allowing the lines afterwards to be executed. On a side note, it doesn't matter if I had the (Request) type cast there or not, either way does not work in 9.1.

     

    What has changed in 9.1? I have been using this (and very similar) code in previous versions and I have never had this issue. Is there a new way I should be grabbing parameters?



  • 2.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 06-30-2016 05:14 PM

    Rather than using getStateValue (since it returns a string object in this case:

    Request reqRequest = (Request) testExec.getStateValue("lisa.vse.request");

    ParameterList plArguments = reqRequest.getArguments();

     

    Can you try referencing the request this way:

    ParameterList plArguments = lisa_vse_request.getArguments();



  • 3.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 07-04-2016 11:22 AM

    Hi Joel, thanks for your reply. I tried using the line you provided instead of what I used, but it doesn't seem to work as I get a new error that just stops the ITR execution all together. It gives me this error:

     

    Error in method invocation: Method getArguments() not found in class'java.lang.String' : at Line: 20 : in file: inline evaluation of: ``import com.itko.lisa.vse.stateful.model.Request;  import com.itko.util.Parameter . . . '' : lisa_vse_request .getArguments ( )

     

    I believe that the lisa_vse_request (I also tried lisa.vse.request) is somehow not inherently a Request object and so you can't just call .getArguments(). Perhaps the request really does come in as a String now since DevTest thinks it belongs to class java.lang.String. However, please do take my assumption with a grain of salt as I am still not quite experienced with the internal workings of DevTest. Please correct me if my understanding is wrong.



  • 4.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 07-01-2016 08:14 AM

    technically, shouldn't it have always been

     

    Request reqRequest = (Request) testExec.getStateObject("lisa.vse.request");

     

    cause you want a pointer to the object, you don't want a conversion (value) of where the pointer points.



  • 5.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 07-04-2016 11:31 AM

    Hi sdetweil2, thanks for your reply. Most of my previous LISA (7.5 or 8.0) services I made in the past used .getStateValue, and in fact, most didn't even have the (Request) typecasting used. However, I did try your syntax, and it seems to be valid syntax; but it has made no difference to the error. I still get the exact same problem and error message as if I used getStateValue. Thanks again for the suggestion.



  • 6.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 07-04-2016 11:35 AM

    Is your VS model of type 'More flexible'?

    I suspect you can use your code only with 'More efficient' type VS models.



  • 7.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 07-04-2016 01:53 PM

    No, my VS model is "More Efficient".



  • 8.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 07-05-2016 09:44 AM

    In 99.9% of cases, either code fragment above should have worked.  Perhaps, we need to widen the search area as to why the error. 

     

    If you copy/pasted your logic, make sure the quotes, dashes, and such are ASCII and not Microsoft characters.

     

    Where in your model is the step with your code?  (i.e., before Listen, after Responder, between Listen / Responder step, part of a Scriptable DPH, etc.)

     

    Since you are running in ITR mode, see if/when the lisa.vse.request object stops looking like a request and begins to look like a string.  Does your lisa.vse.request property look similar to the one below right before and after your step fires?  Launch Extended view to see the whole request. 

    __ITR.JPG 



  • 9.  Re: Help! With DevTest 9.1, getting java.lang.ClassCastException:

    Posted 07-06-2016 10:31 AM

    Hi Joel,

     

    Thanks for your reply. You are correct that this code works 99.9% of cases, usually with the Java Script right after the Listener when "most efficient" assertion is triggered. I recently rebuilt the vsm with the same code and it worked. It looks like the problem has been solved (see Bhavin's suggestion below). I must have accidently checked off "format step response as xml" by accident at some point. But thanks again for your help and suggestion.