You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2003/11/06 01:28:47 UTC
cvs commit: jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/sampler BeanShellSampler.java
sebb 2003/11/05 16:28:47
Modified: src/protocol/java/org/apache/jmeter/protocol/java/sampler
BeanShellSampler.java
Log:
Added Parameter field; pass in SampleResult object; handle null response from script
Revision Changes Path
1.2 +23 -17 jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java
Index: BeanShellSampler.java
===================================================================
RCS file: /home/cvs/jakarta-jmeter/src/protocol/java/org/apache/jmeter/protocol/java/sampler/BeanShellSampler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- BeanShellSampler.java 14 Oct 2003 00:02:56 -0000 1.1
+++ BeanShellSampler.java 6 Nov 2003 00:28:46 -0000 1.2
@@ -64,6 +64,7 @@
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jorphan.logging.LoggingManager;
+import org.apache.jorphan.util.JOrphanUtils;
import org.apache.log.Logger;
/**
@@ -78,6 +79,7 @@
public static final String FILENAME = "BeanShellSampler.filename"; //$NON-NLS-1$
public static final String SCRIPT = "BeanShellSampler.query"; //$NON-NLS-1$
+ public static final String PARAMETERS = "BeanShellSampler.parameters"; //$NON-NLS-1$
private Interpreter bshInterpreter;
@@ -89,16 +91,6 @@
bshInterpreter=null;
}
}
-
- public void setFilename(String newFilename)
- {
- this.setProperty(FILENAME, newFilename);
- }
- public String getFilename()
- {
- return getPropertyAsString(FILENAME);
- }
-
/**
* Returns a formatted string label describing this sampler
@@ -115,6 +107,16 @@
{
return this.getPropertyAsString(SCRIPT);
}
+
+ public String getFilename()
+ {
+ return getPropertyAsString(FILENAME);
+ }
+
+ public String getParameters()
+ {
+ return getPropertyAsString(PARAMETERS);
+ }
public SampleResult sample(Entry e)// Entry tends to be ignored ...
{
@@ -133,11 +135,12 @@
res.setSamplerData(fileName);
}
-
-
//TODO - set some more variables?
bshInterpreter.set("Label",getLabel());
bshInterpreter.set("FileName",getFilename());
+ bshInterpreter.set("SampleResult",res);
+ bshInterpreter.set("Parameters",getParameters());// as a single line
+ bshInterpreter.set("bsh.args",JOrphanUtils.split(getParameters()," "));
// Set default values
bshInterpreter.set("ResponseCode","200"); //$NON-NLS-1$
@@ -151,11 +154,14 @@
} else {
bshOut = bshInterpreter.source(fileName);
}
-
-
-
- res.setResponseData(bshOut.toString().getBytes());
+ String out;
+ if (bshOut == null) {// Script did not return anything...
+ out="";
+ } else {
+ out = bshOut.toString();
+ }
+ res.setResponseData(out.getBytes());
res.setDataType(SampleResult.TEXT);
res.setResponseCode(bshInterpreter.get("ResponseCode").toString());//$NON-NLS-1$
res.setResponseMessage(bshInterpreter.get("ResponseMessage").toString());//$NON-NLS-1$
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org