use of com.servoy.j2db.server.ngclient.scripting.WebServiceScriptable in project servoy-client by Servoy.
the class DebugNGClient method createScriptEngine.
@Override
protected IExecutingEnviroment createScriptEngine() {
RemoteDebugScriptEngine engine = new RemoteDebugScriptEngine(this);
WebObjectSpecification[] serviceSpecifications = WebServiceSpecProvider.getSpecProviderState().getAllWebComponentSpecifications();
PluginScope scope = (PluginScope) engine.getSolutionScope().get("plugins", engine.getSolutionScope());
scope.setLocked(false);
for (WebObjectSpecification serviceSpecification : serviceSpecifications) {
if (serviceSpecification.getApiFunctions().size() != 0 || serviceSpecification.getAllPropertiesNames().size() != 0) {
scope.put(serviceSpecification.getScriptingName(), scope, new WebServiceScriptable(this, serviceSpecification, engine.getSolutionScope()));
}
}
scope.setLocked(true);
if (designerCallback != null) {
designerCallback.addScriptObjects(this, engine.getSolutionScope());
}
return engine;
}
use of com.servoy.j2db.server.ngclient.scripting.WebServiceScriptable in project servoy-client by Servoy.
the class NGClient method createScriptEngine.
@Override
protected IExecutingEnviroment createScriptEngine() {
IExecutingEnviroment scriptEngine = super.createScriptEngine();
WebObjectSpecification[] serviceSpecifications = WebServiceSpecProvider.getSpecProviderState().getAllWebComponentSpecifications();
PluginScope scope = (PluginScope) scriptEngine.getSolutionScope().get("plugins", scriptEngine.getSolutionScope());
scope.setLocked(false);
for (WebObjectSpecification serviceSpecification : serviceSpecifications) {
if (serviceSpecification.getApiFunctions().size() != 0 || serviceSpecification.getAllPropertiesNames().size() != 0) {
scope.put(ClientService.convertToJSName(serviceSpecification.getName()), scope, new WebServiceScriptable(this, serviceSpecification, scriptEngine.getSolutionScope()));
}
}
scope.setLocked(true);
return scriptEngine;
}
use of com.servoy.j2db.server.ngclient.scripting.WebServiceScriptable in project servoy-client by Servoy.
the class NGClient method executeMethod.
/*
* @see org.sablo.websocket.IServerService#executeMethod(java.lang.String, org.json.JSONObject)
*/
@Override
public Object executeMethod(String methodName, JSONObject args) throws Exception {
switch(methodName) {
case "login":
try {
credentials.setUserName(args.optString("username"));
credentials.setPassword(args.optBoolean("encrypted") ? SecuritySupport.decrypt(Settings.getInstance(), args.optString("password")) : args.optString("password"));
authenticate(null, null, new Object[] { credentials.getUserName(), credentials.getPassword() });
if (getClientInfo().getUserUid() != null) {
wsSession.getEventDispatcher().postEvent(new Runnable() {
public void run() {
try {
loadSolution(getSolution().getName());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
});
if (args.optBoolean("remember")) {
JSONObject r = new JSONObject();
r.put("username", credentials.getUserName());
r.put("password", SecuritySupport.encrypt(Settings.getInstance(), credentials.getPassword()));
return r;
} else
return Boolean.TRUE;
}
} catch (Exception ex) {
Debug.error(ex);
}
return Boolean.FALSE;
case "autosave":
getFoundSetManager().getEditRecordList().stopEditing(false);
break;
case "callServerSideApi":
{
String serviceScriptingName = args.getString("service");
PluginScope scope = (PluginScope) getScriptEngine().getSolutionScope().get("plugins", getScriptEngine().getSolutionScope());
Object service = scope.get(serviceScriptingName, scope);
if (service instanceof WebServiceScriptable) {
WebServiceScriptable webServiceScriptable = (WebServiceScriptable) service;
JSONArray methodArguments = args.getJSONArray("args");
String serviceMethodName = args.getString("methodName");
// apply browser to sablo java value conversion - using server-side-API definition from the service's spec file if available (otherwise use default conversion)
// the call to webServiceScriptable.executeScopeFunction will do the java to Rhino one
// find spec for method
// get specification from plugins scope (which uses getScriptName() of service, then use the getClientService using the real name, to make sure client service is created if needed)
WebObjectSpecification serviceSpec = webServiceScriptable.getServiceSpecification();
BaseWebObject serviceWebObject = (BaseWebObject) getWebsocketSession().getClientService(serviceSpec.getName());
WebObjectFunctionDefinition functionSpec = (serviceSpec != null ? serviceSpec.getInternalApiFunction(serviceMethodName) : null);
if (functionSpec == null) {
functionSpec = (serviceSpec != null ? serviceSpec.getApiFunction(serviceMethodName) : null);
}
List<PropertyDescription> argumentPDs = (functionSpec != null ? functionSpec.getParameters() : null);
// apply conversion
Object[] arrayOfJavaConvertedMethodArgs = new Object[methodArguments.length()];
for (int i = 0; i < methodArguments.length(); i++) {
arrayOfJavaConvertedMethodArgs[i] = JSONUtils.fromJSON(null, methodArguments.get(i), (argumentPDs != null && argumentPDs.size() > i) ? argumentPDs.get(i) : null, new BrowserConverterContext(serviceWebObject, PushToServerEnum.allow), new ValueReference<Boolean>(false));
}
Object retVal = webServiceScriptable.executeScopeFunction(functionSpec, arrayOfJavaConvertedMethodArgs);
if (functionSpec != null && functionSpec.getReturnType() != null) {
// this means that when this return value is sent to client it will be converted to browser JSON correctly - if we give it the type
retVal = new TypedData<Object>(retVal, functionSpec.getReturnType());
}
return retVal;
} else {
Debug.warn("callServerSideApi for unknown service '" + serviceScriptingName + "'");
}
break;
}
}
return null;
}
Aggregations