Calling a batch script from a bsf preprocessor to get SHA1

View: New views
5 Messages — Rating Filter:   Alert me  

Calling a batch script from a bsf preprocessor to get SHA1

by mwolfe38 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a jmeter task that automates the process of uploading some file to a server. With this upload I have to send what the sha1 is of the file. Right now I do it manually using the command fciv -sha1 [filename]
which will print the sha1.
I would like to somehow capture this programatically and store it in a variable by using a bsf preprocessor rather than doing it manually and putting the value into a user defined variable.

Any ideas how i can get the sha1 of a file (either by calling a command from bsf or by using some library that can compute a sha1 in  a bsf language)?

Re: Calling a batch script from a bsf preprocessor to get SHA1

by Deepak Shetty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi
In java you could do something like
http://stackoverflow.com/questions/1589996/calculate-sha1-or-md5-hash-in-ireport
so use a BSH processor or Java Sampler and you can get the value

If you want to continue using command line you'd need to create a JAva/BSH
sampler and user Runtime.exec(), and interpret the response.
http://oreilly.com/pub/h/1092

regards
deepak


On Wed, Oct 21, 2009 at 11:07 AM, mwolfe38 <mwolfe38@...> wrote:

>
> I have a jmeter task that automates the process of uploading some file to a
> server. With this upload I have to send what the sha1 is of the file. Right
> now I do it manually using the command fciv -sha1 [filename]
> which will print the sha1.
> I would like to somehow capture this programatically and store it in a
> variable by using a bsf preprocessor rather than doing it manually and
> putting the value into a user defined variable.
>
> Any ideas how i can get the sha1 of a file (either by calling a command
> from
> bsf or by using some library that can compute a sha1 in  a bsf language)?
> --
> View this message in context:
> http://www.nabble.com/Calling-a-batch-script-from-a-bsf-preprocessor-to-get-SHA1-tp25997427p25997427.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@...
> For additional commands, e-mail: jmeter-user-help@...
>
>

Re: Calling a batch script from a bsf preprocessor to get SHA1

by mwolfe38 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok so if I choose to use a java sampler what would that look like. I've programmed in java for years but I'm just not sure how this works. Are there any examples you could point me to?

Thanks.
Deepak Shetty wrote:
Hi
In java you could do something like
http://stackoverflow.com/questions/1589996/calculate-sha1-or-md5-hash-in-ireport
so use a BSH processor or Java Sampler and you can get the value

If you want to continue using command line you'd need to create a JAva/BSH
sampler and user Runtime.exec(), and interpret the response.
http://oreilly.com/pub/h/1092

regards
deepak


On Wed, Oct 21, 2009 at 11:07 AM, mwolfe38 <mwolfe38@gmail.com> wrote:

>
> I have a jmeter task that automates the process of uploading some file to a
> server. With this upload I have to send what the sha1 is of the file. Right
> now I do it manually using the command fciv -sha1 [filename]
> which will print the sha1.
> I would like to somehow capture this programatically and store it in a
> variable by using a bsf preprocessor rather than doing it manually and
> putting the value into a user defined variable.
>
> Any ideas how i can get the sha1 of a file (either by calling a command
> from
> bsf or by using some library that can compute a sha1 in  a bsf language)?
> --
> View this message in context:
> http://www.nabble.com/Calling-a-batch-script-from-a-bsf-preprocessor-to-get-SHA1-tp25997427p25997427.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>

Re: Calling a batch script from a bsf preprocessor to get SHA1

by Deepak Shetty :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

http://jakarta.apache.org/jmeter/usermanual/component_reference.html#Java_Request
Basically implement the JavaSamplerClient interface, put the jar of your
class in lib and pass any parameters that you need

http://jakarta.apache.org/jmeter/api/org/apache/jmeter/protocol/java/sampler/JavaSamplerClient.html

I believe two samples are provide with the jmeter distribution for e.g.
http://www.docjar.com/html/api/org/apache/jmeter/protocol/java/test/JavaTest.java.html

You can return the value in SampleResult or extract it. There was a utility
as well that allowed you to get to the JmeterVariables object so that you
could set the hash value as a variable as well , but I dont remember it
right now (nor is google getting me the answer :) , i think its there
somewhere in the archive)

regards
deepak

On Thu, Oct 22, 2009 at 9:27 AM, mwolfe38 <mwolfe38@...> wrote:

>
> Ok so if I choose to use a java sampler what would that look like. I've
> programmed in java for years but I'm just not sure how this works. Are
> there
> any examples you could point me to?
>
> Thanks.
>
> Deepak Shetty wrote:
> >
> > Hi
> > In java you could do something like
> >
> http://stackoverflow.com/questions/1589996/calculate-sha1-or-md5-hash-in-ireport
> > so use a BSH processor or Java Sampler and you can get the value
> >
> > If you want to continue using command line you'd need to create a
> JAva/BSH
> > sampler and user Runtime.exec(), and interpret the response.
> > http://oreilly.com/pub/h/1092
> >
> > regards
> > deepak
> >
> >
> > On Wed, Oct 21, 2009 at 11:07 AM, mwolfe38 <mwolfe38@...> wrote:
> >
> >>
> >> I have a jmeter task that automates the process of uploading some file
> to
> >> a
> >> server. With this upload I have to send what the sha1 is of the file.
> >> Right
> >> now I do it manually using the command fciv -sha1 [filename]
> >> which will print the sha1.
> >> I would like to somehow capture this programatically and store it in a
> >> variable by using a bsf preprocessor rather than doing it manually and
> >> putting the value into a user defined variable.
> >>
> >> Any ideas how i can get the sha1 of a file (either by calling a command
> >> from
> >> bsf or by using some library that can compute a sha1 in  a bsf
> language)?
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Calling-a-batch-script-from-a-bsf-preprocessor-to-get-SHA1-tp25997427p25997427.html
> >> Sent from the JMeter - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: jmeter-user-unsubscribe@...
> >> For additional commands, e-mail: jmeter-user-help@...
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Calling-a-batch-script-from-a-bsf-preprocessor-to-get-SHA1-tp25997427p26013057.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@...
> For additional commands, e-mail: jmeter-user-help@...
>
>

Re: Calling a batch script from a bsf preprocessor to get SHA1

by mwolfe38 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I figured this one out, its extremely simple.
Basically just call the following function in a Beanshell script (make sure to include the function using the property beanshell.init.function=[filename-of-functions])

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.*;
String sha1FromFilename(String filename) {
        byte[] bytes = FileUtils.readFileToByteArray(new File(filename));
        return DigestUtils.shaHex(bytes);
}


Example:
put a file named user.properties in the location of your .jmx file
put the following line in that file:
beanshell.postprocessor.init=functions.bsh
(replace postprocessor with sampler/preprocessor depending on where you'll be calling this from).


Now in your functions.bsh file include the sha1FromFilename function mentioned above.

Now from your beanshell script just call that function, passing in the path to the filename which you want to compute the sha1 for.


mwolfe38 wrote:
I have a jmeter task that automates the process of uploading some file to a server. With this upload I have to send what the sha1 is of the file. Right now I do it manually using the command fciv -sha1 [filename]
which will print the sha1.
I would like to somehow capture this programatically and store it in a variable by using a bsf preprocessor rather than doing it manually and putting the value into a user defined variable.

Any ideas how i can get the sha1 of a file (either by calling a command from bsf or by using some library that can compute a sha1 in  a bsf language)?