Search in sources :

Example 1 with PlayException

use of play.exceptions.PlayException in project Japid by branaway.

the class ActionBridge method invokeMethod.

/**
	 * this is really to do the reverse url lookup
	 * 
	 * @param actionString
	 * @param param
	 * @return
	 */
public ActionDefinition invokeMethod(String actionString, Object param) {
    try {
        // forms: Controller.action, action, package.Controller.action
        String action = actionString;
        //			String methodName = actionString;
        if (actionString.indexOf(".") > 0) {
        //				int lastIndexOf = actionString.lastIndexOf('.');
        ////				methodName = actionString.substring(lastIndexOf + 1);
        //				controllerName = actionString.substring(0, lastIndexOf);
        //				// fell spec with controller name
        } else {
            Request req = Request.current();
            if (req != null) {
                action = req.controller + "." + actionString;
            }
        }
        try {
            Map<String, Object> args = new HashMap<String, Object>();
            Method actionMethod = (Method) ActionInvoker.getActionMethod(action)[1];
            //				String[] names = (String[]) actionMethod
            //						.getDeclaringClass()
            //						.getDeclaredField("$" + actionMethod.getName() + computeMethodHash(actionMethod.getParameterTypes())).get(null);
            String[] names = Java.parameterNames(actionMethod);
            if (param instanceof Object[]) {
                Object[] arrayParam = (Object[]) param;
                // error. we must warn him.
                if (names.length < arrayParam.length) {
                    throw new NoRouteFoundException(action, null);
                }
                Annotation[] annos = actionMethod.getAnnotations();
                for (int i = 0; i < arrayParam.length; i++) {
                    Object arrayParamElem = arrayParam[i];
                    if (arrayParamElem instanceof Router.ActionDefinition && arrayParamElem != null) {
                        Unbinder.unBind(args, arrayParamElem.toString(), i < names.length ? names[i] : "", annos);
                    } else if (isSimpleParam(actionMethod.getParameterTypes()[i])) {
                        if (arrayParamElem != null) {
                            Unbinder.unBind(args, arrayParamElem.toString(), i < names.length ? names[i] : "", annos);
                        }
                    } else {
                        Unbinder.unBind(args, arrayParamElem, i < names.length ? names[i] : "", annos);
                    }
                }
            }
            Router.ActionDefinition def = Router.reverse(action, args);
            if (absolute) {
                def.absolute();
            }
            // if (template.template.name.endsWith(".html") ||
            // template.template.name.endsWith(".xml")) {
            def.url = def.url.replace("&", "&amp;");
            // }
            return def;
        } catch (ActionNotFoundException e) {
            //				throw new NoRouteFoundException(action, null);
            throw new ReverseRouteException(action);
        }
    } catch (Exception e) {
        if (e instanceof PlayException) {
            throw (PlayException) e;
        }
        if (e instanceof JapidRuntimeException) {
            throw (JapidRuntimeException) e;
        }
        throw new UnexpectedException(e);
    }
}
Also used : JapidRuntimeException(cn.bran.japid.exceptions.JapidRuntimeException) UnexpectedException(play.exceptions.UnexpectedException) HashMap(java.util.HashMap) Request(play.mvc.Http.Request) Router(play.mvc.Router) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) PlayException(play.exceptions.PlayException) JapidRuntimeException(cn.bran.japid.exceptions.JapidRuntimeException) NoRouteFoundException(play.exceptions.NoRouteFoundException) ActionNotFoundException(play.exceptions.ActionNotFoundException) UnexpectedException(play.exceptions.UnexpectedException) ReverseRouteException(cn.bran.play.exceptions.ReverseRouteException) ActionNotFoundException(play.exceptions.ActionNotFoundException) NoRouteFoundException(play.exceptions.NoRouteFoundException) ActionDefinition(play.mvc.Router.ActionDefinition) PlayException(play.exceptions.PlayException) ReverseRouteException(cn.bran.play.exceptions.ReverseRouteException)

Example 2 with PlayException

use of play.exceptions.PlayException in project Japid by branaway.

