Skip to content

Commit

Permalink
remove schema fallback URL for Solr < 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Jul 24, 2016
1 parent 752f899 commit 2585081
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 42 deletions.
36 changes: 16 additions & 20 deletions src/collective/solr/solr.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,24 +308,20 @@ def search(self, **params):
return response

def getSchema(self):
schema_urls = (
'%s/admin/file/?file=schema.xml', # solr 1.3
'%s/admin/get-file.jsp?file=schema.xml') # solr 1.2
for url in schema_urls:
logger.debug('getting schema from: %s', url % self.solrBase)
try:
self.conn.request('GET', url % self.solrBase)
response = self.conn.getresponse()
except (
socket.error, httplib.CannotSendRequest,
httplib.ResponseNotReady, httplib.BadStatusLine
):
# see `doPost` method for more info about these exceptions
self.__reconnect()
self.conn.request('GET', url % self.solrBase)
response = self.conn.getresponse()
if response.status == 200:
xml = response.read()
return SolrSchema(xml.strip())
self.__reconnect() # force a new connection for each url
schema_url = '%s/admin/file/?file=schema.xml'
logger.debug('getting schema from: %s', schema_url % self.solrBase)
try:
self.conn.request('GET', schema_url % self.solrBase)
response = self.conn.getresponse()
except (
socket.error, httplib.CannotSendRequest,
httplib.ResponseNotReady, httplib.BadStatusLine
):
# see `doPost` method for more info about these exceptions
self.__reconnect()
self.conn.request('GET', schema_url % self.solrBase)
response = self.conn.getresponse()
if response.status == 200:
xml = response.read()
return SolrSchema(xml.strip())
self.__errcheck(response) # raise a SolrConnectionException
22 changes: 0 additions & 22 deletions src/collective/solr/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from collective.solr.interfaces import IZCMLSolrConnectionConfig
from collective.solr.mangler import mangleQuery
from collective.solr.testing import LEGACY_COLLECTIVE_SOLR_FUNCTIONAL_TESTING
from collective.solr.tests.utils import fakeServer
from collective.solr.tests.utils import fakehttp
from collective.solr.tests.utils import getData
from collective.solr.utils import getConfig
Expand Down Expand Up @@ -205,27 +204,6 @@ def testInactiveException(self):
# finally:
# thread.join() # the server thread must always be joined

def testSchemaUrlFallback(self):
config = getConfig()
config.active = True
config.port = 55555 # random port so the real solr can still run # noqa

def notfound(handler): # set up fake 404 response
self.assertEqual(handler.path,
'/solr/admin/file/?file=schema.xml')
handler.send_response(404, getData('not_found.txt'))

def solr12(handler): # set up response with the schema
self.assertEqual(handler.path,
'/solr/admin/get-file.jsp?file=schema.xml')
handler.send_response(200, getData('schema.xml'))
responses = [notfound, solr12]
thread = fakeServer(responses, config.port)
schema = queryUtility(ISolrConnectionManager).getSchema()
thread.join() # the server thread must always be joined
self.assertEqual(responses, [])
self.assertEqual(len(schema), 21) # 21 items defined in schema.xml


class ZCMLSetupTests(TestCase):

Expand Down

0 comments on commit 2585081

Please sign in to comment.