[ 
https://issues.apache.org/jira/browse/SOLR-15070?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17262846#comment-17262846
 ] 

ASF subversion and git services commented on SOLR-15070:
--------------------------------------------------------

Commit d44ca858f5e10035de956094dd624e7ca3ee79f7 in lucene-solr's branch 
refs/heads/branch_8x from Jason Gerlowski
[ https://gitbox.apache.org/repos/asf?p=lucene-solr.git;h=d44ca85 ]

SOLR-15070: Fix suggest SolrJ requests w/ XML

Prior to this commit, /suggest requests made using SolrJ's
XMLResponseParser failed with a ClassCastException.  The problem:
javabin and xml requests were serializing/deserializing Solr's response
object differently.  Use of the default format (javabin) resulted in a
Map being used to wrap the 'suggest' response on the client side, use of
XML results in the response being wrapped in a SimpleOrderedMap.

The root cause of this problem was the use of a type on the server-side
that our XML serde code doesn't correctly "round-trip".  This has been
changed in 9.0, but in a backwards-incompatible way that's inappropriate
for the 8.x codeline.  This commit papers over the problem in 8x by
checking for both types in SolrJ's QueryResponse and massaging the types
as necessary.


> SolrJ ClassCastException on XML /suggest requests
> -------------------------------------------------
>
>                 Key: SOLR-15070
>                 URL: https://issues.apache.org/jira/browse/SOLR-15070
>             Project: Solr
>          Issue Type: Task
>      Security Level: Public(Default Security Level. Issues are Public) 
>          Components: SolrJ, Suggester
>    Affects Versions: 8.6.3, master (9.0)
>            Reporter: Jason Gerlowski
>            Assignee: Jason Gerlowski
>            Priority: Minor
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> SolrJ throws a ClassCastException when parsing XML {{/suggest}} responses.
> The following code snippet (run against the techproduct example) produces the 
> stack trace that follows:
> {code}
>   public void testSuggestFailure() throws Exception {
>     HttpSolrClient client = new HttpSolrClient.Builder()
>         .withBaseSolrUrl("http://localhost:8983/solr/techproducts";)
>         .withResponseParser(new XMLResponseParser())
>         .build();
>     Map<String, String> queryParamMap = new HashMap<>();
>     queryParamMap.put("qt", "/suggest");
>     queryParamMap.put("suggest.q", "elec");
>     queryParamMap.put("suggest.build", "true");
>     queryParamMap.put("suggest", "true");
>     queryParamMap.put("suggest.dictionary", "mySuggester");
>     queryParamMap.put("wt", "xml");
>     QueryResponse resp = client.query(new MapSolrParams(queryParamMap));
>   }
> {code}
> {code}
> java.lang.ClassCastException: class 
> org.apache.solr.common.util.SimpleOrderedMap cannot be cast to class 
> java.util.Map (org.apache.solr.common.util.SimpleOrderedMap is in unnamed 
> module of loader 'app'; java.util.Map is in module java.base of loader 
> 'bootstrap')
>     at 
> org.apache.solr.client.solrj.response.QueryResponse.setResponse(QueryResponse.java:170)
>  ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - 
> ishan - 2020-01-10 13:40:30]
>     at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:211) 
> ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - ishan 
> - 2020-01-10 13:40:30]
>     at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:1003) 
> ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - ishan 
> - 2020-01-10 13:40:30]
>     at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:1018) 
> ~[solr-solrj-8.4.1.jar:8.4.1 832bf13dd9187095831caf69783179d41059d013 - ishan 
> - 2020-01-10 13:40:30]
> {code}
> SolrJ's {{QueryResponse}} expects the "suggest" section in the NamedList 
> response to be a Map - and for requests that use javabin (the default 
> ResponseParser), it is.  But when parsing XML responses the "suggest" section 
> deserialized as a SimpleOrderedMap (which despite the name doesn't implement 
> Map).
> The root cause afaict is that SuggestComponent [uses a 
> type|https://github.com/apache/lucene-solr/blob/43b1a2fdc7a4bf8e5c8409013d07858dec6d0c35/solr/core/src/java/org/apache/solr/handler/component/SuggestComponent.java#L261]
>  (HashMap) that serializes/deserializes differently based on the codec/wt 
> used on the wire.  JavaBinCodec has special handling for maps that our XML 
> serialization doesn't have, so the two produce different response structures 
> on the client side.
> The "right" fix here is to change SuggestComponent's response to only use 
> types that serialize/deserialize identically in all SolrJ's ResponseParser's. 
>  This is a breaking change though - a SolrJ user making /suggest requests, 
> getting the responses via javavbin, and inspecting the resulting NamedList 
> directly would get a different object tree after this fix than they would've 
> before.  So an 8.x fix would need to take a different approach.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to