Skip to content

Commit eadd49b

Browse files
authored
Simplify BinaryResponseWriter.getParsedResponse (#3243)
1 parent 746e6bb commit eadd49b

1 file changed

Lines changed: 12 additions & 23 deletions

File tree

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

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.ByteArrayInputStream;
2222
import java.io.ByteArrayOutputStream;
2323
import java.io.IOException;
24-
import java.io.InputStream;
2524
import java.io.OutputStream;
2625
import java.io.Writer;
2726
import java.lang.invoke.MethodHandles;
@@ -162,38 +161,28 @@ public void writeResults(ResultContext ctx, JavaBinCodec codec) throws IOExcepti
162161
}
163162

164163
/**
165-
* TODO -- there may be a way to do this without marshal at all...
164+
* Serializes and deserializes to a {@link NamedList}, thus normalizing a response as if read from
165+
* a client via JavaBin. Documents become {@link org.apache.solr.common.SolrDocument}, DocList
166+
* becomes {@link org.apache.solr.common.SolrDocumentList}, etc.
166167
*
167-
* @return a response object equivalent to what you get from the XML/JSON/javabin parser.
168-
* Documents become SolrDocuments, DocList becomes SolrDocumentList etc.
169168
* @since solr 1.4
170169
*/
171-
@SuppressWarnings("unchecked")
172170
public static NamedList<Object> getParsedResponse(SolrQueryRequest req, SolrQueryResponse rsp) {
171+
// NOTE: EmbeddedSolrServer.writeResponse is similar
172+
// NOTE: this static method could live anywhere; might as well be here I guess
173173
try {
174-
if (req.getParams().getBool(CommonParams.OMIT_HEADER, false)) {
175-
rsp.removeResponseHeader();
176-
}
177-
Resolver resolver = new Resolver(req, rsp.getReturnFields());
178-
179-
try (var out =
174+
var out =
180175
new ByteArrayOutputStream() {
181176
ByteArrayInputStream toInputStream() {
182177
return new ByteArrayInputStream(buf, 0, count);
183178
}
184-
}) {
185-
try (JavaBinCodec jbc = new JavaBinCodec(resolver)) {
186-
jbc.setWritableDocFields(resolver).marshal(rsp.getValues(), out);
187-
}
179+
};
188180

189-
try (InputStream in = out.toInputStream()) {
190-
try (JavaBinCodec jbc = new JavaBinCodec(resolver)) {
191-
return (NamedList<Object>) jbc.unmarshal(in);
192-
}
193-
}
194-
}
195-
} catch (Exception ex) {
196-
throw new RuntimeException(ex);
181+
new BinaryResponseWriter().write(out, req, rsp);
182+
return new BinaryResponseParser().processResponse(out.toInputStream(), null);
183+
184+
} catch (IOException ex) {
185+
throw new RuntimeException(ex); // almost impossible as we don't do real IO
197186
}
198187
}
199188

0 commit comments

Comments
 (0)