Tabnine Logo
Cookie.setMaxAge
Code IndexAdd Tabnine to your IDE (free)

How to use
setMaxAge
method
in
ro.polak.http.servlet.Cookie

Best Java code snippets using ro.polak.http.servlet.Cookie.setMaxAge (Showing top 4 results out of 315)

origin: piotrpolak/android-http-server

@Test
public void shouldSerializeExpiresBasedOnMaxAge() {
  int maxAgeSeconds = 35;
  Cookie cookie = new Cookie("name", "value");
  cookie.setMaxAge(maxAgeSeconds);
  String serializedCookie = cookieHeaderSerializer.serialize(cookie);
  Date date = new Date(System.currentTimeMillis() + Long.valueOf(maxAgeSeconds) * 1000l);
  String expiresValue = DateUtilities.dateFormat(date);
  assertThat(getExpiresValue(serializedCookie), is(expiresValue));
}
origin: piotrpolak/android-http-server

/**
 * Handles session storage/invalidation, sets session cookies.
 *
 * @param session
 * @param response
 * @throws IOException
 */
public void handleSession(final HttpSessionImpl session, final HttpServletResponseImpl response) throws IOException {
  Cookie cookie = new Cookie(HttpSessionImpl.COOKIE_NAME, "");
  if (session.isInvalidated()) {
    cookie.setMaxAge(MAX_AGE_IN_PAST);
    sessionStorage.removeSession(session);
    LOGGER.log(Level.FINE, "Invalidated session {0}",
        new Object[]{session.getId()});
  } else {
    cookie.setValue(session.getId());
    sessionStorage.persistSession(session);
  }
  response.addCookie(cookie);
}
origin: piotrpolak/android-http-server

@Test
public void shouldWorkGettersAndSetters() {
  Cookie cookie = new Cookie("someName", "someValue");
  cookie.setComment("comment");
  cookie.setDomain("example.com");
  cookie.setPath("/somepath");
  cookie.setSecure(true);
  cookie.setHttpOnly(true);
  assertThat(cookie.getName(), is("someName"));
  assertThat(cookie.getValue(), is("someValue"));
  cookie.setValue("SomeValue2");
  assertThat(cookie.getValue(), is("SomeValue2"));
  assertThat(cookie.getComment(), is("comment"));
  assertThat(cookie.getDomain(), is("example.com"));
  assertThat(cookie.getPath(), is("/somepath"));
  assertThat(cookie.isSecure(), is(true));
  assertThat(cookie.isHttpOnly(), is(true));
  assertThat(cookie.getMaxAge(), is(-1));
  cookie.setMaxAge(125);
  assertThat(cookie.getMaxAge(), is(125));
}
origin: piotrpolak/android-http-server

@Test
public void shouldSerializeCookieWithAllAttributes() {
  Cookie cookie = new Cookie("name", "value");
  cookie.setDomain("example.com");
  cookie.setMaxAge(20);
  cookie.setSecure(true);
  cookie.setHttpOnly(true);
  cookie.setPath("/somepath");
  cookie.setComment("Some Comment");
  String serializedCookie = cookieHeaderSerializer.serialize(cookie);
  String[] serializedCookieParts = getCookieParts(serializedCookie);
  assertThat(serializedCookie, startsWith("name=value"));
  assertThat(serializedCookie, containsString("Expires"));
  assertThat(getExpiresValue(serializedCookie), endsWith("GMT")); // Pseudo date validation
  assertThat(serializedCookieParts, hasItemInArray("Domain=example.com"));
  assertThat(serializedCookieParts, hasItemInArray("Path=/somepath"));
  assertThat(serializedCookieParts, hasItemInArray("HttpOnly"));
  assertThat(serializedCookieParts, hasItemInArray("Secure"));
  assertThat(serializedCookieParts, hasItemInArray("Comment=Some Comment"));
}
ro.polak.http.servletCookiesetMaxAge

Javadoc

Sets cookie max age in seconds. Set negative value less than -1 to remove cookie.

Popular methods of Cookie

  • <init>
  • getComment
    Return cookie comment.
  • getDomain
    Returns cookie domain pattern.
  • getMaxAge
    Returns cookie max age in seconds.
  • getName
    Returns cookie name.
  • getPath
    Returns cookie path.
  • getValue
    Returns cookie value.
  • isHttpOnly
    Tells whether the cookie is http only.
  • isSecure
    Tells whether the cookie is secure.
  • setValue
    Sets cookie value.
  • checkNameForIllegalCharacters
  • setComment
    Sets cookie comment.
  • checkNameForIllegalCharacters,
  • setComment,
  • setDomain,
  • setHttpOnly,
  • setPath,
  • setSecure

Popular in Java

  • Reactive rest calls using spring rest template
  • scheduleAtFixedRate (ScheduledExecutorService)
  • addToBackStack (FragmentTransaction)
  • getContentResolver (Context)
  • Kernel (java.awt.image)
  • NoSuchElementException (java.util)
    Thrown when trying to retrieve an element past the end of an Enumeration or Iterator.
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • ReentrantLock (java.util.concurrent.locks)
    A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
  • ImageIO (javax.imageio)
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now