Search in sources :

Example 1 with Cookie

use of org.glassfish.grizzly.http.Cookie in project Payara by payara.

the class ApplicationPushBuilder method push.

@Override
public void push() {
    if (path == null) {
        throw new IllegalStateException(rb.getString(LogFacade.NO_PUSH_PATH_EXCEPTION));
    }
    Http2Stream http2Stream = (Http2Stream) coyoteRequest.getAttribute(Http2Stream.HTTP2_STREAM_ATTRIBUTE);
    if (http2Stream == null || !http2Stream.isPushEnabled()) {
        return;
    }
    // modify pathLocal rather than path
    String pathLocal = ((path.charAt(0) == '/') ? path : coyoteRequest.getContextPath() + '/' + path);
    if (queryString != null) {
        pathLocal += ((pathLocal.indexOf('?') != -1) ? '&' + queryString : '?' + queryString);
    }
    // Session ID (do this before setting the path since it may change it)
    if (sessionId != null) {
        if (addSessionPathParameter) {
            pathLocal = pathLocal + ";" + sessionCookieName + "=" + sessionId;
        }
        if (addSessionCookie) {
            cookies.add(new Cookie(sessionCookieName, sessionId));
        }
    }
    PushEvent.PushEventBuilder pushEventBuilder = PushEvent.builder();
    pushEventBuilder.method(method);
    pushEventBuilder.headers(headers);
    pushEventBuilder.path(pathLocal);
    pushEventBuilder.httpRequest(coyoteRequest.getRequest());
    coyoteRequest.getContext().notifyDownstream(pushEventBuilder.build());
    // Reset for next call
    path = null;
    for (Header conditionalHeader : CONDITIONAL_HEADERS) {
        headers.removeHeader(conditionalHeader);
    }
}
Also used : Cookie(org.glassfish.grizzly.http.Cookie) PushEvent(org.glassfish.grizzly.http.server.http2.PushEvent) Header(org.glassfish.grizzly.http.util.Header) Http2Stream(org.glassfish.grizzly.http2.Http2Stream)

Example 2 with Cookie

use of org.glassfish.grizzly.http.Cookie in project Payara by payara.

the class AdminCallbackHandler method restToken.

private String restToken() {
    final Cookie[] cookies = request.getCookies();
    String result = null;
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if (COOKIE_REST_TOKEN.equals(cookie.getName())) {
                result = cookie.getValue();
            }
        }
    }
    if (result == null) {
        result = request.getHeader(HEADER_X_AUTH_TOKEN);
    }
    return result;
}
Also used : Cookie(org.glassfish.grizzly.http.Cookie)

Example 3 with Cookie

use of org.glassfish.grizzly.http.Cookie in project Payara by payara.

the class AdminAdapter method getCookieHeader.

/**
 * This will create a unique SessionId, Max-Age,Version,Path to be added to the Set-Cookie header
 * @return Set-Cookie2 header
 */
public String getCookieHeader(Request req) {
    String sessionId = null;
    // JSESSIONID in  Set-Cookie2 header
    if (hasCookieHeader(req)) {
        sessionId = getJSESSIONIDHeaders(req)[1];
    } else {
        // There is no Cookie header in request so generate a new JSESSIONID  or
        // failover has occured in which case you can generate a new JSESSIONID
        sessionId = createSessionId();
    }
    StringBuilder sb = new StringBuilder();
    final Cookie cookie = new Cookie(SESSION_COOKIE_NAME, sessionId);
    cookie.setMaxAge(MAX_AGE);
    cookie.setPath(ASADMIN_PATH);
    cookie.setVersion(1);
    CookieSerializerUtils.serializeServerCookie(sb, true, false, false, cookie);
    return sb.toString();
}
Also used : Cookie(org.glassfish.grizzly.http.Cookie)

Aggregations

Cookie (org.glassfish.grizzly.http.Cookie)3 PushEvent (org.glassfish.grizzly.http.server.http2.PushEvent)1 Header (org.glassfish.grizzly.http.util.Header)1 Http2Stream (org.glassfish.grizzly.http2.Http2Stream)1