lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jd...@apache.org
Subject svn commit: r1303042 - in /lucene/dev/branches/branch_3x/solr: ./ CHANGES.txt contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ScriptTransformer.java
Date Tue, 20 Mar 2012 17:48:18 GMT
Author: jdyer
Date: Tue Mar 20 17:48:18 2012
New Revision: 1303042

URL: http://svn.apache.org/viewvc?rev=1303042&view=rev
Log:
SOLR-3260:  better messages when ScriptTransform fails on init

Modified:
    lucene/dev/branches/branch_3x/solr/   (props changed)
    lucene/dev/branches/branch_3x/solr/CHANGES.txt
    lucene/dev/branches/branch_3x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ScriptTransformer.java

Modified: lucene/dev/branches/branch_3x/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/CHANGES.txt?rev=1303042&r1=1303041&r2=1303042&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/CHANGES.txt (original)
+++ lucene/dev/branches/branch_3x/solr/CHANGES.txt Tue Mar 20 17:48:18 2012
@@ -258,6 +258,9 @@ Bug Fixes
  
 * SOLR-2124: Do not log stack traces for "Service Disabled" / 503 Exceptions (PingRequestHandler,
etc)
   (James Dyer, others)
+  
+* SOLR-3260: DataImportHandler: ScriptTransformer gives better error messages when 
+  problems arise on initalization (no Script Engine, invalid script, etc). (James Dyer)
 
 Other Changes
 ----------------------

Modified: lucene/dev/branches/branch_3x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ScriptTransformer.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ScriptTransformer.java?rev=1303042&r1=1303041&r2=1303042&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ScriptTransformer.java
(original)
+++ lucene/dev/branches/branch_3x/solr/contrib/dataimporthandler/src/java/org/apache/solr/handler/dataimport/ScriptTransformer.java
Tue Mar 20 17:48:18 2012
@@ -73,25 +73,35 @@ public class ScriptTransformer extends T
   }
 
   private void initEngine(Context context) {
+    String scriptText = context.getScript();
+    String scriptLang = context.getScriptLanguage();
+    if (scriptText == null) {
+      throw new DataImportHandlerException(SEVERE,
+          "<script> tag is not present under <dataConfig>");
+    }
+    Object scriptEngineMgr = null;
+    try {
+      scriptEngineMgr = Class.forName("javax.script.ScriptEngineManager")
+          .newInstance();
+    } catch (Exception e) {
+      wrapAndThrow(SEVERE, e, "<script> can be used only in java 6 or above");
+    }
     try {
-      String scriptText = context.getScript();
-      String scriptLang = context.getScriptLanguage();
-      if(scriptText == null ){
-        throw new DataImportHandlerException(SEVERE,
-              "<script> tag is not present under <dataConfig>");
-      }
-      Object scriptEngineMgr = Class
-              .forName("javax.script.ScriptEngineManager").newInstance();
-      // create a Script engine
       Method getEngineMethod = scriptEngineMgr.getClass().getMethod(
-              "getEngineByName", String.class);
+          "getEngineByName", String.class);
       engine = getEngineMethod.invoke(scriptEngineMgr, scriptLang);
+    } catch (Exception e) {
+      wrapAndThrow(SEVERE, e, "Cannot load Script Engine for language: "
+          + scriptLang);
+    }
+    try {
       Method evalMethod = engine.getClass().getMethod("eval", String.class);
       invokeFunctionMethod = engine.getClass().getMethod("invokeFunction",
-              String.class, Object[].class);
+          String.class, Object[].class);
       evalMethod.invoke(engine, scriptText);
     } catch (Exception e) {
-      wrapAndThrow(SEVERE,e, "<script> can be used only in java 6 or above");
+      wrapAndThrow(SEVERE, e, "'eval' failed with language: " + scriptLang
+          + " and script: \n" + scriptText);
     }
   }
 



Mime
View raw message