Exemplo n.º 1
0
 /**
  * Processes an action result by dispatching the configured servlet.
  *
  * @param \AppserverIo\Psr\Servlet\ServletRequestInterface  $servletRequest  The request instance
  * @param \AppserverIo\Psr\Servlet\ServletResponseInterface $servletResponse The response sent back to the client
  *
  * @return void
  */
 public function process(ServletRequestInterface $servletRequest, ServletResponseInterface $servletResponse)
 {
     // load the action instance
     $action = $this->getAction();
     // query whether the action contains errors or not
     if ($action instanceof ValidationAware && $action->hasErrors()) {
         $content = $action->getErrors();
     } else {
         $content = $servletRequest->getAttribute(JsonResult::DATA);
     }
     // add the header for the JSON content type
     $servletResponse->addHeader(HttpProtocol::HEADER_CONTENT_TYPE, 'application/json');
     // append the JSON encoded content to the servlet response
     $servletResponse->appendBodyStream(json_encode($content));
 }