You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by is...@apache.org on 2020/01/13 14:13:33 UTC

[lucene-solr] 01/02: Provided the patch for solr-13971 for 7.7

This is an automated email from the ASF dual-hosted git repository.

ishan pushed a commit to branch branch_7_7
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git

commit 2937630e49e07883be8e46127de1dbdff6196824
Author: Sachin Pattan <sa...@sap.com>
AuthorDate: Wed Jan 8 11:46:29 2020 +0100

    Provided the patch for solr-13971 for 7.7
---
 solr/CHANGES.txt                                       |  3 +++
 .../apache/solr/response/VelocityResponseWriter.java   | 12 +++++++-----
 .../solr/velocity/VelocityResponseWriterTest.java      | 11 ++++++++++-
 .../solr/configsets/_default/conf/solrconfig.xml       | 13 +------------
 .../solr/configsets/_default/conf/solrconfig.xml       | 13 +------------
 solr/solr-ref-guide/src/velocity-response-writer.adoc  | 18 +++++++++---------
 6 files changed, 31 insertions(+), 39 deletions(-)

diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index c769355..983e4a7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -45,6 +45,9 @@ Bug fixes
   the number of replicas. This avoids making too many cascading calls to remote servers, which, if not restricted, can
   bring down nodes containing the said collection (Kesharee Nandan Vishwakarma, Ishan Chattopadhyaya)
 
+* SOLR-13971: Velocity response writer's resource loading now possible only through startup parameters. Also, removed velocity 
+  response writer from _default configset. (Ishan Chattopadhyaya, Sachin Pattan)
+
 ==================  7.7.2 ==================
 
 Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release.
diff --git a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
index ad1ee39..6325355 100644
--- a/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
+++ b/solr/contrib/velocity/src/java/org/apache/solr/response/VelocityResponseWriter.java
@@ -65,9 +65,11 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
   // init param names, these are _only_ loaded at init time (no per-request control of these)
   //   - multiple different named writers could be created with different init params
   public static final String TEMPLATE_BASE_DIR = "template.base.dir";
+  public static final String PROPERTIES_FILE = "init.properties.file";
+
+  // System property names, these are _only_ loaded at node startup (no per-request control of these)
   public static final String PARAMS_RESOURCE_LOADER_ENABLED = "params.resource.loader.enabled";
   public static final String SOLR_RESOURCE_LOADER_ENABLED = "solr.resource.loader.enabled";
-  public static final String PROPERTIES_FILE = "init.properties.file";
 
   // request param names
   public static final String TEMPLATE = "v.template";
@@ -110,12 +112,12 @@ public class VelocityResponseWriter implements QueryResponseWriter, SolrCoreAwar
     }
 
     // params resource loader: off by default
-    Boolean prle = args.getBooleanArg(PARAMS_RESOURCE_LOADER_ENABLED);
+    Boolean prle = Boolean.getBoolean(PARAMS_RESOURCE_LOADER_ENABLED);
     paramsResourceLoaderEnabled = (null == prle ? false : prle);
 
-    // solr resource loader: on by default
-    Boolean srle = args.getBooleanArg(SOLR_RESOURCE_LOADER_ENABLED);
-    solrResourceLoaderEnabled = (null == srle ? true : srle);
+    // solr resource loader: off by default
+    Boolean srle = Boolean.getBoolean(SOLR_RESOURCE_LOADER_ENABLED);
+    solrResourceLoaderEnabled = (null == srle ? false : srle);
 
     initPropertiesFileName = (String) args.get(PROPERTIES_FILE);
 
diff --git a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java
index 9b70e1b..b5fa387 100644
--- a/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java
+++ b/solr/contrib/velocity/src/test/org/apache/solr/velocity/VelocityResponseWriterTest.java
@@ -24,6 +24,7 @@ import org.apache.solr.response.SolrParamResourceLoader;
 import org.apache.solr.response.SolrQueryResponse;
 import org.apache.solr.response.VelocityResponseWriter;
 import org.apache.solr.request.SolrQueryRequest;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
