|
21 | 21 | import java.io.ByteArrayInputStream; |
22 | 22 | import java.io.ByteArrayOutputStream; |
23 | 23 | import java.io.IOException; |
24 | | -import java.io.InputStream; |
25 | 24 | import java.io.OutputStream; |
26 | 25 | import java.io.Writer; |
27 | 26 | import java.lang.invoke.MethodHandles; |
@@ -162,38 +161,28 @@ public void writeResults(ResultContext ctx, JavaBinCodec codec) throws IOExcepti |
162 | 161 | } |
163 | 162 |
|
164 | 163 | /** |
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. |
166 | 167 | * |
167 | | - * @return a response object equivalent to what you get from the XML/JSON/javabin parser. |
168 | | - * Documents become SolrDocuments, DocList becomes SolrDocumentList etc. |
169 | 168 | * @since solr 1.4 |
170 | 169 | */ |
171 | | - @SuppressWarnings("unchecked") |
172 | 170 | 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 |
173 | 173 | 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 = |
180 | 175 | new ByteArrayOutputStream() { |
181 | 176 | ByteArrayInputStream toInputStream() { |
182 | 177 | return new ByteArrayInputStream(buf, 0, count); |
183 | 178 | } |
184 | | - }) { |
185 | | - try (JavaBinCodec jbc = new JavaBinCodec(resolver)) { |
186 | | - jbc.setWritableDocFields(resolver).marshal(rsp.getValues(), out); |
187 | | - } |
| 179 | + }; |
188 | 180 |
|
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 |
197 | 186 | } |
198 | 187 | } |
199 | 188 |
|
|
0 commit comments