the class error500ForPlay method doLayout.

@Override
protected void doLayout() {
    beginDoLayout(sourceTemplate);
    // line 1, myerror500.html
    ;
    // line 1, myerror500.html
    ;
    p("<style type=\"text/css\">\n" + "    html, body {\n" + "        margin: 0;\n" + "        padding: 0;\n" + "        font-family: Helvetica, Arial, Sans;\n" + "        background: #EEEEEE;\n" + "    }\n" + "    .block {\n" + "        padding: 20px;\n" + "        border-bottom: 1px solid #aaa;\n" + "    }\n" + "    #header h1 {\n" + "        font-weight: normal;\n" + "        font-size: 28px;\n" + "        margin: 0;\n" + "    }\n" + "    #more {\n" + "        color: #666;\n" + "        font-size: 80%;\n" + "        border: none;\n" + "    }\n" + "    #header {\n" + "        background: #fcd2da;\n" + "    }\n" + "    #header p {\n" + "        color: #333;\n" + "    }\n" + "    #source {\n" + "        background: #f6f6f6;\n" + "    }\n" + "    #source h2 {\n" + "        font-weight: normal;\n" + "        font-size: 18px;\n" + "        margin: 0 0 10px 0;\n" + "    }\n" + "    #source .lineNumber {\n" + "        float: left;\n" + "        display: block;\n" + "        width: 40px;\n" + "        text-align: right;\n" + "        margin-right: 10px;\n" + "        font-size: 14px;\n" + "        font-family: monospace;\n" + "        background: #333;\n" + "        color: #fff;\n" + "    }\n" + "    #source .line {\n" + "        clear: both;\n" + "        color: #333;\n" + "        margin-bottom: 1px;\n" + "    }\n" + "    #source pre {\n" + "        font-size: 14px;\n" + "        margin: 0;\n" + "        overflow-x: hidden;\n" + "    }\n" + "    #source .error {\n" + "        color: #c00 !important;\n" + "    }\n" + "    #source .error .lineNumber {\n" + "        background: #c00;\n" + "    }\n" + "    #source a {\n" + "        text-decoration: none;\n" + "    }\n" + "    #source a:hover * {\n" + "        cursor: pointer !important;\n" + "    }\n" + "    #source a:hover pre {\n" + "        background: #FAFFCF !important;\n" + "    }\n" + "    #source em {\n" + "        font-style: normal;\n" + "        text-decoration: underline;\n" + "        font-weight: bold;\n" + "    }\n" + "    #source strong {\n" + "        font-style: normal;\n" + "        font-weight: bold;\n" + "    }\n" + // line
    "</style>\n");
    if (asBoolean(exp instanceof PlayException)) {
        // line 87,
        // myerror500.html
        // line 88,
        PlayException exception = (PlayException) exp;
        // myerror500.html
        // line 89,
        Integer lineNumber = exception.getLineNumber();
        // myerror500.html
        // line 90, myerror500.html
        String mode = play.Play.mode.name();
        // line
        List<String> source = exception.isSourceAvailable() ? ((SourceAttachment) exception).getSource() : null;
        // 91,
        // myerror500.html
        // line 92,
        int sourceSize = source == null ? -1 : source.size();
        // myerror500.html
        // line
        p("    <div id=\"header\" class=\"block\">\n" + "        <h1>\n" + "            ");
        // 92,
        // myerror500.html
        // line 95, myerror500.html
        p((exception.getErrorTitle()));
        // line 95,
        p(" \n" + "        </h1>\n" + "        ");
        // myerror500.html
        if (asBoolean(mode.equals("DEV"))) {
            // line 97, myerror500.html
            // line 97,
            p("	        <p>\n" + "	            ");
            // myerror500.html
            // line 99, myerror500.html
            p((exception.getErrorDescription()));
            // line 99, myerror500.html
            p("	        </p>\n" + "        ");
        }
        // line 101, myerror500.html
        if (asBoolean(mode.equals("PROD"))) {
            // line 102, myerror500.html
            p("	        <p>\n" + "	            ... Error details are not displayed when Play! is in PROD mode. Check server logs for detail.\n" + "	        </p>\n" + // line 102,
            "        ");
        // myerror500.html
        }
        // line 106, myerror500.html
        // line 106, myerror500.html
        p("    </div>\n" + "    ");
        if (asBoolean(exception.isSourceAvailable() && lineNumber != null && mode.equals("DEV"))) {
            // line
            // 108,
            // myerror500.html
            // line
            p("	    <div id=\"source\" class=\"block\">\n" + "	        <h2>In ");
            // 108,
            // myerror500.html
            // line 110, myerror500.html
            p(exception.getSourceFile());
            // line 110, myerror500.html
            p(" (around line ");
            // line 110, myerror500.html
            p(lineNumber);
            // line 110,
            p(")</h2>\n" + "            \n" + "            ");
            // myerror500.html
            // line
            int from = lineNumber - 5 >= 0 && lineNumber <= sourceSize ? lineNumber - 5 : 0;
            // 112,
            // myerror500.html
            // line
            int to = lineNumber + 5 < sourceSize ? lineNumber + 5 : sourceSize - 1;
            for (int i = from; i < to; i++) {
                // line 115, myerror500.html
                // line 116, myerror500.html
                String line = source.get(i);
                // line 116,
                p("                <div class=\"line ");
                // myerror500.html
                // line 117,
                p(lineNumber.equals(i + 1) ? "error" : "");
                // myerror500.html
                // line
                p("\">\n" + "                    <span class=\"lineNumber\">");
                // 117,
                // myerror500.html
                // line 118, myerror500.html
                p(i + 1);
                // line
                p(":</span>\n" + "                    <pre>&nbsp;");
                // 118,
                // myerror500.html
                // line 119, myerror500.html
                p(escape(line));
                // line
                p("</pre>\n" + "                </div>\n" + "	        ");
            // 119,
            // myerror500.html
            }
            // line 121, myerror500.html
            // line 121, myerror500.html
            p("	    </div>\n" + "    ");
        }
        // line 123, myerror500.html
        // line 125,
        String moreHtml = exception.getMoreHTML();
        // myerror500.html
        if (asBoolean(moreHtml)) {
            // line 126, myerror500.html
            // line
            p("        <div id=\"specific\" class=\"block\">\n" + "            ");
            // 126,
            // myerror500.html
            // line 128, myerror500.html
            p(moreHtml);
            // line 128, myerror500.html
            p("        </div>\n" + "    ");
        }
        // line 130, myerror500.html
        // line
        p("    <div id=\"more\" class=\"block\">\n" + "        This exception has been logged with id <strong>");
        // 130,
        // myerror500.html
        // line 132, myerror500.html
        p(exception.getId());
        // line 132, myerror500.html
        p("</strong>\n" + "    </div>\n");
    } else {
        // line 134, myerror500.html
        // line
        p("    <div id=\"header\" class=\"block\">\n" + "        <h1>");
        // myerror500.html
        try {
            Object o = exp.getMessage();
            if (o.toString().length() == 0) {
                ;
            } else {
                p(o);
            }
        } catch (NullPointerException npe) {
            ;
        }
        // line 136, myerror500.html
        // line 136, myerror500.html
        p("</h1>\n" + "    </div>\n");
    }
    // line 138, myerror500.html
    ;
    endDoLayout(sourceTemplate);
}
Also used : PlayException(play.exceptions.PlayException)

Aggregations

PlayException (play.exceptions.PlayException)2 JapidRuntimeException (cn.bran.japid.exceptions.JapidRuntimeException)1 ReverseRouteException (cn.bran.play.exceptions.ReverseRouteException)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 ActionNotFoundException (play.exceptions.ActionNotFoundException)1 NoRouteFoundException (play.exceptions.NoRouteFoundException)1 UnexpectedException (play.exceptions.UnexpectedException)1 Request (play.mvc.Http.Request)1 Router (play.mvc.Router)1 ActionDefinition (play.mvc.Router.ActionDefinition)1