Package com.alibaba.citrus.service.requestcontext.util

Examples of com.alibaba.citrus.service.requestcontext.util.CookieSupport


    @Test
    public void session_reuseSessionID() throws Exception {
        // request 1
        invokeNoopServlet("/servlet");

        CookieSupport cookie = new CookieSupport("JSESSIONID", "1234567890ABCDEFG");

        cookie.setPath("/");
        cookie.addCookie(response);

        commitToClient();

        assertEquals("1234567890ABCDEFG", clientResponse.getNewCookieValue("JSESSIONID")); // new added cookie
View Full Code Here


        assertEquals(true, session.isNew());

        session.setAttribute("count", 0);

        // 伪造checksum cookie,内容不匹配
        CookieSupport cookie = new CookieSupport("myCookieStoresum", "hello");
        cookie.setDomain(".taobao.com");
        cookie.setPath("/");
        cookie.setMaxAge(10);
        cookie.addCookie(newResponse);

        requestContexts.commitRequestContext(requestContext);
        commitToClient();

        // check new added cookie
View Full Code Here

        invokeNoopServlet("/servlet");
        noSession = true; // 不要创建session,手工建cookies
        initRequestContext("session_cookie");

        // 伪造checksum cookie,数量不匹配
        CookieSupport cookie = new CookieSupport("JSESSIONID", sessionID);
        cookie.setDomain(".taobao.com");
        cookie.setPath("/");
        cookie.setMaxAge(10);
        cookie.addCookie(newResponse);

        cookie = new CookieSupport("myCookieStore0", myCookieStore0);
        cookie.setDomain(".taobao.com");
        cookie.setPath("/");
        cookie.setMaxAge(10);
        cookie.addCookie(newResponse);

        cookie = new CookieSupport("myCookieStoresum", myCookieStoresum + "|hello");
        cookie.setDomain(".taobao.com");
        cookie.setPath("/");
        cookie.setMaxAge(10);
        cookie.addCookie(newResponse);

        requestContexts.commitRequestContext(requestContext);
        commitToClient();

        // check new added cookie
View Full Code Here

    @Test
    public void reuseSessionId() throws Exception {
        // request 1
        invokeNoopServlet("/servlet");

        CookieSupport cookie = new CookieSupport("JSESSIONID", "1234567890ABCDEFG");

        cookie.setPath("/");
        cookie.addCookie(response);

        commitToClient();

        assertEquals("1234567890ABCDEFG", clientResponse.getNewCookieValue("JSESSIONID")); // new added cookie
View Full Code Here

    @Test
    public void checkCookie_modifiy_cookieSupport() {
        createResponse(new MyCookieInterceptor() {
            public Cookie checkCookie(Cookie cookie) {
                return new CookieSupport(cookie, "new" + cookie.getName());
            }
        });

        responseMock.addHeader("Set-Cookie", "newtest=value");
View Full Code Here

        // 预先确定session id 以便测试
        sessionId = "1234567890ABCDEFG";
        invokeNoopServlet("/servlet");

        CookieSupport cookie = new CookieSupport("JSESSIONID", sessionId);

        cookie.setPath("/");
        cookie.addCookie(response);

        commitToClient();

        assertEquals(sessionId, clientResponse.getNewCookieValue("JSESSIONID")); // new added cookie
View Full Code Here

    @Test
    public void session_reuseSessionID() throws Exception {
        // request 1
        invokeNoopServlet("/servlet");

        CookieSupport cookie = new CookieSupport("JSESSIONID", "1234567890ABCDEFG");

        cookie.setPath("/");
        cookie.addCookie(response);

        commitToClient();

        assertEquals("1234567890ABCDEFG", clientResponse.getNewCookieValue("JSESSIONID")); // new added cookie
View Full Code Here

    }

    @Override
    public void addCookie(Cookie cookie) {
        Cookie newCookie = checkCookie(cookie);
        CookieSupport newCookieSupport;

        if (newCookie instanceof CookieSupport) {
            newCookieSupport = (CookieSupport) newCookie;
        } else {
            newCookieSupport = new CookieSupport(newCookie); // 将cookie强制转化成cookie support
        }

        newCookieSupport.addCookie(this); // 通过set-cookie header来添加cookie,以便统一监管
    }
View Full Code Here

    }

    /** 写cookie。 */
    private void writeSessionIDCookie(String cookieValue) {
        CookieConfig cookieConfig = sessionConfig.getId().getCookie();
        CookieSupport cookie = new CookieSupport(cookieConfig.getName(), cookieValue);
        String cookieDomain = cookieConfig.getDomain();

        if (!StringUtil.isEmpty(cookieDomain)) {
            cookie.setDomain(cookieDomain);
        }

        String cookiePath = cookieConfig.getPath();

        if (!StringUtil.isEmpty(cookiePath)) {
            cookie.setPath(cookiePath);
        }

        int cookieMaxAge = cookieConfig.getMaxAge();

        if (cookieMaxAge > 0) {
            cookie.setMaxAge(cookieMaxAge);
        }

        cookie.setHttpOnly(cookieConfig.isHttpOnly());
        cookie.setSecure(cookieConfig.isSecure());

        log.debug("{}", cookie);

        cookie.addCookie(getResponse());
    }
View Full Code Here

        String filteredValue = filterCRLF(value, "cookie " + name);

        if (filteredValue == null) {
            return cookie;
        } else {
            CookieSupport newCookie = new CookieSupport(cookie);
            newCookie.setValue(filteredValue);
            return newCookie;
        }
    }
View Full Code Here

TOP

Related Classes of com.alibaba.citrus.service.requestcontext.util.CookieSupport

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.