SOLR-3260: better messages when ScriptTransform fails on init

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1302972 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Dyer 2012-03-20 16:21:13 +00:00
parent 255f763640
commit f2544bdd3d
2 changed files with 25 additions and 12 deletions

View File

@ -694,6 +694,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
----------------------

View File

@ -72,25 +72,35 @@ public class ScriptTransformer extends Transformer {
}
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);
}
}