use of javax.script.Bindings in project jmeter by apache.
the class JSR223Assertion method getResult.
@Override
public AssertionResult getResult(SampleResult response) {
AssertionResult result = new AssertionResult(getName());
try {
ScriptEngine scriptEngine = getScriptEngine();
Bindings bindings = scriptEngine.createBindings();
bindings.put("SampleResult", response);
bindings.put("AssertionResult", result);
processFileOrScript(scriptEngine, bindings);
result.setError(false);
} catch (IOException | ScriptException e) {
log.error("Problem in JSR223 script: {}", getName(), e);
result.setError(true);
result.setFailureMessage(e.toString());
}
return result;
}
use of javax.script.Bindings in project jmeter by apache.
the class JSR223Listener method sampleOccurred.
@Override
public void sampleOccurred(SampleEvent event) {
try {
ScriptEngine scriptEngine = getScriptEngine();
Bindings bindings = scriptEngine.createBindings();
bindings.put("sampleEvent", event);
bindings.put("sampleResult", event.getResult());
processFileOrScript(scriptEngine, bindings);
} catch (ScriptException | IOException e) {
log.error("Problem in JSR223 script, {}", getName(), e);
}
}
use of javax.script.Bindings in project sling by apache.
the class SlingBindingsVariablesListJsonServlet method getBindingsByEngine.
/**
* Gets the {@link Bindings} object for the given {@link ScriptEngineFactory}.
* It only considers the default context "request".
*
* @see <a href="https://issues.apache.org/jira/browse/SLING-3038">binding contexts(SLING-3083)</a>
*
* @param scriptEngineFactory the factory of the script engine, for which to retrieve the bindings
* @param request the current request (necessary to create the bindings)
* @param response the current response (necessary to create the bindings)
* @return the bindings (list of key/value pairs) as defined by {@link Bindings} for the given script engine.
* @throws IOException
*/
private Bindings getBindingsByEngine(ScriptEngineFactory scriptEngineFactory, SlingHttpServletRequest request, SlingHttpServletResponse response) throws IOException {
// use default context only
String context = SlingScriptAdapterFactory.BINDINGS_CONTEXT;
final Collection<BindingsValuesProvider> bindingsValuesProviders = bindingsValuesProviderTracker.getBindingsValuesProviders(scriptEngineFactory, context);
Resource invalidScriptResource = new NonExistingResource(request.getResourceResolver(), "some/invalid/scriptpath");
DefaultSlingScript defaultSlingScript = new DefaultSlingScript(bundleContext, invalidScriptResource, scriptEngineFactory.getScriptEngine(), bindingsValuesProviders, null, null);
// prepare the bindings (similar as in DefaultSlingScript#service)
final SlingBindings initalBindings = new SlingBindings();
initalBindings.setRequest(request);
initalBindings.setResponse(response);
final Bindings bindings = defaultSlingScript.verifySlingBindings(initalBindings);
// only thing being added in {DefaultSlingScript#call(...)} is resource resolver
bindings.put(SlingScriptConstants.ATTR_SCRIPT_RESOURCE_RESOLVER, request.getResourceResolver());
return bindings;
}
use of javax.script.Bindings in project sling by apache.
the class BindingsValuesProvidersByContextIT method addBVP.
private void addBVP(final String id, String context, String engineName) {
final BindingsValuesProvider bvp = new BindingsValuesProvider() {
@Override
public String toString() {
return id;
}
@Override
public void addBindings(Bindings b) {
}
};
regs.add(bundleContext.registerService(BindingsValuesProvider.class.getName(), bvp, getProperties(context, engineName)));
}
use of javax.script.Bindings in project sling by apache.
the class BindingsValuesProvidersByContextIT method addBVPWithServiceRanking.
private void addBVPWithServiceRanking(final String id, String context, String engineName, int serviceRanking) {
final BindingsValuesProvider bvp = new BindingsValuesProvider() {
@Override
public String toString() {
return id;
}
@Override
public void addBindings(Bindings b) {
}
};
final Dictionary<String, Object> properties = getProperties(context, engineName);
properties.put(Constants.SERVICE_RANKING, serviceRanking);
regs.add(bundleContext.registerService(BindingsValuesProvider.class.getName(), bvp, properties));
}
Aggregations