You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by stuntgirl <fa...@hotmail.com> on 2013/04/19 06:16:51 UTC

Output from running Java in Beanshell | receiving only 'class ${classname}'

Hi All, 

I really hope you can help. 

I bashed out a piece of Java code to do what I need to do. In Eclipse, it
runs like a dream.
I copy and pasted the code from Eclipse into a Beanshell Sampler. 
However, everytime I run my JMeter script, all I get is:

class ${classname} in the Response Data tab.

I'm actually expecting some kind of output. For context, my Java should log
into a GMail account, retrieve a specific email (based on subject), open it,
and interpret the contents of the email.

Can I expect the output from Eclipse to be the same in JMeter? Am I doing
something wrong?

Regards,
stuntgirl



--
View this message in context: http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by stuntgirl <fa...@hotmail.com>.
Yup, got it! Works a treat. Thanks all.



--
View this message in context: http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716812.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by sebb <se...@gmail.com>.
On 29 April 2013 02:35, stuntgirl <fa...@hotmail.com> wrote:

> Thanks sebb, as always. RTFM eh?
>
> So how would one achieve an assertion based on this, then?
>
> I can see my result just fine in the console window. But I don't seem to be
> able to use a Response Assertion for this. I'm trying to extract a
> particular value and use it in a subsequent sampler.
>
> I saw  this
> <
> http://newspaint.wordpress.com/2013/01/15/using-the-jmeter-beanshell-sampler-to-write-to-the-response-data-tab-of-the-results-tree/
> >
> and assumed I would be able to print the result to the Response Data tab
> and
> be able to continue with my testing. I'm guessing this isn't the case?
>
>
Have you tried that? Looks correct to me.


> Apologies in advance for the moronic questions...
>
>
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716807.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>

Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by stuntgirl <fa...@hotmail.com>.
Thanks sebb, as always. RTFM eh?

So how would one achieve an assertion based on this, then?

I can see my result just fine in the console window. But I don't seem to be
able to use a Response Assertion for this. I'm trying to extract a
particular value and use it in a subsequent sampler.

I saw  this
<http://newspaint.wordpress.com/2013/01/15/using-the-jmeter-beanshell-sampler-to-write-to-the-response-data-tab-of-the-results-tree/>   
and assumed I would be able to print the result to the Response Data tab and
be able to continue with my testing. I'm guessing this isn't the case?

Apologies in advance for the moronic questions... 



--
View this message in context: http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716807.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by sebb <se...@gmail.com>.
On 29 April 2013 01:11, stuntgirl <fa...@hotmail.com> wrote:

> I think I might be getting somewhere. At least, I'm a step closer.
>
> Just to be clear - when I run this, can I expect that the output from this
> file appears in the response data (under view results tree)? I can see it
> displaying on the console window, but not within the JMeter GUI.
>
>
View Results Tree shows the output of samplers only.

In the case of BeanShell Sampler,

"The SampleResult ResponseData is set from the return value of the script.
Since version 2.1.2, if the script returns null, it can set the response
directly, by using the method SampleResult.setResponseData(data), where
data is either a String or a byte array. The data type defaults to "text",
but can be set to binary by using the method
SampleResult.setDataType(SampleResult.BINARY)."

See
http://jmeter.apache.org/usermanual/component_reference.html#BeanShell_Sampler

Standard output only goes to the console; it is not automatically captured
by JMeter.


>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716805.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>

Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by stuntgirl <fa...@hotmail.com>.
I think I might be getting somewhere. At least, I'm a step closer.

Just to be clear - when I run this, can I expect that the output from this
file appears in the response data (under view results tree)? I can see it
displaying on the console window, but not within the JMeter GUI.



--
View this message in context: http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716805.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by sebb <se...@gmail.com>.
On 23 April 2013 03:40, Mark Miller <ma...@gmail.com> wrote:

> I suggest that you post your code, verbatim, from the sampler. Just mask
> the parts specific to your mail account first.
>
>
The list does not allow attachments.
Also it's difficult to read inline code (the mailers tend to mangle it).

