Beispiel #1
0
 /**
  * To perform batch request
  *
  * @throws ODataServiceException
  */
 protected function PerformBatchRequest()
 {
     $credentialInHeaders = false;
     $uri = $this->_context->GetBaseUriWithSlash() . '$batch';
     $httpBatchRequest = new HttpBatchRequest($uri, $this->_batchBoundary, $this->_batchRequestBody, $this->_context->Credential, $this->_context->HttpProxy, $this->_context->CustomHeaders, $credentialInHeaders);
     try {
         //require a try-catch block to handle curl error due to curl_exec
         //failure (like failed to connect to host)and missing of changeset
         //boundary in batchresponse tested in BatchResponse::Create invoken
         //by HttpBatchRequest::GetResponse.
         $this->_context->OnBeforeRequestInternal($httpBatchRequest->GetRawHttpRequest());
         $this->_httpBatchResponse = $httpBatchRequest->GetResponse();
         $this->_context->OnAfterResponseInternal($this->_httpBatchResponse->GetAsHttpResponse());
     } catch (InvalidOperation $exception) {
         throw new ODataServiceException($exception->getError() . $exception->getDetailedError(), '', array(), null);
     }
     //Error check for batch Response ex:UnAuthorized
     if (!$this->_httpBatchResponse->IsError()) {
         $this->_httpResponses = $this->_httpBatchResponse->GetSubBatchHttpResponses();
     } else {
         throw new ODataServiceException($this->_httpBatchResponse->GetMessage(), '', $this->_httpBatchResponse->GetHeaders(), $this->_httpBatchResponse->GetCode());
     }
 }
Beispiel #2
0
 /**
  * Construct a HttpBatchResponse object from raw batch response.
  *
  * @param string $httpBatchResponse
  * @param HttpBatchResponse
  */
 public static function Create($httpBatchResponse)
 {
     $changesetBoundary = null;
     $httpResponses = array();
     if (!self::CheckIsError($httpBatchResponse)) {
         $changesetBoundary = HttpBatchResponse::ExtractChangesetBoundary($httpBatchResponse);
         if (!isset($changesetBoundary)) {
             throw new InvalidOperation(Resource::InvalidBatchResponseNoCSBoundary);
         }
         $httpResponses = HttpBatchResponse::ExtractHttpResponses($httpBatchResponse, $changesetBoundary);
     }
     return new HttpBatchResponse($httpResponses, $httpBatchResponse, $changesetBoundary);
 }
Beispiel #3
0
 /**
  * To perform a http batch request and return instance of HTTPBatchResponse
  * class representing the batch response.
  *
  * @return HttpBatchResponse
  */
 public function GetResponse()
 {
     $rawHttpBatchResponse = $this->_httpRequest->GetResponse();
     return HttpBatchResponse::Create($rawHttpBatchResponse);
 }