/** * Central method for making a post operation against this Solr Server * * @see Drupal_Apache_Solr_Service::_sendRawGet() */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { $this->add_request_id($url); list($cookie, $nonce) = acquia_search_auth_cookie($url, $rawPost); $request_headers = array('Content-Type' => $contentType, 'Cookie' => $cookie); list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout); $response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage() . "\n<br />request ID: {$id} <br />" . $url, $response->getHttpStatus()); } return $response; }
/** * Central method for making a post operation against this Solr Server * * @see Drupal_Apache_Solr_Service::_sendRawGet() */ 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); $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); $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); } return $response; }
/** * Central method for making a post operation against this Solr Server * * @see Drupal_Apache_Solr_Service::_sendRawGet() */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { if (variable_get('apachesolr_read_only', 0)) { throw new Exception('Operating in read-only mode; updates are disabled.'); } $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); $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); } return $response; }
/** * HttpTransportException Constructor * * @param Apache_Solr_Response $response */ public function __construct(Apache_Solr_Response $response) { parent::__construct("'{$response->getHttpStatus()}' Status: {$response->getHttpStatusMessage()}", $response->getHttpStatus()); $this->_response = $response; }
/** * Central method for making a post operation against this Solr Server * * @see Apache_Solr_Service::_sendRawGet() */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { $request_headers = array('Content-Type' => $contentType); list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout); $response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays); $code = (int) $response->getHttpStatus(); if ($code != 200) { $message = $response->getHttpStatusMessage(); if ($code >= 400 && $code != 403 && $code != 404) { // Add details, like Solr's exception message. $message .= $response->getRawResponse(); } throw new Exception('"' . $code . '" Status: ' . $message); } return $response; }
/** * Central method for making a post operation against this Solr Server * * @see Apache_Solr_Service::_sendRawGet() */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { $request_headers = array('Content-Type' => $contentType); list($data, $headers) = $this->_makeHttpRequest($url, 'POST', $request_headers, $rawPost, $timeout); $response = new Apache_Solr_Response($data, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage()); } return $response; }
/** * Logs the item and what document was created from it * * @param Tx_Solr_IndexQueue_Item The item that is being indexed. * @param array An array of Solr documents created from the item's data * @param Apache_Solr_Response The Solr response for the particular index document */ protected function log(Tx_Solr_IndexQueue_Item $item, array $itemDocuments, Apache_Solr_Response $response) { if (!$this->loggingEnabled) { return; } $message = 'Index Queue indexing ' . $item->getType() . ':' . $item->getRecordUid() . ' - '; $severity = 0; // info // preparing data $documents = array(); foreach ($itemDocuments as $document) { $documents[] = (array) $document; } $logData = array('item' => (array) $item, 'documents' => $documents, 'response' => (array) $response); if ($response->getHttpStatus() == 200) { $severity = -1; $message .= 'Success'; } else { $severity = 3; $message .= 'Failure'; $logData['status'] = $response->getHttpStatus(); $logData['status message'] = $response->getHttpStatusMessage(); } \TYPO3\CMS\Core\Utility\GeneralUtility::devLog($message, 'solr', $severity, $logData); }
public function searchByPost($query, $offset = 0, $limit = 10, $params = array()) { if (!is_array($params)) { $params = array(); } // construct our full parameters // sending the version is important in case the format changes $params['version'] = self::SOLR_VERSION; // common parameters in this interface $params['wt'] = self::SOLR_WRITER; $params['json.nl'] = $this->_namedListTreatment; $params['q'] = $query; $params['start'] = $offset; $params['rows'] = $limit; //$params['qt'] = 'standard'; // use http_build_query to encode our arguments because its faster // than urlencoding all the parts ourselves in a loop $queryString = http_build_query($params, null, $this->_queryStringDelimiter); // because http_build_query treats arrays differently than we want to, correct the query // string by changing foo[#]=bar (# being an actual number) parameter strings to just // multiple foo=bar strings. This regex should always work since '=' will be urlencoded // anywhere else the regex isn't expecting it $queryString = preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $queryString); $postdata = $queryString; $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata)); $context = stream_context_create($opts); //$result = file_get_contents('http://example.com/submit.php', false, $context); $response = new Apache_Solr_Response(@file_get_contents($this->_searchUrl, false, $context), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus()); } return $response; }
/** * Central method for making a post operation against this Solr Server * * @param string $url * @param string $rawPost * @param float $timeout Read timeout in seconds * @param string $contentType * @return Apache_Solr_Response * * @throws Exception If a non 200 response status is returned */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { stream_context_set_option($this->_postContext, array('http' => array('method' => 'POST', 'header' => "Content-Type: {$contentType}", 'content' => $rawPost, 'timeout' => $this->_defaultTimeout))); // set the timeout if specified if ($timeout !== FALSE && $timeout > 0.0) { // timeouts with file_get_contents seem to need // to be halved to work as expected $timeout = (double) $timeout / 2; stream_context_set_option($this->_postContext, 'http', 'timeout', $timeout); } //$http_response_header is set by file_get_contents $response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus()); } return $response; }
/** * Central method for making a post operation against this Solr Server * * @param string $url * @param string $rawPost * @param float $timeout Read timeout in seconds * @param string $contentType * @return Apache_Solr_Response * * @throws Exception If a non 200 response status is returned */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { //ensure content type is correct stream_context_set_option($this->_postContext, 'http', 'header', 'Content-Type: ' . $contentType); //set the read timeout if specified if ($timeout !== FALSE) { stream_context_set_option($this->_postContext, 'http', 'timeout', $timeout); } //set the content stream_context_set_option($this->_postContext, 'http', 'content', $rawPost); //$http_response_header is set by file_get_contents $response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus()); } return $response; }
/** * Read response for prepared curl request * * @return Apache_Solr_Response * * @throws Exception If a non 200 response status is returned */ protected function _getResponse() { $response = $this->_curlAdapter->read(); $this->_curlAdapter->close(); list($headers, $body) = explode("\r\n\r\n", $response, 2); $headers = explode("\r\n", $headers); $response = new Apache_Solr_Response($body, $headers, $this->_createDocuments, $this->_collapseSingleValueArrays); $httpStatus = $response->getHttpStatus(); if ($httpStatus != 200) { throw new Exception('"' . $httpStatus . '" Status: ' . $response->getHttpStatusMessage(), $httpStatus); } return $response; }
/** * Make a request to a servlet (a path) that's not a standard path. * * @param string $servlet * A path to be added to the base Solr path. e.g. 'extract/tika' * * @param array $params * Any request parameters when constructing the URL. * * @param string $method * 'GET', 'POST', 'PUT', or 'HEAD'. * * @param array $request_headers * Keyed array of header names and values. Should include 'Content-Type' * for POST or PUT. * * @param string $rawPost * Must be an empty string unless method is POST or PUT. * * @param float $timeout * Read timeout in seconds or FALSE. * * @return * Apache_Solr_Response object */ public function makeServletRequest($servlet, $params = array(), $method = 'GET', $request_headers = array(), $rawPost = '', $timeout = FALSE) { if ($method == 'GET' || $method == 'HEAD') { // Make sure we are not sending a request body. $rawPost = ''; } // Add default params. $params += array('wt' => self::SOLR_WRITER); $url = $this->_constructUrl($servlet, $params); $id = $this->add_request_id($url); // We assume we only authenticate the URL for other servlets. list($cookie, $nonce) = acquia_search_auth_cookie($url); if (empty($cookie)) { throw new Exception('Invalid authentication string - subscription keys expired or missing.'); } $request_headers += array('Cookie' => $cookie, 'User-Agent' => 'acquia_search/' . ACQUIA_SEARCH_VERSION); list($data, $headers) = $this->_makeHttpRequest($url, $method, $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(); 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; }
/** * Central method for making a post operation against this Solr Server * * @param string $url * @param string $rawPost * @param float $timeout Read timeout in seconds * @param string $contentType * @return Apache_Solr_Response * * @throws Exception If a non 200 response status is returned */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { //set up the stream context for posting with file_get_contents $context = stream_context_create( array( 'http' => array( // set HTTP method 'method' => 'POST', // Add our posted content type 'header' => "Content-Type: $contentType", // the posted content 'content' => $rawPost ) ) ); // set the timeout if specified, without this I assume // that the default_socket_timeout ini setting is used if ($timeout !== FALSE && $timeout > 0.0) { // timeouts with file_get_contents seem to need // to be halved to work as expected $timeout = (float) $timeout / 2; stream_context_set_option($context, 'http', 'timeout', $timeout); } //$http_response_header is set by file_get_contents $response = new Apache_Solr_Response(@file_get_contents($url, false, $context), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus()); } return $response; }
/** * Central method for making a post operation against this Solr Server * * @param string $url * @param string $rawPost * @param string $contentType * @return Apache_Solr_Response * * @throws Exception If a non 200 response status is returned */ private function _sendRawPost($url, $rawPost, $contentType = 'text/xml; charset=UTF-8') { //ensure content type is correct stream_context_set_option($this->_postContext, 'http', 'header', 'Content-Type: ' . $contentType . "\r\n"); //set the content stream_context_set_option($this->_postContext, 'http', 'content', $rawPost); //$http_response_header is set by file_get_contents $response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage()); } return $response; }
/** * Central method for making a post operation against this Solr Server * * @param string $url * @param string $rawPost * @param float $timeout Read timeout in seconds * @param string $contentType * @return Apache_Solr_Response * * @throws Exception If a non 200 response status is returned */ protected function _sendRawPost($url, $rawPost, $timeout = FALSE, $contentType = 'text/xml; charset=UTF-8') { list($output, $info) = $this->_curlGetContents($url, $rawPost, $timeout, $contentType); $response = new Apache_Solr_Response($output, $info, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($response->getHttpStatus() != 200) { throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus()); } return $response; }