/** * 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; }
/** * 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 * * @param string $url * @param string $rawPost * @param float $timeout Read timeout in seconds * @param string $contentType * @return Apache_Solr_Response * * @throws Apache_Solr_HttpTransportException 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 will be updated by the call to file_get_contents later // see http://us.php.net/manual/en/wrappers.http.php for documentation // Unfortunately, it will still create a notice in analyzers if we don't set it here $http_response_header = null; $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 Apache_Solr_HttpTransportException($response); } 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; }
/** * 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; }
/** * 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); }
/** * Call the /admin/ping servlet, can be used to quickly tell if a connection to the * server is able to be made. * * @param float $timeout maximum time to wait for ping in seconds, -1 for unlimited (default is 2) * @return float Actual time taken to ping the server, FALSE if timeout or HTTP error status occurs */ public function ping($timeout = 2) { $start = microtime(true); $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performHeadRequest($this->_pingUrl, $timeout); $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($solrResponse->getHttpStatus() == 200) { return microtime(true) - $start; } else { return false; } }
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; }
public function getRawResponse() { return $this->response->getRawResponse(); }
/** * Central method for making a post operation against this Solr Server * * @param string $sUrl The URL to be requested * @param string $sRawPost Workload to be delivered * @param float $iTimeLimit Read timeout in seconds * @param string $sContentType The content type to be included in the http-header * @return Apache_Solr_Response * * @throws Exception If a non 200 response status is returned by cURL */ protected function _sendRawPost($sUrl, $sRawPost, $iTimeLimit = false, $sContentType = 'text/xml; charset=UTF-8') { wfProfileIn('BS::' . __METHOD__); try { if ($iTimeLimit === false) { $iTimeLimit = 20; } $ch = $this->getCurlHandle(); curl_setopt($ch, CURLOPT_URL, $sUrl); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $sRawPost); curl_setopt($ch, CURLOPT_TIMEOUT, $iTimeLimit); // maximal exectuion time in seconds $data = curl_exec($ch); $this->curlConnectionCounter++; $data = str_replace("\r\n", "\n", $data); $responseParts = explode("\n\n", $data); $http_response_header = explode("\n", $responseParts[0]); $responseData = isset($responseParts[1]) ? $responseParts[1] : ''; $response = new Apache_Solr_Response($responseData, $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays); } catch (Exception $e) { wfDebugLog('ExtendedSearch', __METHOD__ . ' Error in _sendRawPost ' . $e->getMessage()); wfProfileOut('BS::' . __METHOD__); return new Apache_Solr_Response(''); } if ($response->getHttpStatus() != 200) { wfDebugLog('ExtendedSearch', __METHOD__ . ' Error in _sendRawPost ' . var_export($response, 1)); wfProfileOut('BS::' . __METHOD__); throw new Exception('"' . $response->getHttpStatus() . '" Status: ' . $response->getHttpStatusMessage(), $response->getHttpStatus()); } wfProfileOut('BS::' . __METHOD__); 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 Apache_Solr_HttpTransportException If a non 200 response status is returned */ protected function _sendRawPost($url, $rawPost, $timeout = false, $contentType = 'text/xml; charset=UTF-8') { $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performPostRequest($url, $rawPost, $contentType, $timeout); $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($solrResponse->getHttpStatus() != 200) { throw new Apache_Solr_HttpTransportException($solrResponse); } return $solrResponse; }
/** * 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 Apache_Solr_HttpTransportException 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); } // Proxy settings if ($proxyServer = parse_url($GLOBALS['TYPO3_CONF_VARS']['SYS']['curlProxyServer'])) { if ($proxyServer['host'] && $proxyServer['port']) { stream_context_set_option($this->_postContext, 'http', 'proxy', $proxyServer['host'] . ":" . $proxyServer['port'] . "/"); stream_context_set_option($this->_postContext, 'http', 'request_fulluri', true); } } // $http_response_header will be updated by the call to file_get_contents later // see http://us.php.net/manual/en/wrappers.http.php for documentation // Unfortunately, it will still create a notice in analyzers if we don't set it here $http_response_header = null; //$url = $url . "?commit=true -H \"Content-Type: text/xml\" --data-binary '". $rawPost . "'"; $response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_postContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays); //var_dump("Response:" . file_get_contents($url, false, $this->_postContext)); //exit; if ($response->getHttpStatus() != 200) { throw new Apache_Solr_HttpTransportException($response); } return $response; }
/** * Reloads a single Solr core. * * @param SolrService $solrServer A Solr server connection * @param string $coreName Name of the core to reload * @return bool TRUE if reloading the core was successful, FALSE otherwise */ protected function reloadCore(SolrService $solrServer, $coreName) { $coreReloaded = FALSE; $path = $solrServer->getPath(); $pathElements = explode('/', trim($path, '/')); $coreAdminReloadUrl = $solrServer->getScheme() . '://' . $solrServer->getHost() . ':' . $solrServer->getPort() . '/' . $pathElements[0] . '/' . 'admin/cores?action=reload&core=' . $coreName; $httpTransport = $solrServer->getHttpTransport(); $httpResponse = $httpTransport->performGetRequest($coreAdminReloadUrl); $solrResponse = new \Apache_Solr_Response($httpResponse, $solrServer->getCreateDocuments(), $solrServer->getCollapseSingleValueArrays()); if ($solrResponse->getHttpStatus() == 200) { $coreReloaded = TRUE; } return $coreReloaded; }
/** * 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; }
/** * Posts the given xml document to the Solr server without using the solr php client library. * * @param DOMDocument $solrXml * @return void */ private function sendSolrXmlToServer($solrXml) { $stream = stream_context_create(); stream_context_set_option($stream, array('http' => array('method' => 'POST', 'header' => 'Content-Type: text/xml; charset=UTF-8', 'content' => $solrXml->saveXML(), 'timeout' => '3600'))); $response = new Apache_Solr_Response(@file_get_contents($this->index_server_url . '/update', false, $stream)); $this->log->debug('Solr Response Status: ' . $response->getHttpStatus()); if (!$response->getRawResponse()) { throw new Opus_SolrSearch_Index_Exception("Solr Server {$this->index_server_url} not responding."); } }
/** * 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 HTTP DELETE operation against the Solr server * * @param $url * @param bool|float $timeout Read timeout in seconds * @return \Apache_Solr_Response */ protected function _sendRawDelete($url, $timeout = FALSE) { $logSeverity = 0; // info try { $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performDeleteRequest($url, $timeout); $solrResponse = new \Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($solrResponse->getHttpStatus() != 200) { throw new \Apache_Solr_HttpTransportException($solrResponse); } } catch (\Apache_Solr_HttpTransportException $e) { $logSeverity = 3; // fatal error $solrResponse = $e->getResponse(); } if ($GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_solr.']['logging.']['query.']['rawDelete'] || $solrResponse->getHttpStatus() != 200) { $logData = array('query url' => $url, 'response' => (array) $solrResponse); if (!empty($e)) { $logData['exception'] = $e->__toString(); } else { // trigger data parsing $solrResponse->response; $logData['response data'] = print_r($solrResponse, TRUE); } GeneralUtility::devLog('Querying Solr using GET', 'solr', $logSeverity, $logData); } return $solrResponse; }
/** * Central method for making a HTTP DELETE operation against the Solr server * * @param $url * @param bool|float $timeout Read timeout in seconds * @return Apache_Solr_Response */ protected function _sendRawDelete($url, $timeout = FALSE) { try { $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performDeleteRequest($url, $timeout); $solrResponse = new Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($solrResponse->getHttpStatus() != 200) { throw new Apache_Solr_HttpTransportException($solrResponse); } } catch (Apache_Solr_HttpTransportException $e) { $solrResponse = $e->getResponse(); } if (Mage::getStoreConfig('log/query/rawDelete')) { $logData = array('query url' => $url, 'response' => (array) $solrResponse); if (!empty($e)) { $logData['exception'] = $e->__toString(); } Mage::helper('solr')->getLogger()->debug('Querying Solr using DELETE', $logData); } return $solrResponse; }
/** * 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; }
protected function reloadSiteCores() { $coresReloaded = TRUE; $solrServers = $this->connectionManager->getConnectionsBySite($this->site); foreach ($solrServers as $solrServer) { /* @var $solrServer Tx_Solr_SolrService */ $path = $solrServer->getPath(); $pathElements = explode('/', trim($path, '/')); $coreName = array_pop($pathElements); $coreAdminReloadUrl = $solrServer->getScheme() . '://' . $solrServer->getHost() . ':' . $solrServer->getPort() . '/' . $pathElements[0] . '/' . 'admin/cores?action=reload&core=' . $coreName; $httpTransport = $solrServer->getHttpTransport(); $httpResponse = $httpTransport->performGetRequest($coreAdminReloadUrl); $solrResponse = new Apache_Solr_Response($httpResponse, $solrServer->getCreateDocuments(), $solrServer->getCollapseSingleValueArrays()); if ($solrResponse->getHttpStatus() != 200) { $coresReloaded = FALSE; $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_FlashMessage', 'Failed to reload index configuration for core "' . $coreName . '"', '', t3lib_FlashMessage::ERROR); t3lib_FlashMessageQueue::addMessage($flashMessage); } } if ($coresReloaded) { $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_FlashMessage', 'Index configuration reloaded.', '', t3lib_FlashMessage::OK); t3lib_FlashMessageQueue::addMessage($flashMessage); } }
/** * Central method for making a HTTP DELETE operation against the Solr server * * @param $url * @param bool|float $timeout Read timeout in seconds * @return \Apache_Solr_Response */ protected function _sendRawDelete($url, $timeout = false) { $logSeverity = 0; // info try { $httpTransport = $this->getHttpTransport(); $httpResponse = $httpTransport->performDeleteRequest($url, $timeout); $solrResponse = new \Apache_Solr_Response($httpResponse, $this->_createDocuments, $this->_collapseSingleValueArrays); if ($solrResponse->getHttpStatus() != 200) { throw new \Apache_Solr_HttpTransportException($solrResponse); } } catch (\Apache_Solr_HttpTransportException $e) { $logSeverity = 3; // fatal error $solrResponse = $e->getResponse(); } if ($this->configuration->getLoggingQueryRawDelete() || $solrResponse->getHttpStatus() != 200) { $logData = array('query url' => $url, 'response' => (array) $solrResponse); if (!empty($e)) { $logData['exception'] = $e->__toString(); } else { // trigger data parsing $solrResponse->response; $logData['response data'] = print_r($solrResponse, true); } GeneralUtility::devLog('Querying Solr using DELETE', 'solr', $logSeverity, $logData); } return $solrResponse; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * * @param Apache_Solr_Response $solrResponse */ private function setJsonResponseAsArray($solrResponse) { try { $this->jsonResponse = Zend_Json::decode($solrResponse->getRawResponse()); if (is_null($this->jsonResponse)) { $this->log->warn("result of decoding solr's json string is null"); } } catch (Exception $e) { $this->log->warn("error while decoding solr's json response"); } }