Search in sources :

Example 1 with RenderResult

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);
}
Also used : RenderResult(cn.bran.japid.template.RenderResult) Test(org.junit.Test)

Example 2 with RenderResult

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);
}
Also used : RenderResult(cn.bran.japid.template.RenderResult) Test(org.junit.Test)

Example 3 with RenderResult

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);
    }
//
}
Also used : RenderResult(cn.bran.japid.template.RenderResult)

Example 4 with RenderResult

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();
}
Also used : RenderResult(cn.bran.japid.template.RenderResult) JapidTemplateException(cn.bran.japid.exceptions.JapidTemplateException) CompilationException(play.exceptions.CompilationException) JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) IOException(java.io.IOException)

Example 5 with RenderResult

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);
}
Also used : JapidCompilationException(cn.bran.japid.compiler.JapidCompilationException) JapidTemplateException(cn.bran.japid.exceptions.JapidTemplateException) RenderResult(cn.bran.japid.template.RenderResult) RendererClass(cn.bran.japid.rendererloader.RendererClass)

Aggregations

RenderResult (cn.bran.japid.template.RenderResult)28 Test (org.junit.Test)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 InternetAddress (javax.mail.internet.InternetAddress)3 Email (org.apache.commons.mail.Email)3 EmailAttachment (org.apache.commons.mail.EmailAttachment)3 EmailException (org.apache.commons.mail.EmailException)3 HtmlEmail (org.apache.commons.mail.HtmlEmail)3 MultiPartEmail (org.apache.commons.mail.MultiPartEmail)3 JapidCompilationException (cn.bran.japid.compiler.JapidCompilationException)2 JapidTemplateException (cn.bran.japid.exceptions.JapidTemplateException)2 JapidTemplateBaseWithoutPlay (cn.bran.japid.template.JapidTemplateBaseWithoutPlay)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MailException (play.exceptions.MailException)2 UnexpectedException (play.exceptions.UnexpectedException)2