/** * Send response to the client, render exceptions if they are present. */ public function sendResponse() { try { if ($this->isException()) { $this->_renderMessages(); } parent::sendResponse(); } catch (Exception $e) { // If the server does not support all MIME types accepted by the client it SHOULD send 406 (not acceptable). $httpCode = $e->getCode() == Mage_Webapi_Exception::HTTP_NOT_ACCEPTABLE ? Mage_Webapi_Exception::HTTP_NOT_ACCEPTABLE : Mage_Webapi_Exception::HTTP_INTERNAL_ERROR; /** If error was encountered during "error rendering" process then use error renderer. */ $this->_errorProcessor->renderException($e, $httpCode); } }
/** * Test addMessage, hasMessage, getMessage and clearMessages methods. */ public function testMessagesCrud() { /** Test new object does not contain any messages. */ $this->assertFalse($this->_response->hasMessages(), 'New object contains messages.'); /** Test message adding functionality. */ $this->_response->addMessage('Message text', 200, array('key' => 'value'), Mage_Webapi_Controller_Response::MESSAGE_TYPE_SUCCESS); $this->assertTrue($this->_response->hasMessages(), 'New message is not added right.'); /** Test message getting functionality. */ $expectedMessage = array(Mage_Webapi_Controller_Response::MESSAGE_TYPE_SUCCESS => array(array('key' => 'value', 'message' => 'Message text', 'code' => 200))); $this->assertEquals($expectedMessage, $this->_response->getMessages(), 'Message is got wrong.'); /** Test message clearing functionality. */ $this->_response->clearMessages(); $this->assertFalse($this->_response->hasMessages(), 'Message is not cleared.'); }
/** * Set body to response object. * * @param string $responseBody * @return Mage_Webapi_Controller_Dispatcher_Soap */ protected function _setResponseBody($responseBody) { $this->_response->setBody(preg_replace('/<\\?xml version="([^\\"]+)"([^\\>]+)>/i', '<?xml version="$1" encoding="' . $this->_soapServer->getApiCharset() . '"?>', $responseBody)); return $this; }