You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by an...@apache.org on 2015/05/15 07:56:23 UTC

svn commit: r1679496 - in /lucene/dev/branches/branch_5x: ./ solr/ solr/core/ solr/core/src/java/org/apache/solr/servlet/ solr/webapp/ solr/webapp/web/WEB-INF/

Author: anshum
Date: Fri May 15 05:56:23 2015
New Revision: 1679496

URL: http://svn.apache.org/r1679496
Log:
SOLR-7547: Short circuit SolrDispatchFilter for static content request. Right now it creates a new HttpSolrCall object and tries to process it.(merge from trunk)

Modified:
    lucene/dev/branches/branch_5x/   (props changed)
    lucene/dev/branches/branch_5x/solr/   (props changed)
    lucene/dev/branches/branch_5x/solr/CHANGES.txt   (contents, props changed)
    lucene/dev/branches/branch_5x/solr/core/   (props changed)
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
    lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
    lucene/dev/branches/branch_5x/solr/webapp/   (props changed)
    lucene/dev/branches/branch_5x/solr/webapp/web/WEB-INF/web.xml

Modified: lucene/dev/branches/branch_5x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/CHANGES.txt?rev=1679496&r1=1679495&r2=1679496&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_5x/solr/CHANGES.txt Fri May 15 05:56:23 2015
@@ -213,6 +213,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
 ----------------------
 

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java?rev=1679496&r1=1679495&r2=1679496&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java Fri May 15 05:56:23 2015
@@ -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);

Modified: lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java?rev=1679496&r1=1679495&r2=1679496&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java (original)
+++ lucene/dev/branches/branch_5x/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java Fri May 15 05:56:23 2015
@@ -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
 
   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
   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
   
   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();

Modified: lucene/dev/branches/branch_5x/solr/webapp/web/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_5x/solr/webapp/web/WEB-INF/web.xml?rev=1679496&r1=1679495&r2=1679496&view=diff
==============================================================================
--- lucene/dev/branches/branch_5x/solr/webapp/web/WEB-INF/web.xml (original)
+++ lucene/dev/branches/branch_5x/solr/webapp/web/WEB-INF/web.xml Fri May 15 05:56:23 2015
@@ -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
-    -->
     <!--
+    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>path-prefix</param-name>
-      <param-value>/xxx</param-value>
+      <param-name>excludePatterns</param-name>
+      <param-value>/css/*,/js/*,/img/*,/tpl/*</param-value>
     </init-param>
-    -->
   </filter>
 
   <filter-mapping>