Move HTTP Simple Table Server to groovy

160 views
Skip to first unread message

jmet...@gmail.com

unread,
Jan 20, 2022, 4:18:28 AM1/20/22
to jmeter-plugins
Hello,

About HTTP Simple Table Server, 
It uses Beanshell script which should be deprecated in favor of groovy according to https://jmeter.apache.org/usermanual/best-practices.html#bsh_scripting
I suggest adding groovy script similar to simple-table-server.bsh file
The script can be used in startup using jsr223.init.file property

Thank you
Ori Marko

Vincent Daburon

unread,
Jan 21, 2022, 8:58:13 AM1/21/22
to jmeter-plugins
Hi,
It 's not simple to change the init file from beanshell to groovy because when JMeter is try to launch automaticaly the beanshell init file corresponding to jmeter property : beanshell.init.file
beanshell.init.file=simple-table-server.bsh

In the source code of JMeter.java, you can see the code to run the beanshell file

// Should we run a beanshell script on startup?

String bshinit = JMeterUtils.getProperty("beanshell.init.file");// $NON-NLS-1$

if (bshinit != null){

log.info("Run Beanshell on file: "+bshinit);

try {

BeanShellInterpreter bsi = new BeanShellInterpreter();//bshinit,log);

bsi.source(bshinit);

} catch (ClassNotFoundException e) {

log.warn("Could not start Beanshell: "+e.getLocalizedMessage());

} catch (JMeterException e) {

log.warn("Could not process Beanshell file: "+e.getLocalizedMessage());

}
}

It is ONLY for beanshell NOT for groovy.
Not equivalent for groovy script.

So you can't replace the simple-table-server.bsh by a groovy code like simple-table-serve.groovy because JMeter will not look at this groovy file when it's starting.

You must add in the JMeter.java the code to run the groovy code and it is not a mandotory feature.

Groovy is preferred over Beanshell because it's faster and it's still evolving, but for the startup part of http STS, the code is read once and speed isn't an issue.


Regards.
Vincent DAB.

jmet...@gmail.com

unread,
Jan 30, 2022, 4:40:36 AM1/30/22
to jmeter-plugins
Same as Beanshell init file, Since 5.4 version, you can add JSR223 init file which can be used for startup part of STS
https://github.com/apache/jmeter/blob/85580b49ee2f06505129ebccac5d382e412c58e2/src/core/src/main/java/org/apache/jmeter/JMeter.java#L712

String jsr223Init = JMeterUtils.getProperty(JSR223_INIT_FILE);// $NON-NLS-1$


