private function handleClientMessageQueue(MMapResponse $response) { $messages = ClientMessageBusController::getInstance()->getQueue(); // Check for client bus messages to be appended to the response if ($messages->count() > 0) { self::$Logger->info($messages->count() . ' client bus message(s) found, processing...'); // Only if the current body/bodyrenderer is mappable to a control message $currentBodyRenderer = $response->getBodyRenderer(); if ($currentBodyRenderer !== null && !$currentBodyRenderer instanceof DataManagerBodyRenderer) { self::$Logger->error('Cannot append client bus messages: unable to replace current BodyRenderer from class ' . get_class($currentBodyRenderer) . ', ignoring.'); ClientMessageBusController::getInstance()->getQueue()->clear(); return; } $messages = $messages->getArrayCopy(); foreach ($messages as &$message) { $message = $message->toArray(); } $data = $currentBodyRenderer !== null ? $currentBodyRenderer->getRenderedBody() : $response->getBody(); $newBody = array('messages' => $messages, 'data' => $data); // When using qx.io.ScriptLoader on the JS side, no callback proxy is available // to intercept control messages, so we're using a little workaround here by // calling directly eyeos._callbackProxyWithContent() with the messages queue in // argument. $controlMessageBodyRenderer = new ControlMessageBodyRenderer(ControlMessageBodyRenderer::TYPE_ENHANCEDDATA, $newBody); $responseContent = $controlMessageBodyRenderer->getRenderedBody(); $response->appendToBody('eyeos._callbackProxyWithContent(null, null, null, ' . $responseContent . ');'); ClientMessageBusController::getInstance()->getQueue()->clear(); } }
private function renderResponse(MMapResponse $response) { if (!$response->isValid()) { if (self::$Logger->isInfoEnabled()) { self::$Logger->info('Skipping invalid response: ' . $response); } return; } try { // headers foreach ($response->getHeaders() as $headerField) { self::$Logger->info($headerField); if (is_array($headerField)) { if (isset($headerField[1])) { if (isset($headerField[2])) { header($headerField[0], $headerField[1], $headerField[2]); } else { header($headerField[0], $headerField[1]); } } else { header($headerField[0]); } } else { //if ( !ob_get_status() ) { header($headerField); //} } } // body $bodyRenderer = $response->getBodyRenderer(); if ($bodyRenderer !== null) { self::$Logger->info('Using BodyRenderer: ' . $bodyRenderer); $bodyRenderer->doRender(); } else { self::$Logger->info('Using raw body'); echo $response->getBody(); } } catch (Exception $e) { self::$Logger->error('Exception caught while rendering response!'); self::$Logger->error('Exception message: ' . $e->getMessage()); if (self::$Logger->isDebugEnabled()) { self::$Logger->debug(ExceptionStackUtil::getStackTrace($e, false)); self::$Logger->debug((string) $response); } // the exception will be finally caught by the general try/catch block in index.php throw $e; } }
public function processRequest(MMapRequest $request, MMapResponse $response) { ob_start('mb_output_handler'); $return = null; $dataManager = DataManager::getInstance(); $POST = $request->getPOST(); $params = array(); if (isset($POST['params'])) { $params = $dataManager->doInput($POST['params']); } else { if ($request->issetGET('params')) { $params = $request->getGET('params'); } } //login in the system and get a valid login context $subject = new Subject(); $loginContext = new LoginContext('eyeos-login', $subject); $cred = new EyeosPasswordCredential(); $cred->setUsername($_REQUEST['username']); $cred->setPassword($_REQUEST['password'], true); $subject->getPrivateCredentials()->append($cred); $loginContext->login(); //now create fake process called api Kernel::enterSystemMode(); $appProcess = new Process('api'); $appProcess->setPid('31337'); $mem = MemoryManager::getInstance(); $processTable = $mem->get('processTable', array()); $processTable[31337] = $appProcess; $mem->set('processTable', $processTable); $appProcess->setLoginContext($loginContext); ProcManager::getInstance()->setCurrentProcess($appProcess); kernel::exitSystemMode(); $return = call_user_func_array(array('EyeosApplicationExecutable', '__callModule'), array($request->getPOST('module'), $request->getPOST('name'), $params)); //try to force mime type. If there is a previous mime type defined at application level //this have no effect if (!headers_sent()) { $response->getHeaders()->append('Content-type:text/plain'); } if ($response->getBodyRenderer() === null && $response->getBody() == '') { $response->setBodyRenderer(new DataManagerBodyRenderer($return)); } }
public function processRequest(MMapRequest $request, MMapResponse $response) { ob_start('mb_output_handler'); MMapManager::startSession(); //check if the session has expired MMapManager::checkSessionExpiration(); $return = null; $dataManager = DataManager::getInstance(); // restore current process using checknum $myProcManager = ProcManager::getInstance(); $myProcess = $myProcManager->getProcessByChecknum($request->getGET('checknum')); $myProcManager->setCurrentProcess($myProcess); $appDesc = new EyeosApplicationDescriptor($myProcess->getName()); $POST = $request->getPOST(); $params = array(); if (isset($POST['params'])) { $params = $dataManager->doInput($POST['params']); } else { if ($request->issetGET('params')) { $params = $request->getGET('params'); } } $methodName = $request->getGET('message'); // calling an ExecModule if (strpos($methodName, '__') === 0) { $moduleName = explode('_', substr($methodName, 2)); $methodName = $moduleName[1]; //ex: "FileChooser" $moduleName = $moduleName[0]; //ex: "browsePath" $return = call_user_func_array(array($appDesc->getApplicationClassName(), '__callModule'), array($moduleName, $methodName, $params)); } else { if ($appDesc->isJavascriptOnlyApplication()) { $return = call_user_func(array('EyeosJavascriptApplicationExecutable', $methodName), $params); } else { $return = call_user_func(array($appDesc->getApplicationClassName(), $methodName), $params); } } //try to force mime type. If there is a previous mime type defined at application level //this have no effect if (!headers_sent()) { $response->getHeaders()->append('Content-type:text/plain'); } if ($response->getBodyRenderer() === null && $response->getBody() == '') { $response->setBodyRenderer(new DataManagerBodyRenderer($return)); } }