public function runImpl() { Log::writeInfo("Called invocation task task: " . $this->rai, $target = 'file'); if ($this->rai == null) { Log::writeInfo("Something is null in InvocationActionTask..."); return; } try { $path_to_hosted = PathBuilder::getHostedService($this->rai->getAppVersionId(), $this->rai->getRelativePath()); $parser = HostedServiceParser::getInstance()->parseModelRAI($path_to_hosted, $this->rai->getId()); if ($parser->isError()) { Log::writeError($parser->getError()['msg']); return ResponderProcessor::sendResult($this->rai->getId(), $parser->getError()); } $runtime = ['path' => $path_to_hosted, 'endpointURL' => Config::$CORE['hosted_service']['endpoint_url'], 'serverRootURL' => Config::$CORE['hosted_service']['server_root_url'], 'serverPort' => Config::$CORE['hosted_service']['server_port'], 'serverName' => Config::$CORE['hosted_service']['server_name'], 'codeFormatType' => Config::$CORE['hosted_service']['code_format_type'], "generationMode" => Config::$CORE['hosted_service']['generation_mode'], 'randomUUID' => mt_rand(100000000, PHP_INT_MAX)]; $xml_manager = new XmlManager(); $invocation_result = new InvocationResult(); $invocation_result->setArguments(["xml" => $xml_manager->buildXml($parser->getParsedData(), $runtime), "config" => $parser->getConfigListAsArray()]); // $xml = $xml_manager->buildXml( $hosted_parser->getParsedData(), $runtime ); // file_put_contents("../repo/e3bd3a54-9a07-6160-ff70-a824a9610800/servercode/services/E3BD3A54-9A07-6160-FF70-A824A9610800.xml", $xml); // echo $xml; return; ResponderProcessor::sendResult($this->rai->getId(), $invocation_result); } catch (Exception $e) { Log::writeError($e->getMessage()); } }
public function runImpl() { Log::writeInfo("Called invocation task: " . $this->rsi, $target = 'file'); if ($this->rsi == null) { Log::writeInfo("Something is null in InvocationActionTask..."); return; } try { if (GlobalState::$TYPE == 'CLOUD') { $xml_path = realpath(PathBuilder::getHostedService($this->rsi->getAppVersionId(), $this->rsi->getRelativePath()) . DS . "..") . DS . $this->rsi->getAppVersionId() . ".xml"; HostedModelHolder::setXMLModel(file_get_contents($xml_path)); // load xml from file to holder } $this->initSdk(); $instance_class_name = $this->rsi->getClassName(); $arguments = $this->rsi->getArguments(); $hosted_mapper = new HostedMapper(); $hosted_mapper->prepareArguments($arguments, $this->rsi->getMethod()); if ($hosted_mapper->isError()) { Log::writeError($hosted_mapper->getError()['msg']); return ResponderProcessor::sendResult($this->rsi->getId(), $hosted_mapper->getError()); } $reflection_method = new ReflectionMethod($this->rsi->getClassName(), $this->rsi->getMethod()); $hosted_instance = new $instance_class_name(); $this->setConfiguration($hosted_instance, $this->rsi->getConfiguration()); $result = $reflection_method->invokeArgs($hosted_instance, $arguments); $invocation_result = new InvocationResult(); $hosted_mapper->prepareResult($result); $invocation_result->setArguments($result); ResponderProcessor::sendResult($this->rsi->getId(), $invocation_result); } catch (Exception $e) { Log::writeError($e->getMessage()); } }
public function runImpl() { Log::writeInfo("Called invocation task: " . $this->rmi, $target = 'file'); if ($this->rmi == null || $this->event_handler == null) { Log::writeInfo("Something is null in InvocationTask..."); return; } $invocation_result = new InvocationResult(); try { $definition = self::$event_definition_holder->getDefinitionById($this->rmi->getEventId()); $arguments = self::$argument_adapter_list->beforeExecuting($definition, $this->rmi, $this->rmi->getDecodedArguments()); if ($definition['name'] == 'handleEvent') { // Object context = arguments[ 0 ]; // Class runnerContextClass = classLoader.loadClass( RunnerContext.class.getName() ); // List<String> userRoleList = (List<String>) runnerContextClass.getMethod( "getUserRole" ).invoke( context ); // // String[] userRoles = userRoleList == null ? null : userRoleList.toArray( new String[ userRoleList.size() ] ); // String userId = (String) runnerContextClass.getMethod( "getUserId" ).invoke( context ); // AccessValidator.validateAccess( clazz, userRoles, userId ); } $instance_class_name = $this->event_handler->getProvider(); $method = self::findMethod($instance_class_name, $definition, count($arguments)); // bootstrap onEnter action $backendless_globals = ClassManager::getClassInstanceByName("BackendlessGlobals"); $backendless_globals->onEnter($instance_class_name, $method, $arguments); // end bootstrap onEnter action // switch sdk from rest mode to bl Backendless::switchOnBlMode(); $reflection_method = new ReflectionMethod($instance_class_name, $method); $result = $arguments; // invokeArgs pass $arguments as link and we get changed data after invoke $reflection_method->invokeArgs(new $instance_class_name(), $result); // bootstrap onExit action $backendless_globals->onExit($instance_class_name, $method, $result); // end bootstrap onExit action if ($this->rmi->isAsync()) { return; } $arguments = self::$argument_adapter_list->afterExecuting($definition, $this->rmi, $arguments, $result); if (is_a($arguments[0], "\\backendless\\core\\servercode\\RunnerContext")) { $arguments[0] = $arguments[0]->getConvertedToArray(); } $invocation_result->setArguments($arguments); ResponderProcessor::sendResult($this->rmi->getId(), $invocation_result); } catch (Exception $e) { Log::writeError($e->getMessage()); } catch (BackendlessException $e) { Log::writeError("In Backendless SDK occurred error with message: \"" . $e->getMessage() . "\""); exit; } }
private function handleError($error) { if (GlobalState::$TYPE == 'CLOUD') { ResponderProcessor::sendResult($this->rai_id, $error); } throw new CodeRunnerException($error["msg"]); }
private function handleException($e, $invocation_result) { if ($this->rmi->isAsync()) { return; } if (is_a($e, 'backendless\\core\\commons\\exception\\ExceptionWrapper')) { $invocation_result->setException($e); } else { $exception = new ExceptionWrapper($e->getMessage(), $e->getCode(), $e); $invocation_result->setException($exception); } ResponderProcessor::sendResult($this->rmi->getId(), $invocation_result); }