Skip to content

Commit efbb007

Browse files
committed
I dont think this is right but cant prove it. I dont think we need a null raw response writer
1 parent 37bdfab commit efbb007

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

solr/core/src/java/org/apache/solr/response/RawResponseWriter.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class RawResponseWriter implements QueryResponseWriter {
4747
*/
4848
public static final String CONTENT = "content";
4949

50-
private String _baseWriter = null;
50+
private String baseWriter = null;
5151

5252
/**
5353
* A fallback writer used for requests that don't return raw content and that aren't associated
@@ -62,14 +62,17 @@ public void init(NamedList<?> n) {
6262
if (n != null) {
6363
Object base = n.get("base");
6464
if (base != null) {
65-
_baseWriter = base.toString();
65+
baseWriter = base.toString();
6666
}
6767
}
6868
}
6969

7070
protected QueryResponseWriter getBaseWriter(SolrQueryRequest request) {
7171
if (request.getCore() != null) {
72-
return request.getCore().getQueryResponseWriter(_baseWriter);
72+
// When baseWriter is null, use the core's default writer (useDefault=true)
73+
// Otherwise, look up the specific writer by name (useDefault=false for explicit lookups)
74+
boolean useDefault = (baseWriter == null);
75+
return request.getCore().getResponseWriters().get(baseWriter, useDefault);
7376
}
7477

7578
// Requests to a specific core already have writers, but we still need a 'default writer' for

solr/core/src/test/org/apache/solr/response/TestRawResponseWriter.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class TestRawResponseWriter extends SolrTestCaseJ4 {
4444
private static RawResponseWriter writerJsonBase;
4545
private static RawResponseWriter writerBinBase;
4646
private static RawResponseWriter writerCborBase;
47-
// private static RawResponseWriter writerNoBase;
47+
private static RawResponseWriter writerNoBase;
4848

4949
private static RawResponseWriter[] allWriters;
5050

@@ -56,22 +56,26 @@ public static void setupCoreAndWriters() throws Exception {
5656
// we spin up.
5757
initCore("solrconfig.xml", "schema.xml");
5858

59-
// writerNoBase = newRawResponseWriter(null); /* defaults to standard writer as base */
59+
writerNoBase =
60+
newRawResponseWriter(
61+
null); /* null base uses core's default writer (XML for this core), or JSON if no core */
6062
writerXmlBase = newRawResponseWriter("xml");
6163
writerJsonBase = newRawResponseWriter("json");
6264
writerBinBase = newRawResponseWriter("javabin");
6365
writerCborBase = newRawResponseWriter("cbor");
6466

6567
allWriters =
66-
new RawResponseWriter[] {writerXmlBase, writerJsonBase, writerBinBase, writerCborBase};
68+
new RawResponseWriter[] {
69+
writerXmlBase, writerJsonBase, writerBinBase, writerCborBase, writerNoBase
70+
};
6771
}
6872

6973
@AfterClass
7074
public static void cleanupWriters() {
7175
writerXmlBase = null;
7276
writerJsonBase = null;
7377
writerBinBase = null;
74-
// writerNoBase = null;
78+
writerNoBase = null;
7579
writerCborBase = null;
7680
allWriters = null;
7781
}
@@ -131,7 +135,7 @@ public void testStructuredDataViaBaseWriters() throws IOException {
131135
rsp.add("foo", "bar");
132136

133137
// check Content-Type against each writer
134-
// assertEquals("application/xml; charset=UTF-8", writerNoBase.getContentType(req(), rsp));
138+
assertEquals("application/xml; charset=UTF-8", writerNoBase.getContentType(req(), rsp));
135139
assertEquals("application/xml; charset=UTF-8", writerXmlBase.getContentType(req(), rsp));
136140
assertEquals("application/json; charset=UTF-8", writerJsonBase.getContentType(req(), rsp));
137141
assertEquals("application/octet-stream", writerBinBase.getContentType(req(), rsp));
@@ -153,11 +157,10 @@ public void testStructuredDataViaBaseWriters() throws IOException {
153157
writerXmlBase.write(xmlBout, req(), rsp);
154158
assertEquals(xml, xmlBout.toString(StandardCharsets.UTF_8));
155159

156-
//
157-
// assertEquals(xml, writerNoBase.writeToString(req(), rsp));
158-
// ByteArrayOutputStream noneBout = new ByteArrayOutputStream();
159-
// writerNoBase.write(noneBout, req(), rsp);
160-
// assertEquals(xml, noneBout.toString(StandardCharsets.UTF_8.toString()));
160+
assertEquals(xml, writerNoBase.writeToString(req(), rsp));
161+
ByteArrayOutputStream noneBout = new ByteArrayOutputStream();
162+
writerNoBase.write(noneBout, req(), rsp);
163+
assertEquals(xml, noneBout.toString(StandardCharsets.UTF_8));
161164

162165
// json
163166
String json = "{\n" + " \"content\":\"test\",\n" + " \"foo\":\"bar\"}\n";
@@ -204,7 +207,7 @@ private byte[] convertJsonToCborFormat(byte[] inputJson) throws IOException {
204207
}
205208

206209
/**
207-
* Generates a new {@link RawResponseWriter} wrapping the specified baseWriter name (which much
210+
* Generates a new {@link RawResponseWriter} wrapping the specified baseWriter name (which must
208211
* either be an implicitly defined response writer, or one explicitly configured in
209212
* solrconfig.xml)
210213
*

0 commit comments

Comments
 (0)