quark.Server Maven / Gradle / Ivy
/* Quark 1.0.452 run at 2016-11-11 16:09:46.008093 */
package quark;
public class Server implements HTTPServlet, io.datawire.quark.runtime.QObject {
public static quark.reflect.Class quark_Server_quark_Object__ref = datawire_mdk_md.Root.quark_Server_quark_Object__md;
public T impl;
public Boolean _sendCORS;
public Server(T impl) {
(this).impl = impl;
(this)._sendCORS = false;
}
public void sendCORS(Boolean send) {
(this)._sendCORS = send;
}
public void onHTTPRequest(HTTPRequest request, HTTPResponse response) {
String body = (request).getBody();
io.datawire.quark.runtime.JSONObject envelope = io.datawire.quark.runtime.JSONObject.parse(body);
if ((((envelope).getObjectItem("$method"))==((envelope).undefined()) || ((Object)((envelope).getObjectItem("$method")) != null && ((Object) ((envelope).getObjectItem("$method"))).equals((envelope).undefined()))) || (((envelope).getObjectItem("rpc"))==((envelope).undefined()) || ((Object)((envelope).getObjectItem("rpc")) != null && ((Object) ((envelope).getObjectItem("rpc"))).equals((envelope).undefined())))) {
(response).setBody((("Failed to understand request.\n\n") + (body)) + ("\n"));
(response).setCode(400);
(quark.concurrent.Context.runtime()).respond(request, response);
} else {
String methodName = ((envelope).getObjectItem("$method")).getString();
io.datawire.quark.runtime.JSONObject json = (envelope).getObjectItem("rpc");
quark.reflect.Method method = (((quark.reflect.Class.get(io.datawire.quark.runtime.Builtins._getClass(this))).getField("impl")).getType()).getMethod(methodName);
java.util.ArrayList params = (method).getParameters();
java.util.ArrayList