Am 09.05.19 um 07:21 schrieb Shyam Panjiyar:
> Hi,
>
>
> Getting below error :-
> Response code: 500
> Response message: org.apache.jorphan.util.JMeterException: Error invoking
> bsh method: eval    Sourced file: inline evaluation of: ``import
> org.apache.http.NameValuePair; import org.apache.http.client.utils.URLEnc .
> . . '' : TargetError
>
> Request :-
> import org.apache.http.NameValuePair;
> import org.apache.http.client.utils.URLEncodedUtils;
> import java.net.URI;
> import java.util.List;
> import java.lang.*;
> import java.util.*;
> import org.apache.commons.math3.util.Precision;
> try
> {
>  String SFinPlanIDGen = vars.get("323.0");
>  System.out.println("SFinPlanIDGen");
> int IFinPlanIDGen = Integer.parseInt("SFinPlanIDGen");
> int TFinPlanIDGen = Math.round(IFinPlanIDGen);
> int NFinPlanIDGen = Integer.valueOf(IFinPlanIDGen).intValue();
> System.out.println(NFinPlanIDGen);
> vars.put("FinPlanIDGenerated",NFinPlanIDGen);
> System.out.println(FinPlanIDGenerated);
> }
> catch (Exception ex){
>     log.warn("Error in my script", ex);
>     throw ex; // elsewise JMeter will "swallow" the above exception
> }
>
> Kindly help to resolve it.

I get other exceptions than you seem to get, so some general advise:

* Variables in JMeter should have meaningful names. "323.0" is IMHO not
a good name

* Variables that are not defined in JMeter will be reported back as the
name of the variable, so SFinPlanIDGen will probably be initialized with
"323.0" as a value

* Integer.parseInt(String) expects a value that can be parsed as an
integer. "SFinPlanIDGen" is not such a value. You probably wanted to
place the variable with the same name there: ... =
Integer.parseInt(SFinPlanIDGen);

* JMeter variables are String values by default. If you want to place
other objects as values, you have to use vars.putObject(String, Object)
instead of vars.put(String, Object)

* Don't use System.out.println. Use log.info or log.debug instead

* I had no problems with the exception, even when I removed the try
catch block

* BeanShell is not a good choice for your scripts. groovy is way better
(for complex scripts). jexl3 can be a good alternative for simple
expressions

* The above logic seems to be equivalent to "${__jexl3((${testVar} + 0.5
).intValue().toString())}" (Note that I haven't seen an easy way to
round numbers, so I emulated it)

* I don't know which version of JMeter, Java or OS you are using, so
things might behave differently on your installation

Felix


>
> Sincerely,
>
> Shyam Kishor
>
> +91-7506056770
>
>  
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@jmeter.apache.org
For additional commands, e-mail: user-h...@jmeter.apache.org

Reply via email to