Please post somewhere public and send the link.


> Mark
>
>
> On Mon, Apr 22, 2013 at 8:34 PM, stuntgirl <fa...@hotmail.com> wrote:
>
> > AdrianS wrote
> > > Hello,
> > >
> > > No you shouldn't add every jar to the lib folder. Only those custom
> > > classes
> > > that your code requires. And if those jars have similar dependencies of
> > > their own. But other than this I can't be much of a help, can only tell
> > > you
> > > that every time we encountered similar issues, we used the IDE to
> search
> > > for the packages that we needed to build as jars and move them to
> > JMeter's
> > > lib. When this was done correctly, in beanshell, it worked just like it
> > > did
> > > in eclipse, if not, we had to tediously debug it.
> > >
> > > Adrian S
> >
> > OK maybe I have a older version of the javax.mail jar. However, I thought
> > I'd try with a Hello World (without external jar dependencies, obviously)
> > and I'm still getting 'class HelloWorld'.
> >
> >
> >
> >
> >
> >
> >
> > --
> > View this message in context:
> >
> http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716771.html
> > Sent from the JMeter - User mailing list archive at Nabble.com.
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> > For additional commands, e-mail: user-help@jmeter.apache.org
> >
> >
>
>
> --
> Mark Miller
> mark.o.miller@gmail.com
> [cell]    403.690.5169
> [home] 403.283.3974
>

Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by Mark Miller <ma...@gmail.com>.
I suggest that you post your code, verbatim, from the sampler. Just mask
the parts specific to your mail account first.

Mark


On Mon, Apr 22, 2013 at 8:34 PM, stuntgirl <fa...@hotmail.com> wrote:

> AdrianS wrote
> > Hello,
> >
> > No you shouldn't add every jar to the lib folder. Only those custom
> > classes
> > that your code requires. And if those jars have similar dependencies of
> > their own. But other than this I can't be much of a help, can only tell
> > you
> > that every time we encountered similar issues, we used the IDE to search
> > for the packages that we needed to build as jars and move them to
> JMeter's
> > lib. When this was done correctly, in beanshell, it worked just like it
> > did
> > in eclipse, if not, we had to tediously debug it.
> >
> > Adrian S
>
> OK maybe I have a older version of the javax.mail jar. However, I thought
> I'd try with a Hello World (without external jar dependencies, obviously)
> and I'm still getting 'class HelloWorld'.
>
>
>
>
>
>
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716771.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>


-- 
Mark Miller
mark.o.miller@gmail.com
[cell]    403.690.5169
[home] 403.283.3974

Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by stuntgirl <fa...@hotmail.com>.
AdrianS wrote
> Hello,
> 
> No you shouldn't add every jar to the lib folder. Only those custom
> classes
> that your code requires. And if those jars have similar dependencies of
> their own. But other than this I can't be much of a help, can only tell
> you
> that every time we encountered similar issues, we used the IDE to search
> for the packages that we needed to build as jars and move them to JMeter's
> lib. When this was done correctly, in beanshell, it worked just like it
> did
> in eclipse, if not, we had to tediously debug it.
> 
> Adrian S

OK maybe I have a older version of the javax.mail jar. However, I thought
I'd try with a Hello World (without external jar dependencies, obviously)
and I'm still getting 'class HelloWorld'.







--
View this message in context: http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716771.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by Adrian Speteanu <as...@gmail.com>.
Hello,

No you shouldn't add every jar to the lib folder. Only those custom classes
that your code requires. And if those jars have similar dependencies of
their own. But other than this I can't be much of a help, can only tell you
that every time we encountered similar issues, we used the IDE to search
for the packages that we needed to build as jars and move them to JMeter's
lib. When this was done correctly, in beanshell, it worked just like it did
in eclipse, if not, we had to tediously debug it.

Adrian S

Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by stuntgirl <fa...@hotmail.com>.
Many thanks, AdrianS.

I'm no Java developer, so please forgive my stupid questions...

