0

Hey I'm doing some beanshell scripting for a web application in jmeter. I've written quite a few jmeter scripts with beanshell embedded already and for some reason this one keeps giving me errors about my Integer.parseInt() method invocation.

Here's the error:

2014/06/27 10:08:58 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval Sourced file: inline evaluation of: import java.io.*; import java.util.*; int containerCount = 0; int secondVal = . . . '' : Method Invocation Integer.parseInt 2014/06/27 10:08:58 WARN - jmeter.modifiers.BeanShellPreProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of:import java.io.; import java.util.; int containerCount = 0; int secondVal = . . . '' : Method Invocation Integer.parseInt

All of my Integer.parseInt() invocations are listed below and they all seem pretty legitimate to me, if anyone's a beanshell expert and could help me identify the error, that'd be awesome, Thanks!

int containerCount = 0;
int secondVal = 0;
int BPNumSelected = 0;  //Branch Plant only is in response page with more than one container, in the site shipment but must be initialized to something here.
boolean mult = false;   //Boolean to see if the site shipment has more than one container

String ScontainerCount= vars.get("availableQty_matchNr");
String SsecondVal = vars.get("secondVal");




    if(ScontainerCount!=null)
        containerCount = Integer.parseInt(ScontainerCount); //refers to the number of containers in that site shipment
    if(SsecondVal!=null)
        secondVal = Integer.parseInt(SsecondVal); //A weird value that is passed in the parameter name after selectedLotID, 


    if(vars.get("BPNumSelected")==null){
        vars.put("BPNumSelected","0");
    }

    if(containerCount>1){
    String SBPNumSelected = vars.get("BPNumSelected");
    BPNumSelected = Integer.parseInt(SBPNumSelected); //gets the branch plant ID if more than one container
    mult = true;
    }

and also...

SlocPackedQtyValue = vars.get("locPackedQtyValue");
SavailQtyNoComma = vars.get("availQtyNoComma");

        if(vars.get("locPackedQtyValue")!=null)
            packedQtyVal = Integer.parseInt(SlocPackedQtyValue);
        if(vars.get("availQtyNoComma")!=null)
            availableRoom = Integer.parseInt(SavailQtyNoComma);
kevlar924
  • 55
  • 1
  • 1
  • 6
  • EDIT: it repeats the error for all threads – kevlar924 Jun 27 '14 at 17:20
  • Were you able to solve this problem by chance? I've same problem which I asked at http://stackoverflow.com/questions/24462367/parsing-string-to-integer-in-beanshell-sampler-in-jmeter – TechCrunch Jun 28 '14 at 00:15
  • 1
    By double checking that all Strings had values at the time of the method call, and by double checking that all Strings were declared outside of any loops or anything like that. Seems a little overly cautious to me. I'd use olyv's answer below, that '${}' assignment worked as well for me in beanshell. – kevlar924 Jul 09 '14 at 19:00

2 Answers2

2

Try to use just packedQtyVal = ${locPackedQtyValue} without Integer.parseInt() method. It works for me in Jmeter 2.11 in BeanShell and BSF processors.

olyv
  • 3,699
  • 5
  • 37
  • 67
  • 1
    Thanks, I just tried it out in a different scenario and it functions, very nice considering beanshell hates Integer.parseInt – kevlar924 Jul 09 '14 at 18:58
0

You can use valueOf() instead of parseInt()

String getNoofOrdersCount = vars.get("getTotalNumberOfOrders");
int ngetNoofOrdersCount = Integer.valueOf(getNoofOrdersCount).intValue();