public function handleRequest($httpContext) { $doneTrigger = new tink_core_FutureTrigger(); if (ufront_remoting_RemotingHandler_0($this, $doneTrigger, $httpContext)) { $r = $httpContext->response; $remotingResponse = null; $r->setOk(); $path = null; $args = null; try { $this->initializeContext($httpContext->injector); $params = $httpContext->request->get_params(); if (!$params->exists("__x")) { throw new HException("Remoting call did not have parameter `__x` which describes which API call to make. Aborting"); } $remotingCall = null; $s = ufront_core__MultiValueMap_MultiValueMap_Impl_::get($params, "__x"); $remotingCall = urldecode($s); $u = new haxe_Unserializer($remotingCall); $path = $u->unserialize(); $args = $u->unserialize(); $apiCallFinished = $this->executeApiCall($path, $args, $this->context, $httpContext->actionContext); $remotingResponse = tink_core__Future_Future_Impl_::map($apiCallFinished, array(new _hx_lambda(array(&$apiCallFinished, &$args, &$doneTrigger, &$httpContext, &$params, &$path, &$r, &$remotingCall, &$remotingResponse, &$u), "ufront_remoting_RemotingHandler_1"), 'execute'), null); } catch (Exception $__hx__e) { $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e; $e = $_ex_; $error = $e; $apiNotFoundMessages = new _hx_array(array("Invalid path", "No such object", "Can't access", "No such method")); if ($path !== null && $args !== null && Std::is($e, _hx_qtype("String")) && Lambda::exists($apiNotFoundMessages, array(new _hx_lambda(array(&$apiNotFoundMessages, &$args, &$doneTrigger, &$e, &$error, &$httpContext, &$path, &$r, &$remotingResponse), "ufront_remoting_RemotingHandler_2"), 'execute'))) { $remotingResponse = tink_core__Future_Future_Impl_::sync("Unable to access " . _hx_string_or_null($path->join(".")) . " - API Not Found (" . _hx_string_or_null($error) . "). See " . Std::string($this->context->objects)); $r->setNotFound(); } else { $r->setInternalError(); $remotingResponse = tink_core__Future_Future_Impl_::sync($this->remotingError($e, $httpContext)); } } $remotingResponse(array(new _hx_lambda(array(&$args, &$doneTrigger, &$e, &$httpContext, &$path, &$r, &$remotingResponse), "ufront_remoting_RemotingHandler_3"), 'execute')); } else { $result1 = tink_core_Outcome::Success(tink_core_Noise::$Noise); if ($doneTrigger->{"list"} === null) { false; } else { $list1 = $doneTrigger->{"list"}; $doneTrigger->{"list"} = null; $doneTrigger->result = $result1; tink_core__Callback_CallbackList_Impl_::invoke($list1, $result1); tink_core__Callback_CallbackList_Impl_::clear($list1); true; } } return $doneTrigger->future; }
static function processResponse($response, $onResult, $errorHandler, $remotingCallString) { $ret = null; $stack = null; $hxrFound = false; $errors = new _hx_array(array()); $onError = ufront_remoting_RemotingUtil::wrapErrorHandler($errorHandler); if (_hx_substr($response, 0, 2) !== "hx") { call_user_func_array($onError, array(ufront_remoting_RemotingError::RNoRemotingResult($remotingCallString, $response))); } else { $_g = 0; $_g1 = _hx_explode("\n", $response); while ($_g < $_g1->length) { $line = $_g1[$_g]; ++$_g; if ($line === "") { continue; } $_g2 = _hx_substr($line, 0, 3); switch ($_g2) { case "hxr": $s = new haxe_Unserializer(_hx_substr($line, 3, null)); try { $ret = $s->unserialize(); } catch (Exception $__hx__e) { $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e; $e = $_ex_; $ret = $errors->push(ufront_remoting_RemotingError::RUnserializeFailed($remotingCallString, _hx_substr($line, 3, null), "" . Std::string($e))); } $hxrFound = true; break; case "hxt": $s1 = new haxe_Unserializer(_hx_substr($line, 3, null)); $m = null; try { $m = $s1->unserialize(); } catch (Exception $__hx__e) { $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e; $e1 = $_ex_; $m = $errors->push(ufront_remoting_RemotingError::RUnserializeFailed($remotingCallString, _hx_substr($line, 3, null), "" . Std::string($e1))); } $m->pos->fileName = "[R]" . _hx_string_or_null($m->pos->fileName); haxe_Log::trace("[" . Std::string($m->type) . "]" . Std::string($m->msg), $m->pos); break; case "hxs": $s2 = new haxe_Unserializer(_hx_substr($line, 3, null)); try { $stack = $s2->unserialize(); } catch (Exception $__hx__e) { $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e; $e2 = $_ex_; $stack = $errors->push(ufront_remoting_RemotingError::RUnserializeFailed($remotingCallString, _hx_substr($line, 3, null), "" . Std::string($e2))); } break; case "hxe": $s3 = new haxe_Unserializer(_hx_substr($line, 3, null)); try { $ret = $s3->unserialize(); } catch (Exception $__hx__e) { $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e; $e3 = $_ex_; $ret = $errors->push(ufront_remoting_RemotingError::RServerSideException($remotingCallString, $e3, $stack)); } break; default: $errors->push(ufront_remoting_RemotingError::RUnserializeFailed($remotingCallString, $line, "Invalid line in response")); break; } unset($_g2); unset($line); } } if ($errors->length === 0) { if ($hxrFound) { try { call_user_func_array($onResult, array($ret)); } catch (Exception $__hx__e) { $_ex_ = $__hx__e instanceof HException ? $__hx__e->e : $__hx__e; $e4 = $_ex_; call_user_func_array($onError, array(ufront_remoting_RemotingError::RClientCallbackException($remotingCallString, $e4))); } } else { call_user_func_array($onError, array(ufront_remoting_RemotingError::RNoRemotingResult($remotingCallString, $response))); } } else { $_g3 = 0; while ($_g3 < $errors->length) { $err = $errors[$_g3]; ++$_g3; call_user_func_array($onError, array($err)); unset($err); } } }