use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.
the class MockStrategy method processNonBlock.
@Override
public Object processNonBlock(Class returnType, ClassLoader classLoader, Object params, ExecutionCall call) throws ProcessControlException {
if (Pradar.isClusterTest()) {
if (params instanceof MatchConfig) {
try {
MatchConfig config = (MatchConfig) params;
String scriptContent = config.getScriptContent();
ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
Object result = evaluator.evaluate(scriptContent, config.getArgs());
return call.call(result);
} catch (ProcessControlException e) {
throw e;
} catch (Throwable e) {
LOGGER.error("mock处理异常 {}", e);
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.mock).setErrorCode("mock-0001").setMessage("mock处理异常!" + e.getMessage()).setDetail("脚本内容" + ((MatchConfig) params).getScriptContent()).report();
throw new PressureMeasureError(e);
}
}
}
return true;
}
use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.
the class MockStrategy method processBlock.
@Override
public Object processBlock(Class returnType, ClassLoader classLoader, Object params, ExecutionCall call) throws ProcessControlException {
if (Pradar.isClusterTest()) {
if (params instanceof MatchConfig) {
try {
MatchConfig config = (MatchConfig) params;
String scriptContent = config.getScriptContent();
ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
Object result = evaluator.evaluate(scriptContent, config.getArgs());
Object callResult = call.call(result);
ProcessController.returnImmediately(returnType, callResult);
} catch (ProcessControlException e) {
throw e;
} catch (Throwable e) {
LOGGER.error("mock处理异常 {}", e);
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.mock).setErrorCode("mock-0001").setMessage("mock处理异常!" + e.getMessage()).setDetail("脚本内容" + ((MatchConfig) params).getScriptContent()).report();
throw new PressureMeasureError(e);
}
}
}
return true;
}
use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.
the class MockStrategy method processBlock.
@Override
public Object processBlock(Class returnType, ClassLoader classLoader, Object params) throws ProcessControlException {
if (Pradar.isClusterTest()) {
if (params instanceof MatchConfig) {
try {
MatchConfig config = (MatchConfig) params;
String scriptContent = config.getScriptContent();
ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
Object result = evaluator.evaluate(scriptContent, config.getArgs());
ProcessController.returnImmediately(returnType, result);
} catch (ProcessControlException e) {
throw e;
} catch (Throwable e) {
LOGGER.error("mock处理异常 {}", e);
ErrorReporter.buildError().setErrorType(ErrorTypeEnum.mock).setErrorCode("mock-0003").setMessage("mock处理异常!" + e.getMessage()).setDetail("脚本内容" + ((MatchConfig) params).getScriptContent()).report();
throw new PressureMeasureError(e);
}
}
}
return true;
}
use of com.pamirs.pradar.script.ScriptEvaluator in project LinkAgent by shulieTech.
the class MockAdviceListener method before.
@Override
public void before(Advice advice) throws Throwable {
if (Pradar.isClusterTest()) {
Map<String, Object> binding = new HashMap<String, Object>(4, 1.0f);
binding.put("args", advice.getParameterArray());
binding.put("target", advice.getTarget());
binding.put("classLoader", advice.getClassLoader());
binding.put("logger", mockLogger);
ScriptEvaluator evaluator = ScriptManager.getInstance().getScriptEvaluator("bsh");
Object result = evaluator.evaluate(advice.getClassLoader(), scriptContent, binding);
ProcessController.returnImmediately(advice.getBehavior().getReturnType(), result);
}
}
Aggregations