use of javax.script.SimpleBindings in project metrics by dropwizard.
the class PickledGraphiteTest method unpickleOutput.
private String unpickleOutput() throws Exception {
StringBuilder results = new StringBuilder();
// the charset is important. if the GraphitePickleReporter and this test
// don't agree, the header is not always correctly unpacked.
String payload = output.toString("UTF-8");
PyList result = new PyList();
int nextIndex = 0;
while (nextIndex < payload.length()) {
Bindings bindings = new SimpleBindings();
bindings.put("payload", payload.substring(nextIndex));
unpickleScript.eval(bindings);
result.addAll(result.size(), (PyList) bindings.get("metrics"));
nextIndex += ((BigInteger) bindings.get("batchLength")).intValue();
}
for (Object aResult : result) {
PyTuple datapoint = (PyTuple) aResult;
String name = datapoint.get(0).toString();
PyTuple valueTuple = (PyTuple) datapoint.get(1);
Object timestamp = valueTuple.get(0);
Object value = valueTuple.get(1);
results.append(name).append(" ").append(value).append(" ").append(timestamp).append("\n");
}
return results.toString();
}
use of javax.script.SimpleBindings in project cas by apereo.
the class ScriptingUtils method executeGroovyScriptEngine.
/**
* Execute inline groovy script engine.
*
* @param <T> the type parameter
* @param script the script
* @param variables the variables
* @param clazz the clazz
* @return the t
*/
public static <T> T executeGroovyScriptEngine(final String script, final Map<String, Object> variables, final Class<T> clazz) {
try {
val engine = new ScriptEngineManager().getEngineByName("groovy");
val binding = new SimpleBindings();
if (variables != null && !variables.isEmpty()) {
binding.putAll(variables);
}
if (!binding.containsKey("logger")) {
binding.put("logger", LOGGER);
}
val result = engine.eval(script, binding);
return getGroovyScriptExecutionResultOrThrow(clazz, result);
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
}
return null;
}
use of javax.script.SimpleBindings in project meecrowave by apache.
the class MeecrowaveRunMojo method scriptCustomization.
private void scriptCustomization(final List<String> customizers, final String ext, final Map<String, Object> customBindings) {
if (customizers == null || customizers.isEmpty()) {
return;
}
final ScriptEngine engine = new ScriptEngineManager().getEngineByExtension(ext);
if (engine == null) {
throw new IllegalStateException("No engine for " + ext + ". Maybe add the JSR223 implementation as plugin dependency.");
}
for (final String js : customizers) {
try {
final SimpleBindings bindings = new SimpleBindings();
bindings.put("project", project);
engine.eval(new StringReader(js), bindings);
bindings.putAll(customBindings);
} catch (final ScriptException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class BatchResource method actionCollection.
@Override
public Promise<ActionResponse, ResourceException> actionCollection(Context serverContext, ActionRequest actionRequest) {
if (!actionRequest.getAction().equals(BATCH)) {
final String msg = "Action '" + actionRequest.getAction() + "' not implemented for this resource";
final NotSupportedException exception = new NotSupportedException(msg);
debug.error(msg, exception);
return exception.asPromise();
}
String scriptId = null;
try {
JsonValue scriptIdValue = actionRequest.getContent().get(SCRIPT_ID);
if (scriptIdValue == null) {
if (debug.errorEnabled()) {
debug.error("BatchResource :: actionCollection - ScriptId null. Default scripts not implemented.");
}
return new BadRequestException().asPromise();
} else {
scriptId = scriptIdValue.asString();
}
final JsonValue requests = actionRequest.getContent().get(REQUESTS);
final String realm = getRealm(serverContext);
final ScriptConfiguration scriptConfig = scriptingServiceFactory.create(SubjectUtils.createSuperAdminSubject(), realm).get(scriptId);
final ScriptObject script = new ScriptObject(scriptConfig.getName(), scriptConfig.getScript(), scriptConfig.getLanguage());
final ScriptResponse response = new ScriptResponse();
final Bindings bindings = new SimpleBindings();
bindings.put(PAYLOAD, requests);
bindings.put(CONTEXT, serverContext);
bindings.put(LOGGER, debug);
bindings.put(REQUESTER, requester);
bindings.put(RESPONSE, response);
return newResultPromise(newActionResponse((JsonValue) scriptEvaluator.evaluateScript(script, bindings)));
} catch (ScriptException e) {
debug.error("BatchResource :: actionCollection - Error running script : {}", scriptId);
return exceptionMappingHandler.handleError(serverContext, actionRequest, e).asPromise();
} catch (javax.script.ScriptException e) {
debug.error("BatchResource :: actionCollection - Error running script : {}", scriptId);
return new InternalServerErrorException().asPromise();
}
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class OidcClaimsExtensionTest method testBindings.
private <T> Bindings testBindings(Set<String> scopes, Map<String, Set<T>> requestedClaims) {
Bindings scriptVariables = new SimpleBindings();
scriptVariables.put("logger", logger);
scriptVariables.put("claims", new HashMap<String, Object>());
scriptVariables.put("accessToken", accessToken);
scriptVariables.put("session", ssoToken);
scriptVariables.put("identity", identity);
scriptVariables.put("scopes", scopes);
scriptVariables.put("requestedClaims", requestedClaims);
return scriptVariables;
}
Aggregations