@@ -33,10 +34,18 @@ import java.io.StringWriter;
 public class VelocityResponseWriterTest extends SolrTestCaseJ4 {
   @BeforeClass
   public static void beforeClass() throws Exception {
+    System.setProperty("params.resource.loader.enabled", "true");
+    System.setProperty("solr.resource.loader.enabled", "true");
     initCore("solrconfig.xml", "schema.xml", getFile("velocity/solr").getAbsolutePath());
     System.out.println(getFile("velocity/solr").getAbsolutePath());
   }
-
+  
+  @AfterClass
+  public static void afterClass() throws Exception {
+    System.clearProperty("params.resource.loader.enabled");
+    System.clearProperty("solr.resource.loader.enabled");
+  }
+  
   @Test
   public void testVelocityResponseWriterRegistered() {
     QueryResponseWriter writer = h.getCore().getQueryResponseWriter("velocity");
diff --git a/solr/core/src/test-files/solr/configsets/_default/conf/solrconfig.xml b/solr/core/src/test-files/solr/configsets/_default/conf/solrconfig.xml
index 7941aeb..9e994a6 100644
--- a/solr/core/src/test-files/solr/configsets/_default/conf/solrconfig.xml
+++ b/solr/core/src/test-files/solr/configsets/_default/conf/solrconfig.xml
@@ -81,8 +81,6 @@
   <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" />
   <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" />
 
-  <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" />
-  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" />
   <!-- an exact 'path' can be used instead of a 'dir' to specify a
        specific jar file.  This will cause a serious error to be logged
        if it can't be loaded.
@@ -773,7 +771,7 @@
        (SearchHandler) can be registered multiple times with different
        names (and different init parameters)
     -->
-  <requestHandler name="/browse" class="solr.SearchHandler" useParams="query,facets,velocity,browse">
+  <requestHandler name="/browse" class="solr.SearchHandler" useParams="query,facets,browse">
     <lst name="defaults">
       <str name="echoParams">explicit</str>
     </lst>
@@ -1294,15 +1292,6 @@
     <str name="content-type">text/plain; charset=UTF-8</str>
   </queryResponseWriter>
 
-  <!--
-     Custom response writers can be declared as needed...
-    -->
-  <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" startup="lazy">
-    <str name="template.base.dir">${velocity.template.base.dir:}</str>
-    <str name="solr.resource.loader.enabled">${velocity.solr.resource.loader.enabled:true}</str>
-    <str name="params.resource.loader.enabled">${velocity.params.resource.loader.enabled:false}</str>
-  </queryResponseWriter>
-
   <!-- XSLT response writer transforms the XML output by any xslt file found
        in Solr's conf/xslt directory.  Changes to xslt files are checked for
        every xsltCacheLifetimeSeconds.
diff --git a/solr/server/solr/configsets/_default/conf/solrconfig.xml b/solr/server/solr/configsets/_default/conf/solrconfig.xml
index 7941aeb..9e994a6 100644
--- a/solr/server/solr/configsets/_default/conf/solrconfig.xml
+++ b/solr/server/solr/configsets/_default/conf/solrconfig.xml
@@ -81,8 +81,6 @@
   <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" />
   <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" />
 
-  <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" />
-  <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" />
   <!-- an exact 'path' can be used instead of a 'dir' to specify a
        specific jar file.  This will cause a serious error to be logged
        if it can't be loaded.
@@ -773,7 +771,7 @@
        (SearchHandler) can be registered multiple times with different
        names (and different init parameters)
     -->
-  <requestHandler name="/browse" class="solr.SearchHandler" useParams="query,facets,velocity,browse">
+  <requestHandler name="/browse" class="solr.SearchHandler" useParams="query,facets,browse">
     <lst name="defaults">
       <str name="echoParams">explicit</str>
     </lst>
@@ -1294,15 +1292,6 @@
     <str name="content-type">text/plain; charset=UTF-8</str>
   </queryResponseWriter>
 
-  <!--
-     Custom response writers can be declared as needed...
-    -->
-  <queryResponseWriter name="velocity" class="solr.VelocityResponseWriter" startup="lazy">
-    <str name="template.base.dir">${velocity.template.base.dir:}</str>
-    <str name="solr.resource.loader.enabled">${velocity.solr.resource.loader.enabled:true}</str>
-    <str name="params.resource.loader.enabled">${velocity.params.resource.loader.enabled:false}</str>
-  </queryResponseWriter>
-
   <!-- XSLT response writer transforms the XML output by any xslt file found
        in Solr's conf/xslt directory.  Changes to xslt files are checked for
        every xsltCacheLifetimeSeconds.
diff --git a/solr/solr-ref-guide/src/velocity-response-writer.adoc b/solr/solr-ref-guide/src/velocity-response-writer.adoc
index 38c3c4e..37ee3b6 100644
--- a/solr/solr-ref-guide/src/velocity-response-writer.adoc
+++ b/solr/solr-ref-guide/src/velocity-response-writer.adoc
@@ -27,8 +27,6 @@ Its JAR and dependencies must be added (via `<lib>` or solr/home lib inclusion),
 
 <!--
   <str name="init.properties.file">velocity-init.properties</str>
-  <bool name="params.resource.loader.enabled">true</bool>
-  <bool name="solr.resource.loader.enabled">false</bool>
   <lst name="tools">
     <str name="mytool">com.example.MyCustomTool</str>
   </lst>
@@ -36,16 +34,11 @@ Its JAR and dependencies must be added (via `<lib>` or solr/home lib inclusion),
 </queryResponseWriter>
 ----
 
-The above example shows the optional initialization and custom tool parameters used by VelocityResponseWriter; these are detailed in the following table. These initialization parameters are only specified in the writer registration in `solrconfig.xml`, not as request-time parameters. See further below for request-time parameters.
+The above example shows the optional initialization and custom tool parameters used by VelocityResponseWriter; these are detailed in the following table. These initialization parameters are only specified in the writer registration in `solrconfig.xml`, not as request-time parameters. In this example, all Solr nodes should be started with `-Dparams.resource.loader.enabled=true`. See further below for request-time parameters.
 
 == Configuration & Usage
 
-=== VelocityResponseWriter Initialization Parameters
-
-`template.base.dir`::
-If specified and exists as a file system directory, a file resource loader will be added for this directory. Templates in this directory will override "solr" resource loader templates.
-
-`init.properties.file`:: Specifies a properties file name which must exist in the Solr `conf/` directory (*not* under a `velocity/` subdirectory) or root of a JAR file in a <lib>.
+=== VelocityResponseWriter Startup Parameters
 
 `params.resource.loader.enabled`::
 The "params" resource loader allows templates to be specified in Solr request parameters. For example:
@@ -58,6 +51,13 @@ where `v.template=custom` says to render a template called "custom" and the valu
 `solr.resource.loader.enabled`::
 The "solr" resource loader is the only template loader registered by default. Templates are served from resources visible to the SolrResourceLoader under a `velocity/` subdirectory. The VelocityResponseWriter itself has some built-in templates (in its JAR file, under `velocity/`) that are available automatically through this loader. These built-in templates can be overridden when the same template name is in conf/velocity/ or by using the `template.base.dir` option.
 
+=== VelocityResponseWriter Initialization Parameters
+
+`template.base.dir`::
+If specified and exists as a file system directory, a file resource loader will be added for this directory. Templates in this directory will override "solr" resource loader templates.
+
+`init.properties.file`:: Specifies a properties file name which must exist in the Solr `conf/` directory (*not* under a `velocity/` subdirectory) or root of a JAR file in a <lib>.
+
 `tools`::
 External "tools" can be specified as list of string name/value (tool name / class name) pairs. Tools, in the Velocity context, are simply Java objects. Tool classes are constructed using a no-arg constructor (or a single-SolrCore-arg constructor if it exists) and added to the Velocity context with the specified name.
 +