Beispiel #1
0
 /**
  * Emit JSON
  *
  * Send appropriate HTTP headers. If no Id, then return an empty string.
  *
  * @return string
  */
 public function toJson()
 {
     $this->sendHeaders();
     if (!$this->isError() && null === $this->getId()) {
         return '';
     }
     return parent::toJson();
 }
Beispiel #2
0
 public function getServerResponseFor($nativeVars)
 {
     $response = new Response();
     $response->setResult($nativeVars);
     $json = $response->toJson();
     $response = $this->makeHttpResponseFrom($json);
     return $response;
 }
Beispiel #3
0
 /**
  * Perform an JSOC-RPC request and return a response.
  *
  * @param  Request $request Request.
  * @return Response Response.
  * @throws Exception\HttpException When HTTP communication fails.
  */
 public function doRequest($request)
 {
     $this->lastRequest = $request;
     $httpRequest = $this->httpClient->getRequest();
     if ($httpRequest->getUriString() === null) {
         $this->httpClient->setUri($this->serverAddress);
     }
     $headers = $httpRequest->getHeaders();
     $headers->addHeaders(array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
     if (!$headers->get('User-Agent')) {
         $headers->addHeaderLine('User-Agent', 'Zend_Json_Server_Client');
     }
     $this->httpClient->setRawBody($request->__toString());
     $this->httpClient->setMethod('POST');
     $httpResponse = $this->httpClient->send();
     if (!$httpResponse->isSuccess()) {
         throw new Exception\HttpException($httpResponse->getReasonPhrase(), $httpResponse->getStatusCode());
     }
     $response = new Response();
     $this->lastResponse = $response;
     // import all response data form JSON HTTP response
     $response->loadJson($httpResponse->getBody());
     return $response;
 }