>You can expect that if the dependencies of that code are imported into
>JMeter's lib folder.

So if all of the JARs that come standard with the jdk are present, I should
get this error? Did I get that right?

If I understand you correctly, all JARs that come bog standard with the jdk
should be in the /lib directory in order for my code to work? 

The only external JAR I'm using that's external to the standard ones that
come with every Java project I run in Eclipse is javax.mail.jar. So, should
I be copying ALL JARs into the lib directory (from the JRE system library)
or just javax.mail.jar?

Many thanks in advance,

stuntgirl.





--
View this message in context: http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716752.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by Adrian Speteanu <as...@gmail.com>.
Hi,

You can expect that if the dependencies of that code are imported into
JMeter's lib folder.

I've done that a few times and all errors were related to classpath and
libs missing. The problem with copy-pasting from an IDE appears when you
have to build the lib jars. If those libs have dependencies of their own,
and those are not in JMeter's classpath, it becomes difficult to debug. But
I don't know what to say about what you observed, it doesn't compute with
me.

Adrian S


On Fri, Apr 19, 2013 at 7:16 AM, stuntgirl <fa...@hotmail.com> wrote:

> Hi All,
>
> I really hope you can help.
>
> I bashed out a piece of Java code to do what I need to do. In Eclipse, it
> runs like a dream.
> I copy and pasted the code from Eclipse into a Beanshell Sampler.
> However, everytime I run my JMeter script, all I get is:
>
> class ${classname} in the Response Data tab.
>
> I'm actually expecting some kind of output. For context, my Java should log
> into a GMail account, retrieve a specific email (based on subject), open
> it,
> and interpret the contents of the email.
>
> Can I expect the output from Eclipse to be the same in JMeter? Am I doing
> something wrong?
>
> Regards,
> stuntgirl
>
>
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>

Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by stuntgirl <fa...@hotmail.com>.
Thanks sebb!

In all fairness, the mail reader sampler is great, but I find it a bit
clumsy. I'll preface this by saying I'm probably not using it correctly, but
I don't find it efficient when opening a large mailbox (the one I'm
searching through receives thousands of emails a day) and the fact that each
message becomes a child of the sampler in the results is cumbersome and
makes it impossible to assert/search what I'm after. I figured doing it in
Java was my best option as it allowed me to search for specific text,
extract it and get on with the testing, rather than downloading hundreds of
emails just to try to execute my test. 

Incidentally, the response data is actually class CheckEmail, i figured it
was easier to write it as a variable for the sake of this list, rather than
advertising my crappy classnames ;)

So if I compile my code as Java 1.4 and copy paste into a Beanshell Sampler,
I may have more luck you think?

Regards,

stuntgirl.






--
View this message in context: http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741p5716753.html
Sent from the JMeter - User mailing list archive at Nabble.com.

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


Re: Output from running Java in Beanshell | receiving only 'class ${classname}'

Posted by sebb <se...@gmail.com>.
On 19 April 2013 05:16, stuntgirl <fa...@hotmail.com> wrote:

> Hi All,
>
> I really hope you can help.
>
> I bashed out a piece of Java code to do what I need to do. In Eclipse, it
> runs like a dream.
> I copy and pasted the code from Eclipse into a Beanshell Sampler.
> However, everytime I run my JMeter script, all I get is:
>
> class ${classname} in the Response Data tab.
>
> I'm actually expecting some kind of output. For context, my Java should log
> into a GMail account, retrieve a specific email (based on subject), open
> it,
> and interpret the contents of the email.
>
>
Why not use the Mail sampler?


> Can I expect the output from Eclipse to be the same in JMeter?


Not necessarily; BeanShell is not exactly the same as Java.
Remember it does not support generics, so make sure Eclipse is set to
source level 1.4 at most.

Also variable references such as ${classname} are resolved by JMeter before
the script is passed to BeanShell


> Am I doing
> something wrong?
>
> Regards,
> stuntgirl
>
>
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/Output-from-running-Java-in-Beanshell-receiving-only-class-classname-tp5716741.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>