: Solr is not really designed to be extended in this way.  In fact I believe
: they are moving towards an architecture where this is even less possible -

Correct.

Starting with 5.0, the fact that servlets & a servlet container are used 
by solr becomes a pure implementation detail - subject to change as 
warrented by features so that we can do things like swap out the  
networking stack, listen on multiple ports (for internode communication) 
etc....

In the particular case of this specific error you ran into that prompted 
this thread, the code in question is enforcing how the params come in 
precisely becuase of hte PITA problems solr has had working with arbirary 
servlet containers in the past -- in particular the way diff containers 
use diff defaults for (and requre different config options to overide) 
deciding which charset to use when parsing params...

https://issues.apache.org/jira/browse/SOLR-4265
https://issues.apache.org/jira/browse/SOLR-4283

... in the short term, if you really want ot get your Filter working with 
solr, you can -- but you have to restore the stream in your proxied 
HttpServletRequest object so solr can read it (not just return the values 
from the getParamaeter methods - solr doesn't use those for the reasons 
listed in those bugs) ... or subclass SolrDispatchFilter as Mike 
suggested.


long term: you should think about how to impliment your goals either as a 
network proxy in front of solr, or as a solr plugin.  It's not 100% clear 
what your goal is based on the code you posted (what reads hte "postdata" 
attribute?) based on the code you posted, it appears that all you want to 
do is ignore requests have a start param which is not 0 ... that can be 
done with a solr SearchComponent of about 10 lines of code.




: folks will be encouraged to run solr using a bundled exe, perhaps with jetty
: embedded (I'm not all up to speed on this, maybe someone will correct me), and
: no war file shipped.
: 
: So perhaps a better strategy is to wrap the service at the HTTP layer using a
: proxy.
: 
: Still, you can probably fix your immediate problem by extending Solr's
: SolrDispatchFilter class.  Here's how I did that:
: 
: 
https://github.com/msokolov/lux/blob/master/src/main/java/lux/solr/LuxDispatchFilter.java
: 
: -Mike
: 
: On 12/03/2014 08:02 AM, Stefan Moises wrote:
: > Hi again,
: > 
: > just for reference, here is my filter class (taken from the example posted
: > earlier) - as soon as I iterate over the request parameters, Solr gets
: > angry... :(
: > I have also tried HttpServletRequestWrapper, but that didn't help either...
: > nor did this:
: > 
http://ocpsoft.org/opensource/how-to-safely-add-modify-servlet-request-parameter-values/
: > (because I don't want to only add some static values, I still have to
: > iterate over the original request's parameters to get my desired data out of
: > the request's POST data....)
: > Here goes...
: > 
: > public final class PostDataDumperFilter implements Filter {
: >     private FilterConfig filterConfig = null;
: >     public void init(FilterConfig filterConfig) throws ServletException {
: >         this.filterConfig = filterConfig;
: >     }
: >     public void destroy() {
: >         this.filterConfig = null;
: >     }
: >     public void setFilterConfig(FilterConfig fc) {
: >         filterConfig=fc;
: >     }
: >     public FilterConfig getFilterConfig()         {
: >         return filterConfig;
: >     }
: >     public void doFilter(ServletRequest request, ServletResponse response,
: >             FilterChain chain) throws IOException, ServletException {
: >         if (filterConfig == null)
: >             return;
: >         HttpServletRequest httpRequest = (HttpServletRequest) request;
: > 
: >             // The variable "postdata" is used in the Solr Tomcat Valve
: >             Enumeration<String> names = httpRequest.getParameterNames();
: >             StringBuffer output = new StringBuffer();
: >             boolean skipRequest = false;
: >             while (names.hasMoreElements()) {
: >                 String name = (String) names.nextElement();
: >                 output.append(name + "=");
: >                 String values[] = httpRequest.getParameterValues(name);
: >                 for (int i = 0; i < values.length; i++) {
: >                     if (i > 0) {
: >                         output.append("&" + name + "=");
: >                     }
: >                     output.append(values[i]);
: >                     // ignore paging requests, where request parameter
: > "start" is > 0, e.g. "&start=12":
: >                     if(name.equalsIgnoreCase("start") &&!
: > values[i].equals("0")) {
: >                         skipRequest = true;
: >                     }
: >                 }
: >                 if (names.hasMoreElements())
: >                     output.append("&");
: >             }
: >             if(!skipRequest) {
: >                 request.setAttribute("postdata", output);
: >             }
: > 
: >         chain.doFilter(request, response);
: >     }
: > }
: > 
: > Thanks,
: > Stefan
: > 
: > 
: > Am 03.12.2014 um 09:47 schrieb Stefan Moises:
: > > Hi Folks,
: > > 
: > > I have a problem with an additional servlet filter defined in my web.xml
: > > (Tomcat 7.x).
: > > In Solr 4.2.1. we've successfully used a filter for processing POST
: > > request data (basically, the filter reads the POST data, collects some
: > > parameters from it and writes it back to the request, based on this
: > > example:
: > > http://www.coderanch.com/t/484631/Tomcat/configure-Tomcat-log-POST-data)
: > > To make this work, the filter has to be the first one defined in the
: > > web.xml.
: > > 
: > > But now in Solr 4.8.0, if we define that filter, Solr complains that there
: > > is a filter before it and claims that we have to remove it:
: > > 
: > > null:org.apache.solr.common.SolrException: Solr requires that request
: > > parameters sent using application/x-www-form-urlencoded content-type can
: > > be read through the request input stream. Unfortunately, the stream was
: > > empty / not available. This may be caused by another servlet filter
: > > calling ServletRequest.getParameter*() before SolrDispatchFilter, please
: > > remove it.
: > >     at
: > > 
org.apache.solr.servlet.SolrRequestParsers$FormDataRequestParser.getParameterIncompatibilityException(SolrRequestParsers.java:622)
: > > 
: > > Here is my web.xml:
: > > <!-- My own filter here... -->
: > >  <filter>
: > > <filter-name>post-data-dumper-filter</filter-name>
: > > <filter-class>filters.PostDataDumperFilter</filter-class>
: > >   </filter>
: > >   <filter-mapping>
: > > <filter-name>post-data-dumper-filter</filter-name>
: > >         <url-pattern>/*</url-pattern>
: > >   </filter-mapping>
: > > 
: > >   <!-- Any path (name) registered in solrconfig.xml will be sent to that
: > > filter -->
: > >   <filter>
: > >     <filter-name>SolrRequestFilter</filter-name>
: > > <filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
: > >  </filter>
: > >   <filter-mapping>
: > >     <filter-name>SolrRequestFilter</filter-name>
: > >     <url-pattern>/*</url-pattern>
: > >   </filter-mapping>
: > > 
: > > Any idea how to solve this? Why does Solr have a problem now if there is
: > > any pre-filter defined?
: > > 
: > > Thanks a lot,
: > > Stefan
: > > 
: > 
: 
: 

-Hoss
http://www.lucidworks.com/

Reply via email to