mirror of https://github.com/apache/lucene.git
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:
parent
255f763640
commit
f2544bdd3d
|
@ -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
|
||||
----------------------
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue