Example usage for javax.servlet.http HttpServletResponse addCookie

List of usage examples for javax.servlet.http HttpServletResponse addCookie

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse addCookie.

Prototype

public void addCookie(Cookie cookie);

Source Link

Document

Adds the specified cookie to the response.

Usage

From source file:com.shirokumacafe.archetype.common.utilities.Servlets.java

/**
 * cookie/*w  ww .j  a  v  a2  s .  c o m*/
 */
public static void setCookie(String name, String value, HttpServletResponse response) {
    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge((int) ONE_YEAR_SECONDS);
    cookie.setPath("/");
    response.addCookie(cookie);
}

From source file:com.activecq.api.utils.CookieUtil.java

/**
 * Add the provided HTTP Cookie to the Response
 *
 * @param cookie Cookie to add/*from ww  w .j  av  a 2s . com*/
 * @param response Response to add Cookie to
 * @return true unless cookie or response is null
 */
public static boolean addCookie(Cookie cookie, HttpServletResponse response) {
    if (cookie == null || response == null) {
        return false;
    }

    response.addCookie(cookie);
    return true;
}

From source file:org.examproject.tweet.controller.OAuthController.java

private static void storeTokenToCookie(HttpServletResponse response, OAuthAccessorValue accessorValue,
        int maxAge) {
    Cookie cookie = new Cookie(TweetCookie.REQUEST_TOKEN.getName(), accessorValue.getRequestToken());
    cookie.setMaxAge(maxAge);//  w  w w .j  av a  2  s . com
    response.addCookie(cookie);

    cookie = new Cookie(TweetCookie.ACCESS_TOKEN.getName(), accessorValue.getAccessToken());
    cookie.setMaxAge(maxAge);
    response.addCookie(cookie);

    cookie = new Cookie(TweetCookie.TOKEN_SECRET.getName(), accessorValue.getTokenSecret());
    cookie.setMaxAge(maxAge);
    response.addCookie(cookie);

    cookie = new Cookie(TweetCookie.USER_ID.getName(), accessorValue.getId());
    cookie.setMaxAge(maxAge);
    response.addCookie(cookie);

    cookie = new Cookie(TweetCookie.SCREEN_NAME.getName(), accessorValue.getScreenName());
    cookie.setMaxAge(maxAge);
    response.addCookie(cookie);
}

From source file:com.adobe.acs.commons.util.CookieUtil.java

/**
 * Add the provided HTTP Cookie to the Response
 *
 * @param cookie   Cookie to add/*from ww  w.  ja  va 2 s .c  o m*/
 * @param response Response to add Cookie to
 * @return true unless cookie or response is null
 */
public static boolean addCookie(final Cookie cookie, final HttpServletResponse response) {
    if (cookie == null || response == null) {
        return false;
    }

    response.addCookie(cookie);
    return true;
}

From source file:org.apache.cxf.fediz.service.idp.util.WebUtils.java

public static void addCookie(final RequestContext context, final String cookieName, final String cookieValue) {
    HttpServletResponse httpServletResponse = getHttpServletResponse(context);
    Cookie cookie = new Cookie(cookieName, cookieValue);
    cookie.setSecure(true);//ww w  .j a v  a2s . com
    cookie.setMaxAge(-1);
    httpServletResponse.addCookie(cookie);
}

From source file:com.kingcore.framework.util.CookieUtils.java

/**
 *  ? domain clearCookie//from  ww w . j  av a2 s .  com
 * clear a cookie from client side.
 * @param name the name of cookie will be cleared.
 * @param response HttpServletResponse Object.
 */
public static void clearCookie(String name, HttpServletResponse response) {
    Cookie cookie = new Cookie(name, null);
    cookie.setMaxAge(0);
    cookie.setPath("/");
    response.addCookie(cookie);
}

From source file:alpha.portal.webapp.util.RequestUtil.java

/**
 * Convenience method for deleting a cookie by name.
 * //  w  w w . j ava 2  s  .c  o  m
 * @param response
 *            the current web response
 * @param cookie
 *            the cookie to delete
 * @param path
 *            the path on which the cookie was set (i.e. /appfuse)
 */
public static void deleteCookie(final HttpServletResponse response, final Cookie cookie, final String path) {
    if (cookie != null) {
        // Delete the cookie by setting its maximum age to zero
        cookie.setMaxAge(0);
        cookie.setPath(path);
        response.addCookie(cookie);
    }
}

From source file:gov.nih.nci.cabig.caaers.web.utils.WebUtils.java

public static void setBuildInfoCookie(HttpServletResponse response, String buildName) {
    response.addCookie(new Cookie(BUILD_INFO_COOKIE, buildName));
}

From source file:org.apache.cxf.fediz.service.idp.util.WebUtils.java

public static void removeCookie(final RequestContext context, final String cookieName) {
    HttpServletResponse httpServletResponse = getHttpServletResponse(context);
    Cookie cookie = readCookie(context, cookieName);
    if (cookie != null) {
        cookie.setMaxAge(0);//from  w  w w  . j  a  v a2s  . c  o  m
        cookie.setValue("");
        httpServletResponse.addCookie(cookie);
    }
}

From source file:architecture.ee.web.util.CookieUtils.java

public static void deleteCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie) {
    if (cookie != null) {
        String path = request.getContextPath() != null ? request.getContextPath() : "/";
        if ("".equals(path))
            path = "/";
        cookie.setPath(path);/*from www.j  a  va  2  s.co m*/
        cookie.setValue("");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
    }
}