Your right!
Setting the property to
beanshell.postprocessor.init=functions.bsh
did the trick.
I also had to switch my post processor from BSF to beanshell (which i
suppose is basically on the same thing since I was using the beanshell
language from the bsf post processor).

Thanks for you help

sebb-2-2 wrote:
> 
> On 07/11/2009, mwolfe38 <[email protected]> wrote:
>>
>>  Sorry maybe what I said was confusing.
>>  I was using a BSF PostProcessor which mentions a "prev" variable which I
>>  originally was using in a script right within jmeter, and it worked
>> fine..
>>  Problem was I needed to do that same thing over and over, so I figured
>> it
>>  would be better to put the logic into a function that would be available
>> to
>>  any beanshell script. So i made my own beanshell file with functions in
>> it,
>>  used the property:
>>  beanshell.function.init (as described in the documentation)
> 
> That won't work with a postprocessor, it's only for actual BeanShell
> function calls.
> You need
> 
> beanshell.postprocessor.init=etc
> 
>>  and referenced
>>  the file from a  user.properties file, and pointed it to my beanshell
>>  script. I got that working just fine but couldn't figure out how to pass
>> the
>>  prev variable to the script.
> 
> I don't think you need to - just reference the variable.
> 
>>  Originally I tried calling the function
>>  directly from the script, but that didn't work (btw, is there anyway to
>> do
>>  that without using the __BeanShell function?)
> 
> You can call functions directly.
> 
>>  It would sure be great if in the script section of the bsf postprocessor
>> if
>>  I could just call the function I created directly. Anyways, I figured
>> that
>>  the SampleResult value was the same thing as the prev variable in this
>> case,
>>  i was just kind of curious if I could use the variables exposed in the
>>  script section rather than just those exposed to the __BeanShell
>> function.
>>
> 
> You can,  but you need to use the correct init file ...
> 
>>
>>  sebb-2-2 wrote:
>>  >
>>  > On 06/11/2009, mwolfe38 <[email protected]> wrote:
>>  >>
>>  >>  After playing around with it and reading some more documentation I
>>  >> figured
>>  >>  out how to do it.
>>  >>  I needed to 1. Import the right package to use a SampleResult in my
>>  >> script
>>  >>  file:
>>  >>  import org.apache.jmeter.samplers.SampleResult;
>>  >>
>>  >>  print("Including user defined functions");
>>  >>
>>  >> wrapResponse(SampleResult  result, String prefix,String suffix) {
>>  >>         log.info("Calling wrapResponse");
>>  >>         encoding = result.getDataEncodingWithDefault();
>>  >>         String data = prefix + (new String(result.getResponseData()))
>> +
>>  >> suffix;
>>  >>         result.setResponseData(data.getBytes(encoding));
>>  >>  }
>>  >>
>>  >>
>>  >> Then I called it like this:
>>  >>
>>  >>  ${__BeanShell(wrapResponse(SampleResult\,"<tiqs>"\,"<tiqs>"))}
>>  >>
>>  >>  I'm not sure how I could have accessed the prev value that is set
>> for
>>  >> the
>>  >>  script, but the documentation said that there was a SampleResult
>>  >> variable
>>  >>  for the __BeanShell function and that did in fact work.
>>  >
>>  > The BeanShell function documentation does not mention "prev" at all:
>>  >
>>  > http://jakarta.apache.org/jmeter/usermanual/functions.html#__BeanShell
>>  >
>>  > However, "prev" is set for some of the BeanShell test elements - but
>>  > they are not functions...
>>  >
>>  >>
>>  >>
>>  >>
>>  >>  mwolfe38 wrote:
>>  >>  >
>>  >>  > I was able to get jMeter to include a file with beanshell
>> functions in
>>  >> it
>>  >>  > automatically by using the
>>  >>  > property:
>>  >>  > beanshell.function.init=BeanShellFunction.bshrc
>>  >>  >
>>  >>  > However, I have a function which I want to use that will take a
>>  >>  > SampleResult and do some modifications (basically its an xml
>> document
>>  >> but
>>  >>  > its not well formed in that it has multiple top level nodes, I
>> want to
>>  >>  > wrap it and modify it.. I've got all this working but I can't get
>> it
>>  >>  > working within a function).
>>  >>  >
>>  >>  > here is what I have:
>>  >>  > print("including functions");
>>  >>  > wrapResponse(SampleResult result, String prefix,String suffix, ) {
>>  >>  >       log.info("Calling wrapResponse");
>>  >>  >       encoding = result.getDataEncodingWithDefault();
>>  >>  >       String data = prefix + (new
>> String(result.getResponseData())) +
>>  >> suffix;
>>  >>  >       result.setResponseData(data.getBytes(encoding));
>>  >>  > }
>>  >>  >
>>  >>  > I know that this file is being included but i can't seem to pass
>> the
>>  >>  > result value to the function.
>>  >>  >
>>  >>  > This is within a BSF PostProcessor which has a prev variable which
>> has
>>  >> the
>>  >>  > response in it (like I said, i've verified this works when not in
>> a
>>  >>  > function).
>>  >>  >
>>  >>  > The string values pass just fine though..
>>  >>  >
>>  >>  > I'm calling it like this:
>>  >>  > ${__BeanShell(wrapResponse(prev\,"<tiqs>"\,"<tiqs>"))}
>>  >>  >
>>  >>  >
>>  >>  >
>>  >>  > Here is the error message:
>>  >>  >
>>  >>  > 2009/11/05 17:04:03 WARN  - jmeter.functions.BeanShell: Error
>> running
>>  >> BSH
>>  >>  > script org.apache.jorphan.util.JMeterException: Error invoking bsh
>>  >> method:
>>  >>  > eval  Sourced file: inline evaluation of:
>>  >>  > ``wrapResponse(prev,"<tiqs>","<tiqs>");'' : Undefined argument:
>> prev
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.util.BeanShellInterpreter.bshInvoke(BeanShellInterpreter.java:192)
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.util.BeanShellInterpreter.eval(BeanShellInterpreter.java:198)
>>  >>  >       at
>>  >> org.apache.jmeter.functions.BeanShell.execute(BeanShell.java:106)
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:143)
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.engine.util.CompoundVariable.execute(CompoundVariable.java:112)
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.testelement.property.FunctionProperty.getStringValue(FunctionProperty.java:89)
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.testbeans.TestBeanHelper.prepare(TestBeanHelper.java:69)
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:622)
>>  >>  >       at
>>  >>  >
>>  >>
>> org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:356)
>>  >>  >       at
>>  >> org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:243)
>>  >>  >       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:171)
>>  >>  >       ... 10 more
>>  >>  > Caused by: Sourced file: inline evaluation of:
>>  >>  > ``wrapResponse(prev,"<tiqs>","<tiqs>");'' : Undefined argument:
>> prev
>>  >> : at
>>  >>  > Line: 1 : in file: inline evaluation of:
>>  >>  > ``wrapResponse(prev,"<tiqs>","<tiqs>");'' : ( prev , "<tiqs>" ,
>>  >> "<tiqs>" )
>>  >>  >
>>  >>  >       at bsh.BSHArguments.getArguments(Unknown Source)
>>  >>  >       at bsh.BSHMethodInvocation.eval(Unknown Source)
>>  >>  >       at bsh.BSHPrimaryExpression.eval(Unknown Source)
>>  >>  >       at bsh.BSHPrimaryExpression.eval(Unknown Source)
>>  >>  >       at bsh.Interpreter.eval(Unknown Source)
>>  >>  >       at bsh.Interpreter.eval(Unknown Source)
>>  >>  >       at bsh.Interpreter.eval(Unknown Source)
>>  >>  >       ... 15 more
>>  >>  >
>>  >>  >
>>  >>
>>  >>  --
>>  >>
>>  >> View this message in context:
>>  >>
>> http://old.nabble.com/How-do-I-call-function-passing-in-script-variables-tp26225188p26225648.html
>>  >>
>>  >> Sent from the JMeter - User mailing list archive at Nabble.com.
>>  >>
>>  >>
>>  >> 
>> ---------------------------------------------------------------------
>>  >>  To unsubscribe, e-mail: [email protected]
>>  >>  For additional commands, e-mail: [email protected]
>>  >>
>>  >>
>>  >
>>  > ---------------------------------------------------------------------
>>  > To unsubscribe, e-mail: [email protected]
>>  > For additional commands, e-mail: [email protected]
>>  >
>>  >
>>  >
>>
>>
>> --
>>  View this message in context:
>> http://old.nabble.com/How-do-I-call-function-passing-in-script-variables-tp26225188p26238884.html
>>
>> Sent from the JMeter - User mailing list archive at Nabble.com.
>>
>>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: [email protected]
>>  For additional commands, e-mail: [email protected]
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/How-do-I-call-function-passing-in-script-variables-tp26225188p26250887.html
Sent from the JMeter - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to