SOLR-7547: Short circuit SolrDispatchFilter for static content request. Right now it creates a new HttpSolrCall object and tries to process it.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1679493 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Anshum Gupta 2015-05-15 05:50:54 +00:00
parent fba2134157
commit d0251d9b10
4 changed files with 39 additions and 31 deletions

View File

@ -270,6 +270,9 @@ Optimizations
* SOLR-7324: IndexFetcher does not need to call isIndexStale if full copy is already needed
(Stephan Lagraulet via Varun Thacker)
* SOLR-7547: Short circuit SolrDisptachFilter for static content request. Right now it creates
a new HttpSolrCall object and tries to process it. (Anshum Gupta)
Other Changes
----------------------

View File

@ -400,13 +400,7 @@ public class HttpSolrCall {
1. Authorization is enabled, and
2. The requested resource is not a known static file
*/
// TODO: There should be a better way to ignore the static files.
if (cores.getAuthorizationPlugin() != null &&
!(req.getRequestURI().endsWith(".html")
|| req.getRequestURI().endsWith(".png")
|| req.getRequestURI().endsWith(".ico")
|| req.getRequestURI().endsWith(".css")
)) {
if (cores.getAuthorizationPlugin() != null) {
AuthorizationContext context = getAuthCtx();
log.info(context.toString());
AuthorizationResponse authResponse = cores.getAuthorizationPlugin().authorize(context);

View File

@ -17,10 +17,6 @@
package org.apache.solr.servlet;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
@ -28,6 +24,12 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
@ -57,6 +59,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {
protected String abortErrorMessage = null;
protected final CloseableHttpClient httpClient = HttpClientUtil.createClient(new ModifiableSolrParams());
private ArrayList<Pattern> excludePatterns;
/**
* Enum to define action that needs to be processed.
@ -81,7 +84,14 @@ public class SolrDispatchFilter extends BaseSolrFilter {
public void init(FilterConfig config) throws ServletException
{
log.info("SolrDispatchFilter.init()" + this.getClass().getClassLoader());
String exclude = config.getInitParameter("excludePatterns");
if(exclude != null) {
String[] excludeArray = exclude.split(",");
excludePatterns = new ArrayList();
for (String element : excludeArray) {
excludePatterns.add(Pattern.compile(element));
}
}
try {
Properties extraProperties = (Properties) config.getServletContext().getAttribute(PROPERTIES_ATTRIBUTE);
if (extraProperties == null)
@ -170,6 +180,19 @@ public class SolrDispatchFilter extends BaseSolrFilter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain, boolean retry) throws IOException, ServletException {
if (!(request instanceof HttpServletRequest)) return;
// No need to even create the HttpSolrCall object if this path is excluded.
if(excludePatterns != null) {
String servletPath = ((HttpServletRequest) request).getServletPath().toString();
for (Pattern p : excludePatterns) {
Matcher matcher = p.matcher(servletPath);
if (matcher.lookingAt()) {
chain.doFilter(request, response);
return;
}
}
}
HttpSolrCall call = new HttpSolrCall(this, cores, (HttpServletRequest) request, (HttpServletResponse) response, retry);
try {
Action result = call.call();

View File

@ -49,27 +49,15 @@
<filter>
<filter-name>SolrRequestFilter</filter-name>
<filter-class>org.apache.solr.servlet.SolrDispatchFilter</filter-class>
<!-- If you are wiring Solr into a larger web application which controls
the web context root, you will probably want to mount Solr under
a path prefix (app.war with /app/solr mounted into it, for example).
You will need to put this prefix in front of the SolrDispatchFilter
url-pattern mapping too (/solr/*), and also on any paths for
legacy Solr servlet mappings you may be using.
For the Admin UI to work properly in a path-prefixed configuration,
the admin folder containing the resources needs to be under the app context root
named to match the path-prefix. For example:
.war
xxx
js
main.js
-->
<!--
<init-param>
<param-name>path-prefix</param-name>
<param-value>/xxx</param-value>
</init-param>
Exclude patterns is a list of directories that would be short circuited by the
SolrDispatchFilter. It includes all Admin UI related static content.
NOTE: It is NOT a pattern but only matches the start of the HTTP ServletPath.
-->
<init-param>
<param-name>excludePatterns</param-name>
<param-value>/css/*,/js/*,/img/*,/tpl/*</param-value>
</init-param>
</filter>
<filter-mapping>