You are here

protected function Acquia_Search_Service::_sendRawPost in Acquia Search 6

Central method for making a post operation against this Solr Server

See also

Drupal_Apache_Solr_Service::_sendRawGet()

1 call to Acquia_Search_Service::_sendRawPost()
Acquia_Search_Service::add in ./Acquia_Search_Service.php
Raw Add Method. Takes a raw post body and sends it to the update service. Post body should be a complete and well formed "add" xml document.

File

./Acquia_Search_Service.php, line 82

Class

Acquia_Search_Service
Starting point for the Solr API. Represents a Solr server resource and has methods for pinging, adding, deleting, committing, optimizing and searching.

Code

protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') {
  $id = $this
    ->add_request_id($url);
  list($cookie, $nonce) = acquia_search_auth_cookie($url, $rawPost);
  if (empty($cookie)) {
    throw new Exception('Invalid authentication string - subscription keys expired or missing.');
  }
  $request_headers = array(
    'Content-Type' => $contentType,
    'Cookie' => $cookie,
    'User-Agent' => 'acquia_search/' . ACQUIA_SEARCH_VERSION,
  );
  list($data, $headers) = $this
    ->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout);
  $response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays);
  $hmac = acquia_search_extract_hmac($headers);
  $code = (int) $response
    ->getHttpStatus();
  if ($code != 200) {
    $message = $response
      ->getHttpStatusMessage() . "\n request ID: {$id} \n";
    if ($code >= 400 && $code != 403 && $code != 404) {

      // Add details, like Solr's exception message.
      $message .= $response
        ->getRawResponse();
    }
    throw new Exception('"' . $code . '" Status: ' . $message);
  }
  elseif (!acquia_search_valid_response($hmac, $nonce, $data)) {
    throw new Exception('Authentication of search content failed url: ' . $url);
  }
  return $response;
}