Our Solr instance is on a remote server and uses https so we need to be able to set the context resource otherwise drupal_http_request() borks. e.g.

$context = array(
  'ssl' => array(
    'verify_peer' => true, 
    'cafile' => '/path/to/RapidSSL_CA_bundle.pem',
  )
);

I see there is a setStreamContext method in SearchApiSolrConnection, but how/where should that be called from?

Comments

hitfactory created an issue. See original summary.

kmcculloch’s picture

@hitfactory I just came across the need for this myself as part of a D7 project migration to PHP 7. In order to bake this configuration into search_api_solr you'd need to either patch it or override the server connection class. Rather than do that for every contrib module that might need it, I submitted a patch to this thread in D7 core:

https://www.drupal.org/node/1081192#comment-12039235

Would be interested to hear if it meets your needs.

drunken monkey’s picture

#2 does look like it might solve this, yes, thanks!
Otherwise, either override the backend class to incldude the necessary code, or maybe use a hook to call $server->getSolrConnection()->setStreamContext() early enough during search/indexing.

aklump’s picture

Register the service class like so:

 /**
  * Alter the service class to allow for self-signed cert.
  *
  * @param array $service_info
  */
 function my_module_search_api_service_info_alter(array &$service_info) {
   if (isset($service_info['search_api_solr_service'])) {
     $service_info['search_api_solr_service']['class'] = '\Drupal\my_module\MyModuleSolrService';
     $service_info['search_api_solr_service']['module'] = 'my_module';
   }
 }  

Create a service class override that sets the context :

 namespace Drupal\my_module;
 
 /**
  * Allow solr connection without verifying peer.
  */
 class MyModuleSolrService extends \SearchApiSolrService {
 
   /**
    * {@inheritdoc}
    */
   public function connect() {
     parent::connect();
     $stream_context = stream_context_create([
       'ssl' => [
         'verify_peer' => FALSE,
       ],
     ]);
     $this->solr->setStreamContext($stream_context);
   }
 
 }

Testing using Drupal 7.67 and search_api_solr 7.x-1.14

mkalkbrenner’s picture

Status: Active » Closed (outdated)

This issue was closed due to lack of activity over a long period of time. If the issue is still acute for you, feel free to reopen it and describe the current state.