Manipulating JMeter JDBC connection fields in Java/beanshell code -


this followup using jmeter jdbc connection in java code. how use methods such getpassword() or getusername in datasourceelement class? want , modify username , password (among other things) jdbc connection configuration config.

i'm using same code in post, in beanshell sampler (which used in preprocessor element). think problem need datasourceelement object , have defined connection object. stuck.

my code:

import java.sql.connection; import org.apache.jmeter.protocol.jdbc.config.datasourceelement; print("\nbeanshell script beginning");  try {         connection con = datasourceelement.getconnection("jdbcconfig");         print(con);         string conpasswd = con.getpassword();         print(conpasswd);         if(con!=null)         con.close(); }  catch (throwable ex) {     log.error("something went wrong: ", ex); }  print("the end"); 

jmeter.log returns this:

error - jmeter.util.beanshellinterpreter: error invoking bsh method: eval   sourced file: inline evaluation of: ``import java.sql.connection; import org.apache.jmeter.protocol.jdbc.config.dataso . . . '' : typed variable declaration : error in method invocation: method getpassword() not found in class'com.sun.proxy.$proxy0' 

and console output returns connection object , stops @ error:

beanshell script beginning org.postgresql.jdbc4.jdbc4connection@7849e2a7 

it possible connection information using databasemetadata class like:

import java.sql.connection; import org.apache.jmeter.protocol.jdbc.config.datasourceelement; import java.sql.databasemetadata;  connection con = datasourceelement.getconnection("jdbcconfig"); databasemetadata meta = con.getmetadata(); string conusername = meta.getusername(); print(conusername); 

but don't think able password way ability cause immense security risks.

by way, can more friendly exception message in jmeter.log file surrounding beanshell code try/catch block like:

try {     //your code here } catch (throwable ex) {     log.error("something wrong", ex);     throw ex; } 

see how use beanshell: jmeter's favorite built-in component more information on using jmeter , java apis beanshell test elements


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -