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 Sean Laval <se...@hotmail.com> on 2008/01/29 15:58:10 UTC

custom response writers

I wonder if anyone can help me. I am trying to create a custom response writer that better meets my needs. I am trying to return json data in a format required by dojo data components. As its json, ie text, I tried subclassing the TextResponseWriter and implementing the QueryResponseWriter interface, compiled a jar with this class, dropped it in the solr/lib directory and referenced the response writer in solr-config. When the jetty server starts it has an error to do with this new response writer...
 Caused by: java.lang.InstantiationException: com.ibm.swg.kmt.content.solr.plugin.DojoResponseWriter2
	at java.lang.Class.newInstance0(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.solr.core.Config.newInstance(Config.java:227)
	... 28 more
 
Does anyone have any ideas? I seem to be able to create a responsewriter from scratch with no problems but I want to use the base functionality in TextResponseWriter.
 
Any help greatly appreciated.
 
ps. solr 1.2 on jetty.
 
Sean
 
 
_________________________________________________________________
Share what Santa brought you
https://www.mycooluncool.com

RE: custom response writers

Posted by Sean Laval <se...@hotmail.com>.
Thanks Hoss for that very full response. I did have cursory look at JSONResponseWriter but I must've missed the inner class. Thanks again.
 
Sean> Date: Tue, 29 Jan 2008 14:42:02 -0800> From: hossman_lucene@fucit.org> To: solr-user@lucene.apache.org> Subject: RE: custom response writers> > > : Thats what I thought, but I can't add a noarg constructor to my subclass > : as one doesn't exist in the superclass - TextResponseWriter. All I have > : done is create a class that extends TextResponseWriter and implements > : QueryResponseWriter. The only method that is actually implemented is ..> : > : public String getContentType(SolrQueryRequest arg0, SolrQueryResponse arg1) {> : // TODO Auto-generated method stub> : return CONTENT_TYPE_TEXT_UTF8;> : }> : ie the class at the moment, does nothing, but it shouldn't cause an error.> > yeah ... actually it should ... there's a couple of things wrong with this > picture... for starters, you must have some other code in your > DojoResponseWriter2 or it wouldn't compile (you need to define the methods > init(NamedList) and write(Writer,SolrQueryRequest,SolrQueryResponse) in > order to satisfy the QueryResponseWriter Interface.> > Second: there is some confusion about hte namming of utility classes > related to response writting in Solr. The QueryResponseWriter is what you > have to implement. the TextResponseWriter abstract class is intended to > help you do that ... but you should not attempt to have a single > class subclass TextResponseWriter and implement QueryResponseWriter.> > The intent is that each concrete QueryResponseWriter impl will have a > helper class that it constructs instances of in each call to the > QueryResponseWriter.write method. this helper class can maintain state > and be recursive since there will be one instance per response (meanwhile > the instanes of QueryResponseWriter need to be thread safe.> > Think of QueryResponseWriter as an interface that your factory must > implement, and TextResponseWriter as a base class you can use for the > objects your factory will produce -- except that you never have to return > the objects you produce, you just have to execute them.> > take a loost at the existing JSONResponseWriter as an example ... in > implements QueryResponseWriter but it does not extend TextResponseWriter > -- instead it has an inner class named JSONWriter which extends > TextResponseWriter.> > > -Hoss
_________________________________________________________________
Telly addicts unite!
http://www.searchgamesbox.com/tvtown.shtml

RE: custom response writers

Posted by Chris Hostetter <ho...@fucit.org>.
: Thats what I thought, but I can't add a noarg constructor to my subclass 
: as one doesn't exist in the superclass - TextResponseWriter. All I have 
: done is create a class that extends TextResponseWriter and implements 
: QueryResponseWriter. The only method that is actually implemented is ..
:  
: public String getContentType(SolrQueryRequest arg0, SolrQueryResponse arg1) {
: // TODO Auto-generated method stub
: return CONTENT_TYPE_TEXT_UTF8;
: }
:  ie the class at the moment, does nothing, but it shouldn't cause an error.

yeah ... actually it should ... there's a couple of things wrong with this 
picture...  for starters, you must have some other code in your 
DojoResponseWriter2 or it wouldn't compile (you need to define the methods 
init(NamedList) and write(Writer,SolrQueryRequest,SolrQueryResponse) in 
order to satisfy the QueryResponseWriter Interface.

Second: there is some confusion about hte namming of utility classes 
related to response writting in Solr.  The QueryResponseWriter is what you 
have to implement.  the TextResponseWriter abstract class is intended to 
help you do that ... but you should not attempt to have a single 
class subclass TextResponseWriter and implement QueryResponseWriter.

The intent is that each concrete QueryResponseWriter impl will have a 
helper class that it constructs instances of in each call to the 
QueryResponseWriter.write method.  this helper class can maintain state 
and be recursive since there will be one instance per response (meanwhile 
the instanes of QueryResponseWriter need to be thread safe.

Think of QueryResponseWriter as an interface that your factory must 
implement, and TextResponseWriter as a base class you can use for the 
objects your factory will produce -- except that you never have to return 
the objects you produce, you just have to execute them.

take a loost at the existing JSONResponseWriter as an example ... in 
implements QueryResponseWriter but it does not extend TextResponseWriter 
-- instead it has an inner class named JSONWriter which extends 
TextResponseWriter.


-Hoss

RE: custom response writers

Posted by Sean Laval <se...@hotmail.com>.
Thats what I thought, but I can't add a noarg constructor to my subclass as one doesn't exist in the superclass - TextResponseWriter. All I have done is create a class that extends TextResponseWriter and implements QueryResponseWriter. The only method that is actually implemented is ..
 
public String getContentType(SolrQueryRequest arg0, SolrQueryResponse arg1) {
// TODO Auto-generated method stub
return CONTENT_TYPE_TEXT_UTF8;
}
 ie the class at the moment, does nothing, but it shouldn't cause an error.
 
I did realise that I was unknowingly compiling my class using a 1.4 jdk using maven, but have since recitfied that and the error is still there.
 
Regards,
 
Sean> From: gsingers@apache.org> To: solr-user@lucene.apache.org> Subject: Re: custom response writers> Date: Tue, 29 Jan 2008 10:15:26 -0500> > Can you give more info on the ResponseWriter you are creating? It > looks like it is finding the class (i.e. it is not throwing a > ClassNotFoundException) but is having trouble constructing it. I > believe you need a no argument constructor.> > -Grant> > On Jan 29, 2008, at 9:58 AM, Sean Laval wrote:> > >> > I wonder if anyone can help me. I am trying to create a custom > > response writer that better meets my needs. I am trying to return > > json data in a format required by dojo data components. As its json, > > ie text, I tried subclassing the TextResponseWriter and implementing > > the QueryResponseWriter interface, compiled a jar with this class, > > dropped it in the solr/lib directory and referenced the response > > writer in solr-config. When the jetty server starts it has an error > > to do with this new response writer...> > Caused by: java.lang.InstantiationException: > > com.ibm.swg.kmt.content.solr.plugin.DojoResponseWriter2> > at java.lang.Class.newInstance0(Unknown Source)> > at java.lang.Class.newInstance(Unknown Source)> > at org.apache.solr.core.Config.newInstance(Config.java:227)> > ... 28 more> >> > Does anyone have any ideas? I seem to be able to create a > > responsewriter from scratch with no problems but I want to use the > > base functionality in TextResponseWriter.> >> > Any help greatly appreciated.> >> > ps. solr 1.2 on jetty.> >> > Sean> >> >> > _________________________________________________________________> > Share what Santa brought you> > https://www.mycooluncool.com> > 
_________________________________________________________________
Get Hotmail on your mobile, text MSN to 63463!
http://mobile.uk.msn.com/pc/mail.aspx

Re: custom response writers

Posted by Grant Ingersoll <gs...@apache.org>.
Can you give more info on the ResponseWriter you are creating?  It  
looks like it is finding the class (i.e. it is not throwing a  
ClassNotFoundException) but is having trouble constructing it.  I  
believe you need a no argument constructor.

-Grant

On Jan 29, 2008, at 9:58 AM, Sean Laval wrote:

>
> I wonder if anyone can help me. I am trying to create a custom  
> response writer that better meets my needs. I am trying to return  
> json data in a format required by dojo data components. As its json,  
> ie text, I tried subclassing the TextResponseWriter and implementing  
> the QueryResponseWriter interface, compiled a jar with this class,  
> dropped it in the solr/lib directory and referenced the response  
> writer in solr-config. When the jetty server starts it has an error  
> to do with this new response writer...
> Caused by: java.lang.InstantiationException:  
> com.ibm.swg.kmt.content.solr.plugin.DojoResponseWriter2
> 	at java.lang.Class.newInstance0(Unknown Source)
> 	at java.lang.Class.newInstance(Unknown Source)
> 	at org.apache.solr.core.Config.newInstance(Config.java:227)
> 	... 28 more
>
> Does anyone have any ideas? I seem to be able to create a  
> responsewriter from scratch with no problems but I want to use the  
> base functionality in TextResponseWriter.
>
> Any help greatly appreciated.
>
> ps. solr 1.2 on jetty.
>
> Sean
>
>
> _________________________________________________________________
> Share what Santa brought you
> https://www.mycooluncool.com