You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Tejas Bavishi <te...@bsil.com> on 2011/07/31 14:49:06 UTC

Query regarding Solr ClassCastException on client side for Java

Hi

I am using apache solr 3.3 on windows 7 with JDK 1.6.

I am facing very strange problem. My code makes a query to the solr server in Java, the code is pasted below:

      public QueryResponse getSearchResponse(String query, String url, String...facets){

      try{

            SolrQuery query1 = new SolrQuery();
        query1.setQuery(query);

        if(facets != null){
              if(facets.length > 0){
                  query1.setFacet(true);
                  query1.setRows(0);
                  for(int i=0; i< facets.length; i++){
                        query1.addFacetField(facets[i]);
                  }
              }
        }

        log.info("The URL is " + url);

        query1.setFacetMinCount(1);

        query1.setRows(45);

        query1.setIncludeScore(false);

        log.info("The query is " + query1.getQuery());

            SolrServer solrServer = new CommonsHttpSolrServer(url);

            QueryResponse queryResponse = solrServer.query(query1);

            if(queryResponse == null){
                  queryResponse = new QueryResponse();
                  log.info("The query response is null");
            }

            solrServer.commit();


            return queryResponse;

      }catch(Exception ex){
            log.error("Error fetching data from Solr -!! " + ex.toString());
            ex.printStackTrace();
            return new QueryResponse();
      }
      }


At the line, QueryResponse queryResponse = solrServer.query(query1); Class Cast Exception is thrown and no data is fetched. I suspect this has something to do with Solrj client distribution.

I have pasted the exception as well, where Solr war is reporting that there were 25 records hit, but the client log from my code reports class cast exception. The exception is pasted below:

INFO: [] webapp=/solr path=/select params={facet=true&facet.mincount=1&q=*:*&fac
et.field=grp_id&wt=javabin&rows=45&version=2.2} hits=25 status=0 QTime=2
1822816 [http-8085-5] ERROR com.nb.philips.util.SolrjUtil  - Error fetching data
 from Solr -!! org.apache.solr.client.solrj.SolrServerException: Error executing
 query
org.apache.solr.client.solrj.SolrServerException: Error executing query
        at org.apache.solr.client.solrj.request.QueryRequest.process(QueryReques
t.java:96)
        at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:109)
        at com.nb.philips.util.SolrjUtil.getSearchResponse(SolrjUtil.java:70)
        at com.nb.philips.HomePageBO.getHomePageVO(HomePageBO.java:57)
        at com.nb.philips.HomePageBO.getGroupsSortedByRank(HomePageBO.java:41)
        at org.apache.jsp.includes.dashboard_jsp._jspService(dashboard_jsp.java:
98)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:386)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
13)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
atcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationD
ispatcher.java:551)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDis
patcher.java:488)
        at org.apache.jasper.runtime.JspRuntimeLibrary.include(JspRuntimeLibrary
.java:968)
        at org.apache.jsp.pages.productDetails_jsp._jspService(productDetails_js
p.java:1917)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper
.java:386)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:3
13)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDisp
atcher.java:646)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(Applica
tionDispatcher.java:436)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationD
ispatcher.java:374)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDis
patcher.java:302)
        at org.apache.struts.chain.commands.servlet.PerformForward.handleAsForwa
rd(PerformForward.java:113)
        at org.apache.struts.chain.commands.servlet.PerformForward.perform(Perfo
rmForward.java:96)
        at org.apache.struts.chain.commands.AbstractPerformForward.execute(Abstr
actPerformForward.java:54)
        at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionComm
andBase.java:51)
        at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
        at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.
java:304)
        at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
        at org.apache.struts.chain.ComposableRequestProcessor.process(Composable
RequestProcessor.java:283)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:191
3)
        at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at com.nb.philips.PhilipsFilter.doFilter(PhilipsFilter.java:72)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.tuckey.web.filters.urlrewrite.RuleChain.handleRewrite(RuleChain.j
ava:176)
        at org.tuckey.web.filters.urlrewrite.RuleChain.doRules(RuleChain.java:14
5)
        at org.tuckey.web.filters.urlrewrite.UrlRewriter.processRequest(UrlRewri
ter.java:92)
        at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewrit
eFilter.java:381)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(Authentica
torBase.java:470)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.jav
a:298)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcesso
r.java:864)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.pr
ocess(Http11AprProtocol.java:579)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:16
65)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to jav
a.lang.String
        at org.apache.solr.common.util.NamedListCodec.readOrderedMap(NamedListCo
dec.java:97)
        at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
a:154)
        at org.apache.solr.common.util.NamedListCodec.readSolrDocument(NamedList
Codec.java:284)
        at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
a:171)
        at org.apache.solr.common.util.NamedListCodec.readArray(NamedListCodec.j
ava:367)
        at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
a:153)
        at org.apache.solr.common.util.NamedListCodec.readSolrDocumentList(Named
ListCodec.java:301)
        at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
a:172)
        at org.apache.solr.common.util.NamedListCodec.readOrderedMap(NamedListCo
dec.java:98)
        at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
a:154)
        at org.apache.solr.common.util.NamedListCodec.unmarshal(NamedListCodec.j
ava:89)
        at org.apache.solr.client.solrj.impl.BinaryResponseParser.processRespons
e(BinaryResponseParser.java:39)
        at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(Commo
nsHttpSolrServer.java:385)
        at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(Commo
nsHttpSolrServer.java:183)
        at org.apache.solr.client.solrj.request.QueryRequest.process(QueryReques
t.java:90)
        ... 64 more
