Description
Shouldn't the following code work on the attached input file?
It matches the structure of a Solr response with wt=xml.
import java.io.InputStream; import org.apache.solr.client.solrj.ResponseParser; import org.apache.solr.client.solrj.impl.XMLResponseParser; import org.apache.solr.client.solrj.response.QueryResponse; import org.apache.solr.common.util.NamedList; import org.junit.Test; public class ParseXmlExpandedTest { @Test public void test() { ResponseParser responseParser = new XMLResponseParser(); InputStream inStream = getClass() .getResourceAsStream("test-response.xml"); NamedList<Object> response = responseParser .processResponse(inStream, "UTF-8"); QueryResponse queryResponse = new QueryResponse(response, null); } }
Unexpectedly (for me), it throws a
java.lang.ClassCastException: org.apache.solr.common.util.SimpleOrderedMap cannot be cast to java.util.Map
at org.apache.solr.client.solrj.response.QueryResponse.setResponse(QueryResponse.java:126)
Am I missing something, is XMLResponseParser deprecated or something?
We use a setup like this to "mock" a QueryResponse for unit tests in our service that post-processes the Solr response.
Obviously, it works with the javabin format which SolrJ uses internally.
But that is no appropriate format for unit tests, where the response should be human readable.
I think there's some conversion missing in QueryResponse or XMLResponseParser.
Note: The null value supplied as SolrServer argument to the constructor of QueryResponse shouldn't have an effect as the error occurs before the parameter is even used.