StandardScriptEvaluator uses same eval exception exposure as ScriptTemplateView
Issue: SPR-13557
This commit is contained in:
parent
92dc51f6a8
commit
1d59c5fd41
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -79,10 +79,10 @@ public class BshScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware
|
|||
return interpreter.eval(new StringReader(script.getScriptAsString()));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new ScriptCompilationException(script, "Cannot access script", ex);
|
||||
throw new ScriptCompilationException(script, "Cannot access BeanShell script", ex);
|
||||
}
|
||||
catch (EvalError ex) {
|
||||
throw new ScriptCompilationException(script, "Evaluation failure", ex);
|
||||
throw new ScriptCompilationException(script, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,27 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.scripting.groovy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import groovy.lang.Binding;
|
||||
import groovy.lang.GroovyRuntimeException;
|
||||
import groovy.lang.GroovyShell;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
|
||||
import org.springframework.beans.factory.BeanClassLoaderAware;
|
||||
import org.springframework.scripting.ScriptCompilationException;
|
||||
|
|
@ -65,10 +81,10 @@ public class GroovyScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAw
|
|||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new ScriptCompilationException(script, "Cannot access script", ex);
|
||||
throw new ScriptCompilationException(script, "Cannot access Groovy script", ex);
|
||||
}
|
||||
catch (CompilationFailedException ex) {
|
||||
throw new ScriptCompilationException(script, "Evaluation failure", ex);
|
||||
catch (GroovyRuntimeException ex) {
|
||||
throw new ScriptCompilationException(script, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.scripting.support;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
|
||||
/**
|
||||
* Exception decorating a {@link javax.script.ScriptException} coming out of
|
||||
* JSR-223 script evaluation, i.e. a {@link javax.script.ScriptEngine#eval}
|
||||
* call or {@link javax.script.Invocable#invokeMethod} /
|
||||
* {@link javax.script.Invocable#invokeFunction} call.
|
||||
*
|
||||
* <p>This exception does not print the Java stacktrace, since the JSR-223
|
||||
* {@link ScriptException} results in a rather convoluted text output.
|
||||
* From that perspective, this exception is primarily a decorator for a
|
||||
* {@link ScriptException} root cause passed into an outer exception.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.2.2
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class StandardScriptEvalException extends RuntimeException {
|
||||
|
||||
private final ScriptException scriptException;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new script eval exception with the specified original exception.
|
||||
*/
|
||||
public StandardScriptEvalException(ScriptException ex) {
|
||||
super(ex.getMessage());
|
||||
this.scriptException = ex;
|
||||
}
|
||||
|
||||
|
||||
public final ScriptException getScriptException() {
|
||||
return this.scriptException;
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -133,10 +133,10 @@ public class StandardScriptEvaluator implements ScriptEvaluator, BeanClassLoader
|
|||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new ScriptCompilationException(script, "Cannot access script", ex);
|
||||
throw new ScriptCompilationException(script, "Cannot access script for ScriptEngine", ex);
|
||||
}
|
||||
catch (ScriptException ex) {
|
||||
throw new ScriptCompilationException(script, "Evaluation failure", ex);
|
||||
throw new ScriptCompilationException(script, new StandardScriptEvalException(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.servlet.view.script;
|
||||
|
||||
/**
|
||||
* Exception thrown when an error occurs during script template rendering.
|
||||
*
|
||||
* <p>It does not print the java stacktrace in the logs, since it is not useful
|
||||
* in this script context.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @since 4.2.2
|
||||
*/
|
||||
public class ScriptRenderException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 421565510962788082L;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new script rendering exception with the specified detail message.
|
||||
*/
|
||||
public ScriptRenderException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ import java.util.Map;
|
|||
import javax.script.Invocable;
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
|
@ -42,6 +43,7 @@ import org.springframework.core.NamedThreadLocal;
|
|||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.scripting.support.StandardScriptEvalException;
|
||||
import org.springframework.scripting.support.StandardScriptUtils;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
|
@ -357,8 +359,8 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
|
|||
|
||||
response.getWriter().write(String.valueOf(html));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new ServletException("Failed to render script template", new ScriptRenderException(ex.getMessage()));
|
||||
catch (ScriptException ex) {
|
||||
throw new ServletException("Failed to render script template", new StandardScriptEvalException(ex));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue