use of com.bluenimble.platform.scripting.ScriptingEngineException in project serverless by bluenimble.
the class ScriptableApiSpi method onExecute.
@Override
public void onExecute(Api api, ApiConsumer consumer, ApiService service, ApiRequest request, ApiResponse response) throws ApiServiceExecutionException {
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.OnExecute)) {
return;
}
Object jsApi = ((SpecAndSpiPair) api.getHelper()).spec();
if (jsApi == null) {
throw new ApiServiceExecutionException("api or spi not attached on Api OnStart");
}
try {
// update consumer id
if (consumer.getReference() != null) {
engine.invoke(consumer.getReference(), ConsumerSet, ApiConsumer.Fields.Id, consumer.get(ApiConsumer.Fields.Id));
}
// invoke onExecute
engine.invoke(spi, Functions.OnExecute, jsApi, consumer, service, request, response);
} catch (ScriptingEngineException ex) {
ex.setScript(Json.getString(api.getRuntime(), Api.Spec.Runtime.Function));
throw new ApiServiceExecutionException(ex.getMessage(), ex);
}
}
use of com.bluenimble.platform.scripting.ScriptingEngineException 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