adding an error message if you create a CommonsHttpSolrServer with parameters in the baseURL

git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@663645 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ryan McKinley 2008-06-05 16:02:35 +00:00
parent f2ce567269
commit bb26cafda2
2 changed files with 21 additions and 4 deletions

View File

@ -109,11 +109,14 @@ public class CommonsHttpSolrServer extends SolrServer
public 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) {

View File

@ -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
}
}
}