Uploaded image for project: 'Solr'
  1. Solr
  2. SOLR-6709

ClassCastException in QueryResponse after applying XMLResponseParser on a response containing an "expanded" section

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.2, 6.0
    • Component/s: SolrJ
    • Labels:
      None

      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.

        Attachments

        1. test-response.xml
          0.3 kB
          Simon Endele
        2. SOLR-6709.patch
          8 kB
          Varun Thacker
        3. SOLR-6709.patch
          11 kB
          Varun Thacker
        4. SOLR-6709.patch
          11 kB
          Varun Thacker

          Activity

            People

            • Assignee:
              varunthacker Varun Thacker
              Reporter:
              simon.endele Simon Endele
            • Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: