use of com.bluenimble.platform.scripting.ScriptingEngine in project serverless by bluenimble.
the class ScriptableApiSpi method onStop.
@Override
public void onStop(Api api, ApiContext context) throws ApiManagementException {
Object spi = ((SpecAndSpiPair) api.getHelper()).spi();
if (spi == null) {
return;
}
ScriptingEngine engine = api.space().feature(ScriptingEngine.class, ApiSpace.Features.Default, context);
if (!engine.has(spi, Functions.OnStop)) {
return;
}
Object jsApi = ((SpecAndSpiPair) api.getHelper()).spec();
if (jsApi == null) {
return;
}
// invoke onStop
try {
engine.invoke(spi, Functions.OnStop, jsApi, context);
} catch (Exception ex) {
api.tracer().log(Level.Error, Lang.BLANK, ex);
}
}
use of com.bluenimble.platform.scripting.ScriptingEngine in project serverless by bluenimble.
the class ScriptableApiSpi method findConsumer.
@Override
public void findConsumer(Api api, ApiService service, ApiRequest request, ApiConsumer consumer) throws ApiAuthenticationException {
Object spi = ((SpecAndSpiPair) api.getHelper()).spi();
if (spi == null) {
return;
}
ScriptingEngine engine = api.space().feature(ScriptingEngine.class, ApiSpace.Features.Default, request);
if (!engine.has(spi, Functions.FindConsumer)) {
return;
}
Object jsApi = ((SpecAndSpiPair) api.getHelper()).spec();
if (jsApi == null) {
throw new ApiAuthenticationException("api or spi not attached on Api OnStart");
}
// invoke findConsumer
try {
engine.invoke(spi, Functions.FindConsumer, jsApi, service, request, consumer);
} catch (ScriptingEngineException ex) {
ex.setScript(Json.getString(api.getRuntime(), Api.Spec.Runtime.Function));
throw new ApiAuthenticationException(ex.getMessage(), ex);
}
}
Aggregations