// Open db
WGDatabase db = retrieveAndOpenDB(session, dbKey);
// Test permissions
if (!mayCallAction(db, actionID)) {
throw new WGAServiceException("You are not permitted to call remote action '" + actionID + "'");
}
// Get root content and action
TMLContext context = new TMLContext(db.getDummyContent(db.getDefaultLanguage()), _core, null, null);
context.makeThreadMainContext();
TMLAction action = context.getActionByID(actionID, null);
if (action == null) {
throw new WGAServiceException("Undefined action: " + actionID);
}
// Calculate execution context
if (executionContext != null) {
context = context.context(executionContext, false);
if (context == null) {
throw new WGAServiceException("Unretrievable execution context: " + executionContext);
}
}
// Create TMLForm, if form information was issued
if (form != null) {
FormInfo formInfo = new FormInfo(form.getId(), false, false);
formInfo.setSource("none");
formInfo.setKeepOnValidate(false);
CSConfig csConfig = (CSConfig) db.getAttribute(WGACore.DBATTRIB_CSCONFIG);
if (csConfig != null) {
formInfo.setVersionCompliance(csConfig.getVersionCompliance());
}
de.innovationgate.wgpublisher.webtml.utils.TMLForm tmlForm = context.createform(formInfo);
tmlForm.importServicesForm(form);
}
// Create map of parent scope objects
Map<String, Object> parentScopeObjects = new HashMap<String, Object>();
parentScopeObjects.put(SCRIPTOBJ_WGASERVICESCONTEXT, _contextProvider);
// Call action
Object result = context.callCustomAction(action, params, parentScopeObjects);
if (context.isdefined("actionresult")) {
ExpressionResult expressionResult = (ExpressionResult) context.item("actionresult");
if (expressionResult.isError()) {
WGExpressionException ex = expressionResult.getException();
// User defined TMLScript exception should be passed on unmodified
if (ex.getCause() instanceof TMLScriptException) {
throw ex.getCause();
}
else {
throw ex;
}
}
}
// If action result is an TMLForm, transform it back into a services form
if (result instanceof de.innovationgate.wgpublisher.webtml.utils.TMLForm) {
de.innovationgate.wgpublisher.webtml.utils.TMLForm tmlForm = (de.innovationgate.wgpublisher.webtml.utils.TMLForm) result;
Form servicesForm = tmlForm.exportServicesForm();
ActionResult actionResult = new ActionResult();
actionResult.setForm(servicesForm);
return actionResult;
} else {
ActionResult actionResult = new ActionResult();
actionResult.setNativeResult(result);
return actionResult;
}
}
catch (TMLScriptException e) {
throw new WGAServiceException(e.getMessage());
}
catch (WGCreationException e) {
throw new WGAServiceException("Error creating context for action: " + e.getMessage());
}
catch (Throwable e) {
_core.getLog().error("Exception executing remote action '" + actionID + "'", e);
if (e instanceof WGAServiceException) {
throw (WGAServiceException) e;
} else {
throw new WGAServiceException("Error executing action: " + e.getClass().getName() + " - " + e.getMessage());
}
}
}