Apache Lucene open-source search software
adding an error message if you create a CommonsHttpSolrServer with parameters in the baseURL
Ryan McKinleybb26cafda26f
diff --git a/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java b/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.javaindex b53fd08cc70..d0033875dbe 100644--- a/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java+++ b/client/java/solrj/src/org/apache/solr/client/solrj/impl/CommonsHttpSolrServer.java@@ -109,11 +109,14 @@ public class CommonsHttpSolrServer extends SolrServerpublic CommonsHttpSolrServer(URL baseURL, HttpClient client, ResponseParser parser) {- this._baseURL = baseURL.toExternalForm();- if( this._baseURL.endsWith( "/" ) ) {- this._baseURL = this._baseURL.substring( 0, this._baseURL.length()-1 );+ _baseURL = baseURL.toExternalForm();+ if( _baseURL.endsWith( "/" ) ) {+ _baseURL = _baseURL.substring( 0, _baseURL.length()-1 );}-+ if( _baseURL.indexOf( '?' ) >=0 ) {+ throw new RuntimeException( "Invalid base url for solrj. The base URL must not contain parameters: "+_baseURL );+ }+_httpClient = (client == null) ? new HttpClient(new MultiThreadedHttpConnectionManager()) : client;if (client == null) {diff --git a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.javaindex f74aa82915c..d0c4a20b42c 100644--- a/client/java/solrj/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java+++ b/client/java/solrj/test/org/apache/solr/client/solrj/embedded/SolrExampleJettyTest.java@@ -22,6 +22,7 @@ import org.apache.solr.client.solrj.SolrServer;import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;import org.apache.solr.core.SolrCore;import org.apache.solr.schema.SchemaField;+import org.junit.Assert;/*** TODO? perhaps use:@@ -79,4 +80,17 @@ public class SolrExampleJettyTest extends SolrExampleTests {throw new RuntimeException( ex );}}++ public void testBadSetup()+ {+ try {+ // setup the server...+ String url = "http://localhost/?core=xxx";+ CommonsHttpSolrServer s = new CommonsHttpSolrServer( url );+ Assert.fail( "CommonsHttpSolrServer should not allow a path with a parameter: "+s.getBaseURL() );+ }+ catch( Exception ex ) {+ // expected+ }+ }}