org.eclipse.jetty.http.DateGenerator Java Examples

The following examples show how to use org.eclipse.jetty.http.DateGenerator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CookieTestingServlet.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String redirect = req.getParameter("redirect");
    if (redirect == null) {
        redirect = "null";
    }

    String dateMode = req.getParameter("datemode");
    if (dateMode == null) {
        dateMode = DATEMODE_COOKIE_DEFAULT;
    }
    switch (dateMode) {
    case DATEMODE_COOKIE_DEFAULT:
    default:
        // standard way of building a cookie header date uses format "EEE, dd-MMM-yy HH:mm:ss z"
        // this results in Set-Cookie: session=abc123; path=/; expires=EEE, dd-MMM-yy HH:mm:ss z; HttpOnly
        Cookie cookie = new Cookie("session", "abc123");
        cookie.setPath("/");
        cookie.setHttpOnly(true);
        cookie.setMaxAge(86400);
        resp.addCookie(cookie);
        break;

    case DATEMODE_COOKIE_NOT_TYPICAL:
        // hacked way of building a cookie header, to get less-often-used date format "EEE, dd MMM yy HH:mm:ss z"
        // this results in Set-Cookie: session=abc123; path=/; expires=EEE, dd MMM yy HH:mm:ss z; HttpOnly
        StringBuilder buf = new StringBuilder("session=abc123; path=/; expires=");
        buf.append(DateGenerator.formatDate(System.currentTimeMillis() + 1000L * 60 * 60 * 24));
        buf.append("; HttpOnly");
        resp.addHeader("Set-Cookie", buf.toString());
    }

    resp.sendRedirect(redirect);
}
 
Example #2
Source File: CookieTestingServlet.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String redirect = req.getParameter("redirect");
    if (redirect == null) {
        redirect = "null";
    }

    String dateMode = req.getParameter("datemode");
    if (dateMode == null) {
        dateMode = DATEMODE_COOKIE_DEFAULT;
    }
    switch (dateMode) {
    case DATEMODE_COOKIE_DEFAULT:
    default:
        // standard way of building a cookie header date uses format "EEE, dd-MMM-yy HH:mm:ss z"
        // this results in Set-Cookie: session=abc123; path=/; expires=EEE, dd-MMM-yy HH:mm:ss z; HttpOnly
        Cookie cookie = new Cookie("session", "abc123");
        cookie.setPath("/");
        cookie.setHttpOnly(true);
        cookie.setMaxAge(86400);
        resp.addCookie(cookie);
        break;

    case DATEMODE_COOKIE_NOT_TYPICAL:
        // hacked way of building a cookie header, to get less-often-used date format "EEE, dd MMM yy HH:mm:ss z"
        // this results in Set-Cookie: session=abc123; path=/; expires=EEE, dd MMM yy HH:mm:ss z; HttpOnly
        StringBuilder buf = new StringBuilder("session=abc123; path=/; expires=");
        buf.append(DateGenerator.formatDate(System.currentTimeMillis() + 1000L * 60 * 60 * 24));
        buf.append("; HttpOnly");
        resp.addHeader("Set-Cookie", buf.toString());
    }

    resp.sendRedirect(redirect);
}