if (jsr223Init != null){


log.info("Running JSR-223 init script in file: {}", jsr223Init);

Vincent Daburon

unread,
Jan 31, 2022, 11:44:21 AM1/31/22
to jmeter-plugins
Hi,
you are right, i missed this feature in the
https://bz.apache.org/bugzilla/show_bug.cgi?id=62700 (september 2018)
In the JMeter 5.0 new feature

So i need to try to change the
simple-table-server.bsh to  simple-table-serve.groovy
and change the
beanshell.init.file=simple-table-server.bsh
to
jsr223.init.file=simple-table-serve.groovy

but you also need to change files to be upload with the sts plugin.
add file simple-table-serve.groovy in the ressources directory

Upgrade the documentation for the Http STS page

It could be also the good time to upgrade the nanoHttpServer version

Regards.
Vincent DAB.

Vincent Daburon

unread,
Jan 31, 2022, 12:09:39 PM1/31/22
to jmeter-plugins
Hi,
I made some modifications to declare the charset of the files read (INITFILE) or write (SAVE).
# For the name of the charset look at : https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html
# Colum Canonical Name for java.io API and java.lang API
# If you have accent in your csv file set charsetEncodingHttpResponse=UTF-8
jmeterPlugin.sts.charsetEncodingHttpResponse=UTF-8

# read (INITFILE) or write (SAVE) file with accent from text file in the charset like UTF-8 or ISO8859_15 or win1252
# All csv files need to be in the same charset encoding
#jmeterPlugin.sts.charsetEncodingReadFile=ISO8859_15
#jmeterPlugin.sts.charsetEncodingWriteFile=ISO8859_15


I could add this new feature (set the charset) and a the new groovy simple-table-server.groovy at the same time

I think also to add the possibility to load csv files at startup

something like this :
// read 3 csv files with comma separator, files are read from the directory set with : jmeterPlugin.sts.datasetDirectory
jmeterPlugin.sts.InitfileAtStartup=file1.csv,file2.csv,file3.csv
jmeterPlugin.sts.initFileAtStartupRegex=false

or 
// read all files with .csv extension declare with a regular expression
jmeterPlugin.sts.InitfileAtStartup=.*.csv
jmeterPlugin.sts. initFileAtStartupRegex=true

// read all files start with 2022 and  .csv extension declare with a regular expression
jmeterPlugin.sts.InitfileAtStartup=2022.*.csv
jmeterPlugin.sts. initFileAtStartupRegex=true

Regards.
Vincent DAB.

Vincent Daburon

unread,
Feb 1, 2022, 12:16:04 PM2/1/22
to jmeter-plugins
Hi,
I made some modifications (diff from 2.4 version) :

Help Http Simple Table Server (STS) Version : 2.5
From a data file (default: <JMETER_HOME>/bin/<data_file>) or from the directory set with jmeterPlugin.sts.datasetDirectory

The parameter enclosed in square brackets is [optional] and and the values in italics correspond to the possible values

Load file in memory:
http://hostname:port/sts/INITFILE?FILENAME=file.txt

Get one line from list:
http://hostname:port/sts/READ?FILENAME=file.txt&[READ_MODE=[FIRST,LAST,RANDOM]]&[KEEP=[TRUE,FALSE]]

Return the number of remaining lines of a linked list:
http://hostname:port/sts/LENGTH?FILENAME=file.txt

Add a line into a file: (GET OR POST HTTP protocol)
GET : http://hostname:port/sts/ADD?FILENAME=file.txt&LINE=D0001123&[ADD_MODE=[FIRST,LAST]]&[UNIQUE=[FALSE,TRUE]]
GET Parameters : FILENAME=file.txt&LINE=D0001123&[ADD_MODE=[FIRST,LAST]]&[UNIQUE=[FALSE,TRUE]]
POST : http://hostname:port/sts/ADD
POST Parameters : FILENAME=file.txt,LINE=D0001123,[ADD_MODE=[FIRST,LAST]],[UNIQUE=[FALSE,TRUE]]

Save the specified linked list in a file to the default location:
http://hostname:port/sts/SAVE?FILENAME=file.txt&[ADD_TIMESTAMP=[FALSE,TRUE]]

Display the list of loaded files and the number of remaining lines for each linked list:
http://hostname:port/sts/STATUS

Remove all of the elements from the specified list:
http://hostname:port/sts/RESET?FILENAME=file.txt

Show configuration:
http://hostname:port/sts/CONFIG

Shutdown the Simple Table Server:
http://hostname:port/sts/STOP

To load files at STS Startup use (optional) :

E.g : read 3 csv files with comma separator (not a regular expression), files are read from the directory set with jmeterPlugin.sts.datasetDirectory
jmeterPlugin.sts.initFileAtStartup=file1.csv,file2.csv,file3.csv
jmeterPlugin.sts.initFileAtStartupRegex=false

OR E.g : read all files with .csv extension declare with a regular expression (initFileAtStartupRegex=true) from directory set with jmeterPlugin.sts.datasetDirectory
jmeterPlugin.sts.initFileAtStartup=.+\.csv
jmeterPlugin.sts.initFileAtStartupRegex=true

Set the Charset to read, write file and send http response :

E.g : charset = UTF-8, ISO8859_15 or Cp1252 (Windows)
jmeterPlugin.sts.charsetEncodingHttpResponse=<charset> (Use UTF-8) in the http header add "Content-Type:text/html; charset=<charset>"
jmeterPlugin.sts.charsetEncodingReadFile=<charset> (set the charset corresponding to characters in the file)
jmeterPlugin.sts.charsetEncodingWriteFile=<charset>

and the
simple-table-server.groovy

I add the feature to load on startup some files in the STS in the simple-table-server.groovy and also in the jmeter-plugins-table-server-2.5.jar for CLI (simple-table-server.cmd or simple-table-server.sh)

Regards.
Vincent DAB.

Vincent Daburon

unread,
May 23, 2022, 3:43:56 AM5/23/22
to jmeter-plugins
Hi,
The STS Version 3.1 is release and add this feature to load files when STS startup and also groovy script replace the beanshell script.

And a new feature :
set jmeterPlugin.sts.daemon=true when you want launch the STS with the nohup linux command like process daemon, the STS will not waiting the <ENTER> key to stop.

Documentation
Reply all
Reply to author
Forward
0 new messages