Apache Solr open-source search software
SOLR-10886: Using V2Request.process(solrClient) method throws NPE if the API returns an error
Cao Manh Dat751a5c814cb8
diff --git a/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java b/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.javaindex fa6d4e37729..5a8d4820b38 100644--- a/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java+++ b/solr/core/src/test/org/apache/solr/handler/V2ApiIntegrationTest.java@@ -27,6 +27,7 @@ import org.apache.solr.client.solrj.SolrServerException;import org.apache.solr.client.solrj.impl.CloudSolrClient;import org.apache.solr.client.solrj.request.CollectionAdminRequest;import org.apache.solr.client.solrj.request.V2Request;+import org.apache.solr.client.solrj.response.V2Response;import org.apache.solr.cloud.SolrCloudTestCase;import org.apache.solr.common.params.ModifiableSolrParams;import org.apache.solr.common.util.NamedList;@@ -49,14 +50,11 @@ public class V2ApiIntegrationTest extends SolrCloudTestCase {@Testpublic void testWelcomeMessage() throws Exception {- NamedList res = cluster.getSolrClient().request(- new V2Request.Builder("").build());- NamedList header = (NamedList) res.get("responseHeader");- assertEquals(0, header.get("status"));+ V2Response res = new V2Request.Builder("").build().process(cluster.getSolrClient());+ assertEquals(0, res.getStatus());- res = cluster.getSolrClient().request(new V2Request.Builder("/_introspect").build());- header = (NamedList) res.get("responseHeader");- assertEquals(0, header.get("status"));+ res = new V2Request.Builder("/_introspect").build().process(cluster.getSolrClient());+ assertEquals(0, res.getStatus());}@Testdiff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java b/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.javaindex df186e8477d..39220d1fa3d 100644--- a/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/request/V2Request.java@@ -28,14 +28,14 @@ import java.util.regex.Pattern;import org.apache.solr.client.solrj.SolrClient;import org.apache.solr.client.solrj.SolrRequest;-import org.apache.solr.client.solrj.SolrResponse;+import org.apache.solr.client.solrj.response.V2Response;import org.apache.solr.common.SolrException;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.ContentStream;import org.apache.solr.common.util.ContentStreamBase;import org.apache.solr.common.util.Utils;-public class V2Request extends SolrRequest {+public class V2Request extends SolrRequest<V2Response> {//only for debugging purposespublic static final ThreadLocal<AtomicLong> v2Calls = new ThreadLocal<>();static final Pattern COLL_REQ_PATTERN = Pattern.compile("/(c|collections)/[^/]+/(?!shards)");@@ -77,8 +77,8 @@ public class V2Request extends SolrRequest {}@Override- protected SolrResponse createResponse(SolrClient client) {- return null;+ protected V2Response createResponse(SolrClient client) {+ return new V2Response();}public static class Builder {diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/response/V2Response.java b/solr/solrj/src/java/org/apache/solr/client/solrj/response/V2Response.javanew file mode 100644index 00000000000..bd9ca9cdd4b--- /dev/null+++ b/solr/solrj/src/java/org/apache/solr/client/solrj/response/V2Response.java@@ -0,0 +1,22 @@+/*+ * Licensed to the Apache Software Foundation (ASF) under one or more+ * contributor license agreements. See the NOTICE file distributed with+ * this work for additional information regarding copyright ownership.+ * The ASF licenses this file to You under the Apache License, Version 2.0+ * (the "License"); you may not use this file except in compliance with+ * the License. You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++package org.apache.solr.client.solrj.response;++public class V2Response extends SolrResponseBase {++}