Apache Solr open-source search software
SOLR-10458: setFollowRedirects should be deprecated in favor of Solr Client Builder methods (#1216)
Eric Pugh46bce2382f8c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 93d265199ca..4fc745ab91a 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -125,6 +125,8 @@ Bug Fixes* SOLR-16473: Fix race condition in shard split when a sub-shard is put in recovery state. (Andy Vuong via Bruno Roustant)+* SOLR-10458: Fix followRedirect property on HttpSolrClient not set when using Builder pattern. (Eric Pugh)+Build---------------------* Upgrade forbiddenapis to 3.4 (Uwe Schindler)diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.javaindex c13076337aa..79d01a5c4f4 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/HttpSolrClient.java@@ -165,11 +165,13 @@ public class HttpSolrClient extends BaseHttpSolrClient {}if (builder.httpClient != null) {+ this.internalClient = false;this.followRedirects = builder.followRedirects;this.httpClient = builder.httpClient;- this.internalClient = false;+} else {this.internalClient = true;+ this.followRedirects = builder.followRedirects;ModifiableSolrParams params = new ModifiableSolrParams();params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, followRedirects);params.set(HttpClientUtil.PROP_ALLOW_COMPRESSION, builder.compression);diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.javaindex c59085bb0e6..11d59297d3d 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/BasicHttpSolrClientTest.java@@ -542,18 +542,24 @@ public class BasicHttpSolrClientTest extends SolrJettyTestBase {@Testpublic void testRedirect() throws Exception {final String clientUrl = jetty.getBaseUrl().toString() + "/redirect/foo";- try (HttpSolrClient client = getHttpSolrClient(clientUrl)) {- SolrQuery q = new SolrQuery("*:*");- // default = false+ SolrQuery q = new SolrQuery("*:*");++ // default for redirect is false.+ try (HttpSolrClient client = new HttpSolrClient.Builder(clientUrl).build()) {SolrServerException e = expectThrows(SolrServerException.class, () -> client.query(q));assertTrue(e.getMessage().contains("redirect"));+ }- client.setFollowRedirects(true);+ try (HttpSolrClient client =+ new HttpSolrClient.Builder(clientUrl).withFollowRedirects(true).build()) {+ // No exception expectedclient.query(q);+ }- // And back again:- client.setFollowRedirects(false);- e = expectThrows(SolrServerException.class, () -> client.query(q));+ // And with explicit false:+ try (HttpSolrClient client =+ new HttpSolrClient.Builder(clientUrl).withFollowRedirects(false).build()) {+ SolrServerException e = expectThrows(SolrServerException.class, () -> client.query(q));assertTrue(e.getMessage().contains("redirect"));}}diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.javaindex d53b86c45f9..e08b12f8a3f 100644--- a/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/impl/Http2SolrClientTest.java@@ -575,27 +575,27 @@ public class Http2SolrClientTest extends SolrJettyTestBase {@Testpublic void testRedirectSwapping() throws Exception {final String clientUrl = jetty.getBaseUrl().toString() + "/redirect/foo";- try (Http2SolrClient client = getHttp2SolrClient(clientUrl)) {- SolrQuery q = new SolrQuery("*:*");- // default = false- try {- client.query(q);- fail("Should have thrown an exception.");- } catch (SolrServerException e) {- assertTrue(e.getMessage().contains("redirect"));- }+ SolrQuery q = new SolrQuery("*:*");++ // default for follow redirects is false+ try (Http2SolrClient client = new Http2SolrClient.Builder(clientUrl).build()) {++ SolrServerException e = expectThrows(SolrServerException.class, () -> client.query(q));+ assertTrue(e.getMessage().contains("redirect"));+ }- client.setFollowRedirects(true);+ try (Http2SolrClient client =+ new Http2SolrClient.Builder(clientUrl).withFollowRedirects(true).build()) {+ // shouldn't throw an exceptionclient.query(q);+ }- // And back again:- client.setFollowRedirects(false);- try {- client.query(q);- fail("Should have thrown an exception.");- } catch (SolrServerException e) {- assertTrue(e.getMessage().contains("redirect"));- }+ // set explicit false for following redirects+ try (Http2SolrClient client =+ new Http2SolrClient.Builder(clientUrl).withFollowRedirects(false).build()) {++ SolrServerException e = expectThrows(SolrServerException.class, () -> client.query(q));+ assertTrue(e.getMessage().contains("redirect"));}}