/**
  * Sends the given HTTP request
  *
  * @param \TYPO3\FLOW3\Http\Request $request
  * @return \TYPO3\FLOW3\Http\Response
  * @throws \TYPO3\FLOW3\Http\Exception
  * @api
  */
 public function sendRequest(Request $request)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof \TYPO3\FLOW3\Tests\FunctionalTestRequestHandler) {
         throw new \TYPO3\FLOW3\Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
     }
     $response = new Response();
     $requestHandler->setHttpRequest($request);
     $requestHandler->setHttpResponse($response);
     try {
         $actionRequest = $this->router->route($request);
         $this->securityContext->clearContext();
         $this->securityContext->injectRequest($actionRequest);
         $this->dispatcher->dispatch($actionRequest, $response);
     } catch (\Exception $exception) {
         $pathPosition = strpos($exception->getFile(), 'Packages/');
         $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile();
         $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : '';
         $content = PHP_EOL . 'Uncaught Exception in FLOW3 ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL;
         $content .= 'thrown in file ' . $filePathAndName . PHP_EOL;
         $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL;
         $content .= \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL;
         $response->setStatus(500);
         $response->setContent($content);
         $response->setHeader('X-FLOW3-ExceptionCode', $exceptionCodeNumber);
         $response->setHeader('X-FLOW3-ExceptionMessage', $exception->getMessage());
     }
     return $response;
 }
Exemple #2
0
 /**
  * Writes information about the given exception into the log.
  *
  * @param \Exception $exception The exception to log
  * @param array $additionalData Additional data to log
  * @return void
  * @api
  */
 public function logException(\Exception $exception, array $additionalData = array())
 {
     $backTrace = $exception->getTrace();
     $className = isset($backTrace[0]['class']) ? $backTrace[0]['class'] : '?';
     $methodName = isset($backTrace[0]['function']) ? $backTrace[0]['function'] : '?';
     $message = $this->getExceptionLogMessage($exception);
     if ($exception->getPrevious() !== NULL) {
         $additionalData['previousException'] = $this->getExceptionLogMessage($exception->getPrevious());
     }
     $explodedClassName = explode('\\', $className);
     // FIXME: This is not really the package key:
     $packageKey = isset($explodedClassName[1]) ? $explodedClassName[1] : NULL;
     if (!file_exists(FLOW3_PATH_DATA . 'Logs/Exceptions')) {
         mkdir(FLOW3_PATH_DATA . 'Logs/Exceptions');
     }
     if (file_exists(FLOW3_PATH_DATA . 'Logs/Exceptions') && is_dir(FLOW3_PATH_DATA . 'Logs/Exceptions') && is_writable(FLOW3_PATH_DATA . 'Logs/Exceptions')) {
         $referenceCode = $exception instanceof \TYPO3\FLOW3\Exception ? $exception->getReferenceCode() : date('YmdHis', $_SERVER['REQUEST_TIME']) . substr(md5(rand()), 0, 6);
         $exceptionDumpPathAndFilename = FLOW3_PATH_DATA . 'Logs/Exceptions/' . $referenceCode . '.txt';
         file_put_contents($exceptionDumpPathAndFilename, $message . PHP_EOL . PHP_EOL . \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($backTrace, FALSE, TRUE));
         $message .= ' - See also: ' . basename($exceptionDumpPathAndFilename);
     } else {
         $this->log(sprintf('Could not write exception backtrace into %s because the directory could not be created or is not writable.', FLOW3_PATH_DATA . 'Logs/Exceptions/'), LOG_WARNING, array(), 'FLOW3', __CLASS__, __FUNCTION__);
     }
     $this->log($message, LOG_CRIT, $additionalData, $packageKey, $className, $methodName);
 }
 /**
  * Returns a link pointing to Forge to create a new issue.
  *
  * @param \Exception $exception
  * @return string
  */
 protected function getCreateIssueLink(\Exception $exception)
 {
     $filename = basename($exception->getFile());
     return 'http://forge.typo3.org/projects/package-typo3-flow3/issues/new?issue[subject]=' . urlencode(get_class($exception) . ' thrown in file ' . $filename) . '&issue[description]=' . urlencode($exception->getMessage() . chr(10) . strip_tags(str_replace(array('<br />', '</pre>'), chr(10), \TYPO3\FLOW3\Error\Debugger::getBacktraceCode($exception->getTrace(), FALSE))) . chr(10) . 'Please include more helpful information!') . '&issue[category_id]=554&issue[priority_id]=7';
 }