Esempio n. 1
0
 /**
  * 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;
 }
Esempio n. 2
0
 /**
  * Handles a HTTP request
  *
  * @return void
  */
 public function handleRequest()
 {
     // Create the request very early so the Resource Management has a chance to grab it:
     $this->request = Request::createFromEnvironment();
     $this->response = new Response();
     $this->boot();
     $this->resolveDependencies();
     $this->request->injectSettings($this->settings);
     $this->router->setRoutesConfiguration($this->routesConfiguration);
     $actionRequest = $this->router->route($this->request);
     $this->securityContext->injectRequest($actionRequest);
     $this->dispatcher->dispatch($actionRequest, $this->response);
     $this->response->makeStandardsCompliant($this->request);
     $this->response->send();
     $this->bootstrap->shutdown('Runtime');
     $this->exit->__invoke();
 }
Esempio n. 3
0
 /**
  * Calls the given action of the given controller
  *
  * @param string $controllerName The name of the controller to be called
  * @param string $controllerPackageKey The package key the controller resides in
  * @param string $controllerActionName The name of the action to be called, e.g. 'index'
  * @param array $arguments Optional arguments passed to controller
  * @param string $format The request format, defaults to 'html'
  * @return string The result of the controller action
  * @deprecated since 1.1
  */
 protected function sendWebRequest($controllerName, $controllerPackageKey, $controllerActionName, array $arguments = array(), $format = 'html')
 {
     $this->setupHttp();
     $route = new \TYPO3\FLOW3\Mvc\Routing\Route();
     $route->setName('sendWebRequest Route');
     $uriPattern = 'test/' . uniqid();
     $route->setUriPattern($uriPattern);
     $route->setDefaults(array('@package' => $controllerPackageKey, '@controller' => $controllerName, '@action' => $controllerActionName, '@format' => $format));
     $route->setAppendExceedingArguments(TRUE);
     $this->router->addRoute($route);
     $uri = new \TYPO3\FLOW3\Http\Uri('http://baseuri/' . $uriPattern);
     $response = $this->browser->request($uri, 'POST', $arguments);
     return $response->getContent();
 }