use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class JMeter method startOptionalServers.
/**
*
*/
private void startOptionalServers() {
// $NON-NLS-1$
int bshport = JMeterUtils.getPropDefault("beanshell.server.port", 0);
// $NON-NLS-1$ $NON-NLS-2$
String bshfile = JMeterUtils.getPropDefault("beanshell.server.file", "");
if (bshport > 0) {
log.info("Starting Beanshell server ({},{})", bshport, bshfile);
Runnable t = new BeanShellServer(bshport, bshfile);
// NOSONAR we just evaluate some code here
t.run();
}
// Should we run a beanshell script on startup?
// $NON-NLS-1$
String bshinit = JMeterUtils.getProperty("beanshell.init.file");
if (bshinit != null) {
log.info("Run Beanshell on file: {}", bshinit);
try {
BeanShellInterpreter bsi = new BeanShellInterpreter();
bsi.source(bshinit);
} catch (ClassNotFoundException e) {
if (log.isWarnEnabled()) {
log.warn("Could not start Beanshell: {}", e.getLocalizedMessage());
}
} catch (JMeterException e) {
if (log.isWarnEnabled()) {
log.warn("Could not process Beanshell file: {}", e.getLocalizedMessage());
}
}
}
// $NON-NLS-1$
int mirrorPort = JMeterUtils.getPropDefault("mirror.server.port", 0);
if (mirrorPort > 0) {
log.info("Starting Mirror server ({})", mirrorPort);
try {
Object instance = ClassTools.construct(// $NON-NLS-1$
"org.apache.jmeter.protocol.http.control.HttpMirrorControl", mirrorPort);
ClassTools.invoke(instance, "startHttpMirror");
} catch (JMeterException e) {
log.warn("Could not start Mirror server", e);
}
}
}
use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class AccessLogSampler method sampleWithParser.
/**
* sample gets a new HTTPSampler from the generator and calls it's sample()
* method.
*
* @return newly generated and called sample
*/
public SampleResult sampleWithParser() {
initFilter();
instantiateParser();
SampleResult res = null;
try {
if (parser == null) {
throw new JMeterException("No Parser available");
}
// we call parse with 1 to get only one.
// this also means if we change the implementation
// to use 2, it would use every other entry and
// so on. Not that it is really useful, but a
// person could use it that way if they have a
// huge gigabyte log file and they only want to
// use a quarter of the entries.
int thisCount = parser.parseAndConfigure(1, this);
if (// Was there an error?
thisCount < 0) {
return errorResult(new Error("Problem parsing the log file"), new HTTPSampleResult());
}
if (thisCount == 0) {
if (count == 0 || filter == null) {
log.info("Stopping current thread");
JMeterContextService.getContext().getThread().stop();
}
if (filter != null) {
filter.reset();
}
CookieManager cm = getCookieManager();
if (cm != null) {
cm.clear();
}
count = 0;
return errorResult(new Error("No entries found"), new HTTPSampleResult());
}
count = thisCount;
res = sample();
if (res != null) {
res.setSampleLabel(toString());
}
} catch (Exception e) {
log.warn("Sampling failure", e);
return errorResult(e, new HTTPSampleResult());
}
return res;
}
use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class BeanShellPreProcessor method process.
@Override
public void process() {
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
log.error("BeanShell not found");
return;
}
JMeterContext jmctx = JMeterContextService.getContext();
Sampler sam = jmctx.getCurrentSampler();
try {
// Add variables for access to context and variables
// $NON-NLS-1$
bshInterpreter.set("sampler", sam);
processFileOrScript(bshInterpreter);
} catch (JMeterException e) {
if (log.isWarnEnabled()) {
log.warn("Problem in BeanShell script. {}", e.toString());
}
}
}
use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class BeanShellTimer method delay.
/**
* {@inheritDoc}
*/
@Override
public long delay() {
String ret = "0";
final BeanShellInterpreter bshInterpreter = getBeanShellInterpreter();
if (bshInterpreter == null) {
log.error("BeanShell not found");
return 0;
}
try {
Object o = processFileOrScript(bshInterpreter);
if (o != null) {
ret = o.toString();
}
} catch (JMeterException e) {
if (log.isWarnEnabled()) {
log.warn("Problem in BeanShell script. {}", e.toString());
}
}
try {
return Long.decode(ret);
} catch (NumberFormatException e) {
log.warn("Number format exception while decoding number: '{}'", ret);
return 0;
}
}
use of org.apache.jorphan.util.JMeterException in project jmeter by apache.
the class BeanShellInterpreter method bshInvoke.
private Object bshInvoke(Method m, Object[] o, boolean shouldLog) throws JMeterException {
Object r = null;
final String errorString = "Error invoking bsh method: ";
try {
r = m.invoke(bshInstance, o);
} catch (IllegalArgumentException | IllegalAccessException e) {
// Programming error
final String message = errorString + m.getName();
log.error(message);
throw new JMeterError(message, e);
} catch (InvocationTargetException e) {
// Can occur at run-time
// could be caused by the bsh Exceptions:
// EvalError, ParseException or TargetError
String message = errorString + m.getName();
Throwable cause = e.getCause();
if (cause != null) {
message += "\t" + cause.getLocalizedMessage();
}
if (shouldLog) {
log.error(message);
}
throw new JMeterException(message, e);
}
return r;
}
Aggregations