Service Virtualization

Expand all | Collapse all

Number format exception while converting string to integer using groovy scripting

  • 1.  Number format exception while converting string to integer using groovy scripting

    Posted Sep 29, 2017 06:41 AM

    Hi ,

     

    In below code i am reading a value from database and then converting it into integer to convert it in IPV4 format. But getting exception - javax.script.ScriptException: java.lang.NumberFormatException: while running it in ITR

     

    String a = "{{START_IP}}"
    //a= "99993699"
    def startIP =Integer.valueOf(a)
    def IPString1 = ((startIP >> 24 ) & 0xFF) + "." + ((startIP >> 16 ) & 0xFF) + "." + ((startIP >> 8 ) & 0xFF) + "." +(startIP & 0xFF);

    return IPString1

     

    But if I test the script in Execute script(JSR-223) step using hardcode values it returns correct IP address. Can anyone please let me know is there anything I need to update to run it as Groovy script.



  • 2.  Re: Number format exception while converting string to integer using groovy scripting
    Best Answer

    Posted Oct 02, 2017 03:28 PM

    Try String a = testExec.getStateValue("START_IP") instead of String a = "{{START_IP}}".

     



  • 3.  Re: Number format exception while converting string to integer using groovy scripting

    Posted Oct 03, 2017 03:11 AM

    Thanks , it worked