[
https://issues.apache.org/jira/browse/SOLR-9860?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15749368#comment-15749368
]
Ishan Chattopadhyaya commented on SOLR-9860:
--------------------------------------------
I think something like this would just suffice.
{code}
diff --git
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java
index a42e820..9b97378 100644
---
a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java
+++
b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/HttpSolrClientBuilderTest.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.lucene.util.LuceneTestCase;
+import org.apache.solr.SolrTestCaseJ4;
import org.apache.solr.client.solrj.ResponseParser;
import org.apache.solr.client.solrj.impl.HttpSolrClient.Builder;
import org.junit.Test;
@@ -73,4 +74,38 @@ public class HttpSolrClientBuilderTest extends
LuceneTestCase {
assertTrue(usedParser instanceof BinaryResponseParser);
}
}
+
+ @Test
+ public void testInvariantParams() throws IOException {
+ try(HttpSolrClient createdClient = new Builder(ANY_BASE_SOLR_URL)
+ .withHttpClient(ANY_HTTP_CLIENT)
+ .withInvariantParams(SolrTestCaseJ4.params("param", "value"))
+ .build()) {
+ assertTrue(createdClient.getHttpClient().equals(ANY_HTTP_CLIENT));
+ assertEquals("value", createdClient.getInvariantParams().get("param"));
+ }
+
+ try(HttpSolrClient createdClient = new Builder(ANY_BASE_SOLR_URL)
+ .withHttpClient(ANY_HTTP_CLIENT)
+ .withInvariantParams(SolrTestCaseJ4.params("fq", "fq1", "fq", "fq2"))
+ .build()) {
+ assertTrue(createdClient.getHttpClient().equals(ANY_HTTP_CLIENT));
+ assertEquals(2,
createdClient.getInvariantParams().getParams("fq").length);
+ }
+
+ try(HttpSolrClient createdClient = new Builder(ANY_BASE_SOLR_URL)
+ .withHttpClient(ANY_HTTP_CLIENT)
+ .withDelegationToken("mydt")
+
.withInvariantParams(SolrTestCaseJ4.params(DelegationTokenHttpSolrClient.DELEGATION_TOKEN_PARAM,
"mydt"))
+ .build()) {
+ fail();
+ } catch(Exception ex) {
+ if (ex.getMessage().equals("parameter "+
DelegationTokenHttpSolrClient.DELEGATION_TOKEN_PARAM +" is redefined.")) {
+ // we're good
+ } else {
+ throw ex;
+ }
+ }
+ }
+
}
{code}
> Enable configuring invariantParams via HttpSolrClient.Builder
> -------------------------------------------------------------
>
> Key: SOLR-9860
> URL: https://issues.apache.org/jira/browse/SOLR-9860
> Project: Solr
> Issue Type: Improvement
> Security Level: Public(Default Security Level. Issues are Public)
> Affects Versions: 6.3
> Reporter: Hrishikesh Gadre
> Priority: Minor
>
> HttpSolrClient provides a facility to add default parameters for every
> request via the invariantParams attribute. Currently HttpSolrClient.Builder
> does not provide any option to configure this attribute. This jira is to add
> this functionality.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]