Hi,
Following up from my thread yesterday, I'm trying to use a BeanShell function
in a Http Request Sampler that POSTs a form. This function transforms the
contents of a variable called viewstate containing a string grabbed from the
form in a RegEx Extractor attached to the Http Request Sampler that did a GET
of the form.
I've tried two versions of the function without success. A succint version
and a more verbose one. My Java is more than a little rusty, so I probably
made a newbie error somewhere. Here are the functions:
1st function was derived from print(java.net.URLEncoder.encode(viewstate,
"UTF-8"));
${__BeanShell(return java.net.URLEncoder.encode(vars.get("${viewstate}"),
"UTF-8"); )}
2006/02/08 17:10:33 ERROR - jmeter.util.BeanShellInterpreter: Error invoking
bsh method eval
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:136)
at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:172)
at org.apache.jmeter.functions.BeanShell.execute(BeanShell.java:114)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:125)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:93)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:195)
at org.apache.jmeter.config.Argument.getValue(Argument.java:121)
at
org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:140)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.getQueryString(HTTPSamplerBase.java:430)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.setupConnection(HTTPSampler.java:157)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:422)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:514)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:503)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)
at java.lang.Thread.run(Unknown Source)
Caused by: Parse error at line 1, column 34. Encountered: (
at bsh.Parser.generateParseException(Unknown Source)
at bsh.Parser.jj_consume_token(Unknown Source)
at bsh.Parser.ReturnStatement(Unknown Source)
at bsh.Parser.Statement(Unknown Source)
at bsh.Parser.BlockStatement(Unknown Source)
at bsh.Parser.Line(Unknown Source)
at bsh.Interpreter.Line(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
... 20 more
2006/02/08 17:10:33 WARN - jmeter.functions.BeanShell: Error running BSH
script org.apache.jorphan.util.JMeterException: Error invoking bsh method
eval
at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:147)
at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:172)
at org.apache.jmeter.functions.BeanShell.execute(BeanShell.java:114)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:125)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:93)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:195)
at org.apache.jmeter.config.Argument.getValue(Argument.java:121)
at
org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:140)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.getQueryString(HTTPSamplerBase.java:430)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.setupConnection(HTTPSampler.java:157)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:422)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:514)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:503)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:136)
... 15 more
Caused by: Parse error at line 1, column 34. Encountered: (
at bsh.Parser.generateParseException(Unknown Source)
at bsh.Parser.jj_consume_token(Unknown Source)
at bsh.Parser.ReturnStatement(Unknown Source)
at bsh.Parser.Statement(Unknown Source)
at bsh.Parser.BlockStatement(Unknown Source)
at bsh.Parser.Line(Unknown Source)
at bsh.Interpreter.Line(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
... 20 more
2006/02/08 17:10:33 ERROR - jmeter.protocol.http.sampler.HTTPSampler:
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://192.168.254.215/Login/Login.aspx
2006/02/08 17:10:33 ERROR - jmeter.protocol.http.sampler.HTTPSampler:
<html>
<head>
<title>Value was invalid.</title>
<style>
body
{font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p
{font-family:"Verdana";font-weight:normal;color:black;margin-top:
-5px}
b
{font-family:"Verdana";font-weight:bold;color:black;margin-top:
-5px}
H1
{ font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2
{ font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold;
color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1
color=silver></H1>
<h2> <i>Value was
...
The 2nd function:
${__BeanShell( vstate = vars.get("${viewstate}"); print(vstate); newViewstate
= java.net.URLEncoder.encode(vstate, "UTF-8"); print(newViewstate); return
newViewstate;)}
2006/02/08 16:54:28 ERROR - jmeter.util.BeanShellInterpreter: Error invoking
bsh method eval
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:136)
at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:172)
at org.apache.jmeter.functions.BeanShell.execute(BeanShell.java:114)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:125)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:93)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:195)
at org.apache.jmeter.config.Argument.getValue(Argument.java:121)
at
org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:140)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.getQueryString(HTTPSamplerBase.java:430)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.setupConnection(HTTPSampler.java:157)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:422)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:514)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:503)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)
at java.lang.Thread.run(Unknown Source)
Caused by: Parse error at line 1, column 81. Encountered: (
at bsh.Parser.generateParseException(Unknown Source)
at bsh.Parser.jj_consume_token(Unknown Source)
at bsh.Parser.Statement(Unknown Source)
at bsh.Parser.BlockStatement(Unknown Source)
at bsh.Parser.Line(Unknown Source)
at bsh.Interpreter.Line(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
... 20 more
2006/02/08 16:54:28 WARN - jmeter.functions.BeanShell: Error running BSH
script org.apache.jorphan.util.JMeterException: Error invoking bsh method
eval
at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:147)
at
org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:172)
at org.apache.jmeter.functions.BeanShell.execute(BeanShell.java:114)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:125)
at
org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:93)
at
org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:85)
at
org.apache.jmeter.testelement.AbstractTestElement.getPropertyAsString(AbstractTestElement.java:195)
at org.apache.jmeter.config.Argument.getValue(Argument.java:121)
at
org.apache.jmeter.protocol.http.util.HTTPArgument.getEncodedValue(HTTPArgument.java:140)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.getQueryString(HTTPSamplerBase.java:430)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.setupConnection(HTTPSampler.java:157)
at
org.apache.jmeter.protocol.http.sampler.HTTPSampler.sample(HTTPSampler.java:422)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:514)
at
org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:503)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:247)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at
org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:136)
... 15 more
Caused by: Parse error at line 1, column 81. Encountered: (
at bsh.Parser.generateParseException(Unknown Source)
at bsh.Parser.jj_consume_token(Unknown Source)
at bsh.Parser.Statement(Unknown Source)
at bsh.Parser.BlockStatement(Unknown Source)
at bsh.Parser.Line(Unknown Source)
at bsh.Interpreter.Line(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
at bsh.Interpreter.eval(Unknown Source)
... 20 more
2006/02/08 16:54:28 ERROR - jmeter.protocol.http.sampler.HTTPSampler:
java.io.IOException: Server returned HTTP response code: 500 for URL:
http://192.168.254.215/Login/Login.aspx
2006/02/08 16:54:28 ERROR - jmeter.protocol.http.sampler.HTTPSampler:
<html>
<head>
<title>Value was invalid.</title>
<style>
body
{font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
p
{font-family:"Verdana";font-weight:normal;color:black;margin-top:
-5px}
b
{font-family:"Verdana";font-weight:bold;color:black;margin-top:
-5px}
H1
{ font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
H2
{ font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
pre {font-family:"Lucida Console";font-size: .9em}
.marker {font-weight: bold; color: black;text-decoration: none;}
.version {color: gray;}
.error {margin-bottom: 10px;}
.expandable { text-decoration:underline; font-weight:bold;
color:navy; cursor:hand; }
</style>
</head>
<body bgcolor="white">
<span><H1>Server Error in '/' Application.<hr width=100% size=1
color=silver></H1>
<h2> <i>Value was
...
Can anybody spot obvious errors or point me to a working example of a
BeanShell function that uses a JMeter variable. I did look for an example in
the mailing list archive but didn't find one.
--
Qmediastream http://qmediastream.com
design, commerce, hosting, streaming, multimedia
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]