public function sendMessage(Xcom_Xfabric_Model_Message $message, array $options = array()) { $url = $this->prepareUri($message->getTopic()); Mage::getSingleton('xcom_xfabric/debug')->start('Send Request to ' . $url->getUri(), $message->getTopic(), serialize($message->getHeaders()), isset($options['message_data']) ? $options['message_data'] : ''); $adapter = $this->_getAdapter(); $adapter->setConfig($this->_config); $adapter->write(Zend_Http_Client::POST, $url, '1.1', $this->_prepareHeaders($message->getHeaders()), $message->getBody()); $result = $adapter->read(); $error = ''; $httpCode = $adapter->getInfo(CURLINFO_HTTP_CODE); if ($adapter->getErrno()) { $error = $adapter->getError(); } if (!$result || $error) { Mage::getSingleton('xcom_xfabric/debug')->stop('Unable to complete the request.', $message->getTopic(), $result, 'Unable to complete the request. ' . $error); switch ($httpCode) { case '400': $errorText = 'Bad request. '; break; case '401': $errorText = 'Request is unauthorized. '; break; case '403': $errorText = 'Request is forbidden. '; break; case '404': $errorText = 'Not Found. '; break; case '413': $errorText = 'Message is too large'; break; default: $errorText = ''; break; } throw Mage::exception('Xcom_Xfabric', Mage::helper('xcom_xfabric')->__('Unable to complete the request. ') . $errorText . $error); } $zendHttpCode = Zend_Http_Response::extractCode($result); $zendHttpMessage = Zend_Http_Response::extractMessage($result); $zendHttpBody = Zend_Http_Response::extractBody($result); if ($zendHttpCode != '200') { Mage::getSingleton('xcom_xfabric/debug')->stop('Unable to complete the request.', $message->getTopic(), $result, $zendHttpMessage . ' ' . $zendHttpBody); throw Mage::exception('Xcom_Xfabric', $zendHttpMessage . ' ' . $zendHttpBody, $zendHttpCode); } if (!empty($options['synchronous']) && !$error) { $response = $this->_getResponseMessage($message->getCorrelationId()); if (!$response) { Mage::getSingleton('xcom_xfabric/debug')->stop('Response is not received', $message->getTopic(), $result, 'No Errors'); throw Mage::exception('Xcom_Xfabric', Mage::helper('xcom_xfabric')->__('Unable to complete the request. Please refer to the User Guide ' . 'to verify your settings and try again. If the error persists, contact your administrator.')); } return $response; } Mage::getSingleton('xcom_xfabric/debug')->stop('No Response is been waiting', $message->getTopic(), $result, $error); return true; }
public function testExtractorsOnInvalidString() { // Try with an empty string $response_str = ''; $this->assertTrue(Zend_Http_Response::extractCode($response_str) === false); $this->assertTrue(Zend_Http_Response::extractMessage($response_str) === false); $this->assertTrue(Zend_Http_Response::extractVersion($response_str) === false); $this->assertTrue(Zend_Http_Response::extractBody($response_str) === ''); $this->assertTrue(Zend_Http_Response::extractHeaders($response_str) === array()); }
/** * @param Zend_Http_Response $reponse */ protected function _throwResponseErrorException(Zend_Http_Response $response) { require_once 'Zend/Service/GitHub/Exception.php'; $exceptionMessage = 'The GitHub API interaction failed. ' . '%s: %s'; $exceptionMessage = sprintf($exceptionMessage, $response->extractCode($response->asString()), $response->extractMessage($response->asString())); throw new Zend_Service_GitHub_Exception($exceptionMessage); }