Package ninja

Examples of ninja.Cookie


    public void init(Context context) {

        try {

            // get the cookie that contains session information:
            Cookie cookie = context.getCookie(applicationCookiePrefix
                    + ninja.utils.NinjaConstant.SESSION_SUFFIX);

            // check that the cookie is not empty:
            if (cookie != null && cookie.getValue() != null
                    && !cookie.getValue().trim().equals("")) {

                String value = cookie.getValue();

                // the first substring until "-" is the sign
                String sign = value.substring(0, value.indexOf("-"));

                // rest from "-" until the end it the payload of the cookie
View Full Code Here


    }

    @Override
    public void init(Context context) {
        // get flash cookie:
        Cookie flashCookie = context.getCookie(applicationCookiePrefix
                + ninja.utils.NinjaConstant.FLASH_SUFFIX);

        if (flashCookie != null) {
            try {
               
                CookieDataCodec.decode(currentFlashCookieData, flashCookie.getValue());

            } catch (UnsupportedEncodingException e) {
                logger.error("Encoding exception - this must not happen", e);
            }
        }
View Full Code Here

     * @return The cookie
     */
    private Cookie generateNinjaLanguageCookie() {
       
           
        Cookie cookie = Cookie.builder(applicationCookiePrefix
                    + ninja.utils.NinjaConstant.LANG_COOKIE_SUFFIX, "")
                    .setMaxAge(TEN_YEARS).build();
           
       
       
View Full Code Here

   

    @Test
    public void testGetLanguage() {
       
        Cookie cookie = Cookie.builder("NINJA_TEST" + NinjaConstant.LANG_COOKIE_SUFFIX, "de").build();

        when(ninjaProperties.getOrDie(NinjaConstant.applicationCookiePrefix)).thenReturn("NINJA_TEST");
        when(context.getCookie("NINJA_TEST" + NinjaConstant.LANG_COOKIE_SUFFIX)).thenReturn(cookie);

        Lang lang = new LangImpl(ninjaProperties);
View Full Code Here

    }
   
    @Test
    public void testChangeLanguage() {
       
        Cookie cookie = Cookie.builder("NINJA_TEST" + NinjaConstant.LANG_COOKIE_SUFFIX, "de").build();
        when(ninjaProperties.getOrDie(NinjaConstant.applicationCookiePrefix)).thenReturn("NINJA_TEST");
      
        Lang lang = new LangImpl(ninjaProperties);
       
        // test with result
        Result result = Results.noContent();
       
        result = lang.setLanguage("to", result);
        assertEquals("to", result.getCookie(cookie.getName()).getValue());
        assertEquals(Result.SC_204_NO_CONTENT, result.getStatusCode());


    }
View Full Code Here

    }
   
    @Test
    public void testClearLanguage() {
       
        Cookie cookie = Cookie.builder("NINJA_TEST" + NinjaConstant.LANG_COOKIE_SUFFIX, "de").build();

        when(ninjaProperties.getOrDie(NinjaConstant.applicationCookiePrefix)).thenReturn("NINJA_TEST");

        Lang lang = new LangImpl(ninjaProperties);
       
        Result result = Results.ok();
       
        lang.clearLanguage(result);
       
        Cookie returnCookie = result.getCookie(cookie.getName());
        assertEquals("", returnCookie.getValue());
        assertEquals(0, returnCookie.getMaxAge());
       
    }
View Full Code Here

TOP

Related Classes of ninja.Cookie

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.