public function processRequest(MMapRequest $request, MMapResponse $response, AppExecutionContext $appContext = null) { $status = ob_get_status(); $response->getHeaders()->append('Content-type:text/javascript'); if (isset($status['name']) && $status['name'] != 'ob_gzhandler') { ob_start("ob_gzhandler"); } try { MMapManager::startSession(); if (!$appContext instanceof AppExecutionContext) { $appContext = new AppExecutionContext(); $appContext->initFromRequest($request); } $appDesc = $appContext->getApplicationDescriptor(); // Check if the session has expired only if the application we want to execute is not "init" nor "logout" // FIXME: Not sure this way for checking session is the best here (maybe a flag in the metadata instead?) if ($appDesc->getName() != 'init' && $appDesc->getName() != 'logout') { MMapManager::checkSessionExpiration(); } // Restore parent process if available try { $checknum = (int) $request->getGET('checknum'); $procFather = ProcManager::getInstance()->getProcessByChecknum($checknum); ProcManager::getInstance()->setCurrentProcess($procFather); // Access control is based on current user, contained in the login context of // the current process, so we can only perform security checks when a process // is active. // In case no login context is defined, we can be sure that almost nothing unsafe // will be done, because this element is required in most of the operations. if ($procFather->getLoginContext() !== null) { SecurityManager::getInstance()->checkExecute($appDesc); } } catch (EyeProcException $e) { } // Start process (PHP) $this->startProcess($appContext); // Append necessary scripts and execute JS code (actually, only append it to the $response body) $appDesc->executeJavascript($appContext, $response); } catch (Exception $e) { self::$Logger->error('Uncaught exception while processing request: ' . $request); self::$Logger->error('Exception message: ' . $e->getMessage()); if (self::$Logger->isDebugEnabled()) { self::$Logger->debug(ExceptionStackUtil::getStackTrace($e, false)); } // Special processing on session expiration if ($e instanceof EyeSessionExpiredException) { $controlMessageBodyRenderer = new ControlMessageBodyRenderer(ControlMessageBodyRenderer::TYPE_SESSION_EXPIRED); } else { // Remove incomplete process $proc = $appContext->getProcess(); if ($proc instanceof Process) { try { ProcManager::getInstance()->kill($proc); } catch (Exception $e) { self::$Logger->error('Cannot kill incomplete process: ' . $proc); self::$Logger->error('Exception message: ' . $e->getMessage()); } } $controlMessageBodyRenderer = new ControlMessageBodyRenderer(ControlMessageBodyRenderer::TYPE_EXCEPTION, $e); } // 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 exception summary // in argument. $responseContent = $controlMessageBodyRenderer->getRenderedBody(); $response->setBody('eyeos._callbackProxyWithContent(null, null, null, ' . $responseContent . ');'); } $this->handleClientMessageQueue($response); }