Search in sources :

Example 6 with SessionWrapper

use of org.exist.http.servlets.SessionWrapper in project exist by eXist-db.

the class SessionFunction method getOrCreateSession.

private static SessionWrapper getOrCreateSession(final Expression expr, final XQueryContext context, final Optional<SessionWrapper> session, final boolean sessionMustBeValid) throws XPathException {
    if (session.isPresent()) {
        final SessionWrapper existingSession = session.get();
        if (sessionMustBeValid) {
            if (existingSession.isInvalid()) {
                LOG.warn("Existing HTTP Session was invalid, creating a new HTTP Session");
            } else {
                return existingSession;
            }
        } else {
            return existingSession;
        }
    }
    final RequestWrapper request = Optional.ofNullable(context.getHttpContext()).map(XQueryContext.HttpContext::getRequest).orElseThrow(() -> new XPathException(expr, ErrorCodes.XPDY0002, "No request object found in the current XQuery context."));
    final SessionWrapper newSession = request.getSession(true);
    context.setHttpContext(context.getHttpContext().setSession(newSession));
    return newSession;
}
Also used : RequestWrapper(org.exist.http.servlets.RequestWrapper) SessionWrapper(org.exist.http.servlets.SessionWrapper)

Aggregations

SessionWrapper (org.exist.http.servlets.SessionWrapper)6 RequestWrapper (org.exist.http.servlets.RequestWrapper)2 StringValue (org.exist.xquery.value.StringValue)2 Enumeration (java.util.Enumeration)1 AuthenticationException (org.exist.security.AuthenticationException)1 SecurityManager (org.exist.security.SecurityManager)1 Subject (org.exist.security.Subject)1 IntegerValue (org.exist.xquery.value.IntegerValue)1 Sequence (org.exist.xquery.value.Sequence)1 ValueSequence (org.exist.xquery.value.ValueSequence)1