You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Coret Bob <b....@pinkroccade.com> on 2004/12/17 18:00:23 UTC
AbstractJavaSamplerClient / getSystemResource question
Hi all,
We're building our own AbstractJavaSamplerClient but we run into a problem when we want to read a property file using the ClassLoader.getSystemResource method. Whatever we try in regard to the directory/filename (file:///d:/etc/test.properties, d:\etc\test.properties, .\test.properties, test) or the placement of the (in d:\etc, jmeter bin, jmeter lib) the file cannot be found.
If we try the same in a seperate Java client (so without Jmeter) the file can be found?!?!
I've added our AbstractJavaSamplerClient below. This client take the filename as parameter (via GUI).
Regards,
Bob Coret
-----------------------------
package org.apache.jmeter.protocol.java.test;
import java.io.Serializable;
import java.util.Iterator;
import java.net.URL;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient;
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
public class SystemResourceTest extends AbstractJavaSamplerClient implements Serializable {
public static final String DEFAULT_FILE = "d:\\etc\\test.properties";
private String fileName;
public SleepTest() { }
public void setupTest(JavaSamplerContext context) {
fileName= context.getParameter("Filename", DEFAULT_FILE);
}
public SampleResult runTest(JavaSamplerContext context) {
SampleResult results = new SampleResult();
results.sampleStart();
results.setSampleLabel("System Resource Test");
URL epFunctionsConfigURL = ClassLoader.getSystemResource(getFileName());
if (epFunctionsConfigURL == null) {
results.setResponseMessage("File '"+getFileName()+"' not found!");
results.setSuccessful(false);
} else {
results.setResponseMessage("File '"+getFileName()+"' found!");
results.setSuccessful(true);
}
results.sampleEnd();
return results;
}
public void teardownTest(JavaSamplerContext context) { }
public Arguments getDefaultParameters()
{
Arguments params = new Arguments();
params.addArgument("Filename", DEFAULT_FILE);
return params;
}
private String getFileName()
{
return fileName;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
Re: AbstractJavaSamplerClient / getSystemResource question
Posted by sebb <se...@gmail.com>.
On Fri, 17 Dec 2004 18:00:23 +0100, Coret Bob <b....@pinkroccade.com> wrote:
> Hi all,
>
> We're building our own AbstractJavaSamplerClient but we run into a problem when we want to read a property file using the ClassLoader.getSystemResource method. Whatever we try in regard to the directory/filename (file:///d:/etc/test.properties, d:\etc\test.properties, .\test.properties, test) or the placement of the (in d:\etc, jmeter bin, jmeter lib) the file cannot be found.
>
> If we try the same in a seperate Java client (so without Jmeter) the file can be found?!?!
>
I think the difference could be a classpath problem.
Would it not be easier to use the java.util.Properties.load() method
to load the properties file?
This is what JMeter.java does in the getProperties() method.
S.
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org