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