Package ninja

Examples of ninja.Result


            allRequestsMeter.mark();

            try {

                Result result = route.getFilterChain().next(context);

                resultHandler.handleResult(result, context);

            } catch (Exception exception) {

                if (exception instanceof BadRequestException) {

                    badRequests.mark();

                } else {

                    internalServerErrors.mark();

                }

                Result result = onException(context, exception);
                renderErrorResultAndCatchAndLogExceptions(result, context);

            }

        } else {
            // throw a 404 "not found" because we did not find the route
            routesNotFound.mark();

            Result result = getNotFoundResult(context);
            renderErrorResultAndCatchAndLogExceptions(result, context);
        }

        activeRequests.dec();
    }
View Full Code Here


        Cookie cookie = Cookie.builder("cookie", "yum").setDomain("domain").build();
        context.init(servletContext, httpServletRequest, httpServletResponse);
        //context.addCookie(cookie);

        //generate an arbitrary result:
        Result result = Results.html();
        result.addCookie(cookie);

        //finalize the headers => the cookies must be copied over to the servletcookies
        context.finalizeHeaders(result);

        //and verify the stuff:
View Full Code Here

        //init the context
        context.init(servletContext, httpServletRequest, httpServletResponse);

        //this must be Content-Type: application/json; encoding=utf-8
        Result result = Results.json();

        context.finalizeHeaders(result);

        verify(httpServletResponse).setCharacterEncoding(result.getCharset());
        verify(httpServletResponse).setContentType(result.getContentType());
    }
View Full Code Here

        //init the context
        context.init(servletContext, httpServletRequest, httpServletResponse);

        //this must be Content-Type: application/json; encoding=utf-8
        Result result = Results.json();
        //force a characterset that is not there. Stupid but tests that its working.
        result.charset(null);

        context.finalizeHeaders(result);

        //make sure utf-8 is used under all circumstances:
        verify(httpServletResponse).setCharacterEncoding(NinjaConstant.UTF_8);
View Full Code Here

    @Test
    public void testThatPostArticleReturnsOkWhenArticleDaoReturnsTrue() {

        when(articleDao.postArticle(null, null)).thenReturn(true);
       
        Result result = apiController.postArticleJson(null, null);
       
        assertEquals(200, result.getStatusCode());

    }
View Full Code Here

    @Test
    public void testThatPostArticleReturnsNotFoundWhenArticleDaoReturnsFalse() {

        when(articleDao.postArticle(null, null)).thenReturn(false);
       
        Result result = apiController.postArticleJson(null, null);
       
        assertEquals(404, result.getStatusCode());

    }
View Full Code Here

           
            if (timeout != 0) {
               
                if (System.currentTimeMillis() - theTimeQueued > timeout) {
                   
                    Result result = yodaResults.getTimeoutExceptionResult(context);
                    ninja.renderErrorResultAndCatchAndLogExceptions(result, context);
               
                }
               
            } else {

                context.returnResultAsync(filterChain.next(context));
               
            }
           
        } catch (Exception exception) {
           
            Result result = ninja.onException(context, exception);
            ninja.renderErrorResultAndCatchAndLogExceptions(result, context);
       
        }
    }
View Full Code Here

    public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
        
        
        YodaAsyncTask task = (YodaAsyncTask) runnable;
        Context context = task.getContext();
        Result result = yodaResults.getResponderRejectedExecutionResult(context);
       
       
        ninja.renderErrorResultAndCatchAndLogExceptions(result, context);
       
    }
View Full Code Here

                        context,
                        Optional.<Result>absent());
       
        Message message = new Message(messageI18n);

        Result result = Results
                .internalServerError()
                .render(message)
                .template(NinjaConstant.LOCATION_VIEW_FTL_HTML_INTERNAL_SERVER_ERROR);

        return result;
View Full Code Here

                        context,
                        Optional.<Result>absent());
       
        Message message = new Message(messageI18n);

        Result result = Results
                .internalServerError()
                .render(message)
                .template(NinjaConstant.LOCATION_VIEW_FTL_HTML_INTERNAL_SERVER_ERROR);

        return result;
View Full Code Here

TOP

Related Classes of ninja.Result

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.