1822822 [http-8085-5] INFO  com.nb.philips.HomePageBO  - Got the response from S
Olr



Can someone point me to a solution, is this a problem with Solr or am I doing something wrong ?

Thanks for your help!!

Best Regards,
Tejas Bavishi

RE: Query regarding Solr ClassCastException on client side for Java

Posted by Tejas Bavishi <te...@bsil.com>.
Hi

This happened because the there are 2 jars - apache-solr-solrj-3.3.0.jar and apache-solr-solrj-1.3.0.jar in the Apache Solr distribution. After I removed the apache-solr-solrj-1.3.0.jar file, the code is working fine.

Thank you for your pointers!!

Best Regards,
Tejas Bavishi

-----Original Message-----
From: Chris Hostetter [mailto:hossman_lucene@fucit.org] 
Sent: Monday, August 01, 2011 3:21 AM
To: solr-user@lucene.apache.org
Subject: Re: Query regarding Solr ClassCastException on client side for Java


: I am using apache solr 3.3 on windows 7 with JDK 1.6.

First question: what version of SolrJ are you using?  is it also 3.3?

: At the line, QueryResponse queryResponse = solrServer.query(query1); 
: Class Cast Exception is thrown and no data is fetched. I suspect this 
: has something to do with Solrj client distribution.
	...
: INFO: [] webapp=/solr path=/select params={facet=true&facet.mincount=1&q=*:*&fac
: et.field=grp_id&wt=javabin&rows=45&version=2.2} hits=25 status=0 QTime=2

Assuming that URL still causes the same problem, can you try loading it in 
a browser (using "wt=xml" instead of wt=javabin) and posting the results 
to the list?  It would help if you could also add "echoParams=all" to the 
URL and/or show us your requestHandler configuration.

I haven't dug into the code, but based on your stack trace i suspect maybe 
there is a bug somewhere in the NamedListCodec that assumes Map keys will 
always be Strings -- would like to see the data being returned to try and 
unerstand why tests are failing or no one else has reported seeing the 
same problem you are since that request seems fairly simple and straight 
forward (unless ou have some interesting defaults in your config)


: Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to jav
: a.lang.String
:         at org.apache.solr.common.util.NamedListCodec.readOrderedMap(NamedListCo
: dec.java:97)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:154)
:         at org.apache.solr.common.util.NamedListCodec.readSolrDocument(NamedList
: Codec.java:284)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:171)
:         at org.apache.solr.common.util.NamedListCodec.readArray(NamedListCodec.j
: ava:367)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:153)
:         at org.apache.solr.common.util.NamedListCodec.readSolrDocumentList(Named
: ListCodec.java:301)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:172)
:         at org.apache.solr.common.util.NamedListCodec.readOrderedMap(NamedListCo
: dec.java:98)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:154)
:         at org.apache.solr.common.util.NamedListCodec.unmarshal(NamedListCodec.j
: ava:89)
:         at org.apache.solr.client.solrj.impl.BinaryResponseParser.processRespons
: e(BinaryResponseParser.java:39)


-Hoss

Re: Query regarding Solr ClassCastException on client side for Java

Posted by Chris Hostetter <ho...@fucit.org>.
: I am using apache solr 3.3 on windows 7 with JDK 1.6.

First question: what version of SolrJ are you using?  is it also 3.3?

: At the line, QueryResponse queryResponse = solrServer.query(query1); 
: Class Cast Exception is thrown and no data is fetched. I suspect this 
: has something to do with Solrj client distribution.
	...
: INFO: [] webapp=/solr path=/select params={facet=true&facet.mincount=1&q=*:*&fac
: et.field=grp_id&wt=javabin&rows=45&version=2.2} hits=25 status=0 QTime=2

Assuming that URL still causes the same problem, can you try loading it in 
a browser (using "wt=xml" instead of wt=javabin) and posting the results 
to the list?  It would help if you could also add "echoParams=all" to the 
URL and/or show us your requestHandler configuration.

I haven't dug into the code, but based on your stack trace i suspect maybe 
there is a bug somewhere in the NamedListCodec that assumes Map keys will 
always be Strings -- would like to see the data being returned to try and 
unerstand why tests are failing or no one else has reported seeing the 
same problem you are since that request seems fairly simple and straight 
forward (unless ou have some interesting defaults in your config)


: Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to jav
: a.lang.String
:         at org.apache.solr.common.util.NamedListCodec.readOrderedMap(NamedListCo
: dec.java:97)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:154)
:         at org.apache.solr.common.util.NamedListCodec.readSolrDocument(NamedList
: Codec.java:284)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:171)
:         at org.apache.solr.common.util.NamedListCodec.readArray(NamedListCodec.j
: ava:367)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:153)
:         at org.apache.solr.common.util.NamedListCodec.readSolrDocumentList(Named
: ListCodec.java:301)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:172)
:         at org.apache.solr.common.util.NamedListCodec.readOrderedMap(NamedListCo
: dec.java:98)
:         at org.apache.solr.common.util.NamedListCodec.readVal(NamedListCodec.jav
: a:154)
:         at org.apache.solr.common.util.NamedListCodec.unmarshal(NamedListCodec.j
: ava:89)
:         at org.apache.solr.client.solrj.impl.BinaryResponseParser.processRespons
: e(BinaryResponseParser.java:39)


-Hoss