Apache Lucene open-source search software
SOLR-8317: add responseHeader and response accessors to SolrQueryResponse. TestSolrQueryResponse tests for accessors.
Christine Poerschke6e4bb7c60f3e
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 5f7154d22ec..9e528426206 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -358,6 +358,8 @@ Other Changes* SOLR-8419: TermVectorComponent for distributed search now requires a uniqueKey in the schema. Also, it no longerreturns "uniqueKeyField" in the response. (David Smiley)+* SOLR-8317: add responseHeader and response accessors to SolrQueryResponse. (Christine Poerschke)+================== 5.4.0 ==================Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this releasediff --git a/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java b/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.javaindex 5fc3198b624..4db52453399 100644--- a/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java+++ b/solr/core/src/java/org/apache/solr/response/SolrQueryResponse.java@@ -67,6 +67,8 @@ import org.apache.solr.search.SolrReturnFields;*/public class SolrQueryResponse {public static final String NAME = "response";+ private static final String RESPONSE_HEADER_KEY = "responseHeader";+ private static final String RESPONSE_KEY = "response";/*** Container for user defined values@@ -171,12 +173,32 @@ public class SolrQueryResponse {return err;}+ /** Set response header */+ public void addResponseHeader(NamedList<Object> header) {+ values.add(RESPONSE_HEADER_KEY, header);+ }++ /** Clear response header */+ public void removeResponseHeader() {+ values.remove(RESPONSE_HEADER_KEY);+ }+/** Response header to be logged */public NamedList<Object> getResponseHeader() {@SuppressWarnings("unchecked")- SimpleOrderedMap<Object> header = (SimpleOrderedMap<Object>) values.get("responseHeader");+ SimpleOrderedMap<Object> header = (SimpleOrderedMap<Object>) values.get(RESPONSE_HEADER_KEY);return header;}++ /** Set response */+ public void addResponse(Object response) {+ values.add(RESPONSE_KEY, response);+ }++ /** Return response */+ public Object getResponse() {+ return values.get(RESPONSE_KEY);+ }/** Add a value to be logged.*diff --git a/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java b/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.javaindex 01b9a484829..e012d734f44 100644--- a/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java+++ b/solr/core/src/test/org/apache/solr/response/TestSolrQueryResponse.java@@ -63,6 +63,16 @@ public class TestSolrQueryResponse extends LuceneTestCase {}}+ @Test+ public void testResponse() throws Exception {+ final SolrQueryResponse response = new SolrQueryResponse();+ assertEquals("response initial value", null, response.getResponse());+ final Object newValue = (random().nextBoolean()+ ? (random().nextBoolean() ? new String("answer") : new Integer(42)) : null);+ response.addResponse(newValue);+ assertEquals("response new value", newValue, response.getResponse());+ }+@Testpublic void testToLog() throws Exception {final SolrQueryResponse response = new SolrQueryResponse();@@ -247,6 +257,19 @@ public class TestSolrQueryResponse extends LuceneTestCase {assertEquals("exception new value", newValue, response.getException());}+ @Test+ public void testResponseHeader() throws Exception {+ final SolrQueryResponse response = new SolrQueryResponse();+ assertEquals("responseHeader initially present", null, response.getResponseHeader());+ final NamedList<Object> newValue = new SimpleOrderedMap<>();+ newValue.add("key1", "value1");+ response.add("key2", "value2");+ response.addResponseHeader(newValue);+ assertEquals("responseHeader new value", newValue, response.getResponseHeader());+ response.removeResponseHeader();+ assertEquals("responseHeader removed value", null, response.getResponseHeader());+ }+@Testpublic void testHttpCaching() throws Exception {final SolrQueryResponse response = new SolrQueryResponse();