use of cn.bran.japid.template.RenderResult in project Japid by branaway.
the class ControllerUtilsTest method testEmptyArgs.
/**
* @throws InvocationTargetException
* @throws IllegalAccessException
* @throws IllegalArgumentException
*
*/
@Test
public void testEmptyArgs() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
RenderResult render;
render = (RenderResult) RenderInvokerUtils.render(new Bar(null));
assertNotNull(render);
}
use of cn.bran.japid.template.RenderResult in project Japid by branaway.
the class RenderResultCacheTest method testSimpleExpiration.
@Test
public void testSimpleExpiration() throws ShouldRefreshException {
RenderResultCache.setAltCache(new AltCacheSimpleImpl());
RenderResult rr = new RenderResult(null, null, 0);
RenderResultCache.set(KEY1, rr, "2s");
RenderResult rrr;
rrr = RenderResultCache.get(KEY1);
assertNotNull(rrr);
waitfor(3000);
rrr = RenderResultCache.get(KEY1);
assertNull(rrr);
}
use of cn.bran.japid.template.RenderResult in project Japid by branaway.
the class CacheableRunner method run.
/**
* the main entry point this action runner
*/
@Override
public RenderResult run() {
if (!shouldCache()) {
return render();
} else {
// cache in work
RenderResult rr = null;
if (!readThru) {
try {
rr = RenderResultCache.get(getKeyString());
if (rr != null)
return rr;
} catch (ShouldRefreshException e) {
// let's refresh the cache, flow through
}
}
try {
rr = render();
} catch (JapidResult e) {
rr = e.getRenderResult();
}
cacheResult(rr);
return (rr);
}
//
}
use of cn.bran.japid.template.RenderResult in project Japid by branaway.
the class JapidPlayRenderer method renderPlayException.
public static String renderPlayException(Exception e) {
Exception exp = cn.bran.play.util.PlayExceptionUtils.mapJapidJavaCodeError(e);
RenderResult rr = error500ForPlay.apply(exp);
return rr.toString();
}
use of cn.bran.japid.template.RenderResult in project Japid by branaway.
the class JapidPlayRenderer method handleException.
public static RenderResult handleException(Throwable e) throws RuntimeException {
if (!presentErrorInHtml)
if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException(e);
// if (Play.mode == Mode.PROD)
// throw new RuntimeException(e);
//
Class<? extends JapidTemplateBaseWithoutPlay> rendererClass = getErrorRendererClass();
if (e instanceof JapidTemplateException) {
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, (JapidTemplateException) e);
return (rr);
}
if (e instanceof RuntimeException && e.getCause() != null)
e = e.getCause();
if (e instanceof JapidCompilationException) {
JapidCompilationException jce = (JapidCompilationException) e;
JapidTemplateException te = JapidTemplateException.from(jce);
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
return (rr);
}
e.printStackTrace();
// find the latest japidviews exception or the controller that caused
// the exception
StackTraceElement[] stackTrace = e.getStackTrace();
for (StackTraceElement ele : stackTrace) {
String className = ele.getClassName();
if (className.startsWith("japidviews")) {
int lineNumber = ele.getLineNumber();
RendererClass applicationClass = japidClasses.get(className);
if (applicationClass != null) {
// let's get the line of problem
int oriLineNumber = applicationClass.mapJavaLineToJapidScriptLine(lineNumber);
if (oriLineNumber > 0) {
if (rendererClass != null) {
String path = applicationClass.getOriSourceCode();
JapidTemplateException te = new JapidTemplateException("Japid Error", path + "(" + oriLineNumber + "): " + e.getClass().getName() + ": " + e.getMessage(), oriLineNumber, path, applicationClass.getOriSourceCode());
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
return (rr);
}
}
}
} else if (className.startsWith("controllers.")) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
else
throw new RuntimeException(e);
}
}
JapidTemplateException te = new JapidTemplateException(e);
RenderResult rr = RenderInvokerUtils.invokeRender(rendererClass, te);
return rr;
// if (e instanceof RuntimeException)
// throw (RuntimeException) e;
// else
// throw new RuntimeException(e);
}
Aggregations