Example usage for javax.servlet.http Cookie setMaxAge

List of usage examples for javax.servlet.http Cookie setMaxAge

Introduction

In this page you can find the example usage for javax.servlet.http Cookie setMaxAge.

Prototype

public void setMaxAge(int expiry) 

Source Link

Document

Sets the maximum age in seconds for this Cookie.

Usage

From source file:com.eryansky.common.web.utils.RequestUtil.java

public static void setCookie(HttpServletResponse response, String name, String value, String path) {
    if (logger.isDebugEnabled()) {
        logger.debug("Cookie '" + name + "',?: '" + path + "'");
    }/*from  w  w w .  ja v  a  2 s  .  c o  m*/

    Cookie cookie = new Cookie(name, value);
    cookie.setSecure(false);
    cookie.setPath(path);
    cookie.setMaxAge(2592000);

    response.addCookie(cookie);
}

From source file:com.usefullc.platform.common.utils.CookieUtils.java

/**
 * cookie//  w w w .j  a  va 2  s.co  m
 * 
 * @param request
 * @param response
 * @param name
 */
public static void remove(String name, String domain) {
    Cookie cookie = new Cookie(name, "");
    cookie.setPath("/");
    cookie.setMaxAge(0);
    cookie.setDomain(domain);
    HttpServletResponse response = ServeltContextManager.getResponse();
    response.addCookie(cookie);
}

From source file:ke.alphacba.cms.core.util.NoSessionIdUtils.java

private static void writeCookie(HttpServletResponse response, String loginCookieName, String domain,
        int cookieTime, String jsessionId, boolean httpOnly) {

    String cookieValue = new String(Base64.encodeBase64(new StringBuilder().append(loginCookieName)
            .append(new Date().getTime()).append(jsessionId).toString().getBytes()));
    Cookie cookie1 = new Cookie(loginCookieName, cookieValue);
    cookie1.setHttpOnly(true);/*from   w  ww  . ja  v  a 2s  .co  m*/
    cookie1.setMaxAge(cookieTime);
    cookie1.setPath("/");
    cookie1.setDomain(domain);
    response.addCookie(cookie1);
}

From source file:de.escidoc.core.common.servlet.UserHandleCookieUtil.java

/**
 * Creates an authentication cookie holding the provided eSciDoc user handle.<br> The cookie is valid for all
 * locations of the eSciDoc domain. Its max age is set to the value of the configuration parameter
 * escidoc.userHandle.cookie.lifetime.//from  w  w  w  .j a  v a  2s  .c  o  m
 *
 * @param handle The eSciDocUserHandle.
 * @return Returns the created {@link Cookie}.
 * @throws WebserverSystemException Thrown in case of an internal error (configuration parameter not retrievable).
 */
public static Cookie createAuthCookie(final String handle) throws WebserverSystemException {

    final Cookie authCookie = new Cookie(EscidocServlet.COOKIE_LOGIN, handle);

    authCookie.setMaxAge(getEscidocCookieLifetime());

    // Set the cookie for all locations of the escidoc domain
    authCookie.setPath("/");
    return authCookie;
}

From source file:net.bluehornreader.web.WebUtils.java

private static void saveCookie(HttpServletResponse httpServletResponse, boolean secured, String name,
        String value, int expires) {
    Cookie cookie = new Cookie(name, value);
    cookie.setHttpOnly(true);/*  w  w  w  . jav a 2  s. co m*/
    cookie.setMaxAge(expires);
    cookie.setPath("/");
    if (secured) {
        cookie.setSecure(true);
    }
    LOG.info(cookieAsString(cookie));
    httpServletResponse.addCookie(cookie);
}

From source file:org.glimpse.server.GlimpseUtils.java

public static void setConnectionId(HttpServletRequest request, HttpServletResponse response,
        String connectionId, boolean persistent) {
    Cookie cookie = new Cookie(COOKIE_CONNECTION, connectionId);
    cookie.setPath(request.getContextPath() + "/");
    if (!persistent) {
        cookie.setMaxAge(-1);
    } else {/*  ww w  .ja v a2  s .c o  m*/
        cookie.setMaxAge(365 * 24 * 60 * 60);
    }
    response.addCookie(cookie);
}

From source file:com.leixl.easyframework.web.CookieUtils.java

/**
 * ?cookie?//from  w w  w. j  av a 2  s  .  c o m
 * 
 * @param request
 * @param response
 * @param name
 * @param value
 * @param expiry
 * @param domain
 * @return
 */
public static Cookie addCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String value, Integer expiry, String domain) {
    Cookie cookie = new Cookie(name, value);
    if (expiry != null) {
        cookie.setMaxAge(expiry);
    }
    if (StringUtils.isNotBlank(domain)) {
        cookie.setDomain(domain);
    }
    String ctx = request.getContextPath();
    cookie.setPath(StringUtils.isBlank(ctx) ? "/" : ctx);
    response.addCookie(cookie);
    return cookie;
}

From source file:com.wikipy.security.AuthenticationFilter.java

public static Cookie createNewCookie(HttpServletResponse httpResp) {
    Cookie cookie = new Cookie(ARG_TICKET, UUID.randomUUID().toString());
    cookie.setMaxAge(24 * 60 * 60);
    cookie.setPath("/");
    httpResp.addCookie(cookie);//w w  w .j a  va  2  s .co m
    return cookie;
}

From source file:com.erudika.scoold.utils.HttpUtils.java

/**
 * Sets a cookie./*from www.  j a  v a2 s .  c  om*/
 * @param name the name
 * @param value the value
 * @param req HTTP request
 * @param res HTTP response
 * @param httpOnly HTTP only flag
 * @param maxAge max age
 */
public static void setRawCookie(String name, String value, HttpServletRequest req, HttpServletResponse res,
        boolean httpOnly, int maxAge) {
    if (StringUtils.isBlank(name) || value == null || req == null || res == null) {
        return;
    }
    Cookie cookie = new Cookie(name, value);
    cookie.setHttpOnly(httpOnly);
    cookie.setMaxAge(maxAge < 0 ? Config.SESSION_TIMEOUT_SEC : maxAge);
    cookie.setPath("/");
    cookie.setSecure(req.isSecure());
    res.addCookie(cookie);
}

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);
    response.addCookie(cookie);//from   w ww.  ja  v a 2  s. c  o  m

    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);
}