@Override public void setAttribute(String name, Object value, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot set request attribute - request is not active anymore!"); } this.request.setAttribute(name, value); } else { HttpSession session = obtainSession(); this.sessionAttributesToUpdate.remove(name); session.setAttribute(name, value); } }
/** * Exposes the {@link HttpSession} that we're wrapping. * @param allowCreate whether to allow creation of a new session if none exists yet */ @Nullable protected final HttpSession getSession(boolean allowCreate) { if (isRequestActive()) { HttpSession session = this.request.getSession(allowCreate); this.session = session; return session; } else { // Access through stored session reference, if any... HttpSession session = this.session; if (session == null) { if (allowCreate) { throw new IllegalStateException( "No session found and request already completed - cannot create new session!"); } else { session = this.request.getSession(false); this.session = session; } } return session; } }
@Override public Object getAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attribute - request is not active anymore!"); } return this.request.getAttribute(name); } else { HttpSession session = getSession(false); if (session != null) { try { Object value = session.getAttribute(name); if (value != null) { this.sessionAttributesToUpdate.put(name, value); } return value; } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return null; } }
@Override public void removeAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (isRequestActive()) { this.request.removeAttribute(name); removeRequestDestructionCallback(name); } } else { HttpSession session = getSession(false); if (session != null) { this.sessionAttributesToUpdate.remove(name); try { session.removeAttribute(name); // Remove any registered destruction callback as well. session.removeAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } } }
@Override public void setAttribute(String name, Object value, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot set request attribute - request is not active anymore!"); } this.request.setAttribute(name, value); } else { HttpSession session = obtainSession(); this.sessionAttributesToUpdate.remove(name); session.setAttribute(name, value); } }
/** * Exposes the {@link HttpSession} that we're wrapping. * @param allowCreate whether to allow creation of a new session if none exists yet */ @Nullable protected final HttpSession getSession(boolean allowCreate) { if (isRequestActive()) { HttpSession session = this.request.getSession(allowCreate); this.session = session; return session; } else { // Access through stored session reference, if any... HttpSession session = this.session; if (session == null) { if (allowCreate) { throw new IllegalStateException( "No session found and request already completed - cannot create new session!"); } else { session = this.request.getSession(false); this.session = session; } } return session; } }
@Override public String[] getAttributeNames(int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attributes - request is not active anymore!"); } return StringUtils.toStringArray(this.request.getAttributeNames()); } else { HttpSession session = getSession(false); if (session != null) { try { return StringUtils.toStringArray(session.getAttributeNames()); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return new String[0]; } }
@Override public Object getAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attribute - request is not active anymore!"); } return this.request.getAttribute(name); } else { HttpSession session = getSession(false); if (session != null) { try { Object value = session.getAttribute(name); if (value != null) { this.sessionAttributesToUpdate.put(name, value); } return value; } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return null; } }
@Override public void removeAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (isRequestActive()) { this.request.removeAttribute(name); removeRequestDestructionCallback(name); } } else { HttpSession session = getSession(false); if (session != null) { this.sessionAttributesToUpdate.remove(name); try { session.removeAttribute(name); // Remove any registered destruction callback as well. session.removeAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } } }
@Override public String[] getAttributeNames(int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attributes - request is not active anymore!"); } return StringUtils.toStringArray(this.request.getAttributeNames()); } else { HttpSession session = getSession(false); if (session != null) { try { return StringUtils.toStringArray(session.getAttributeNames()); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return new String[0]; } }
@Override public void setAttribute(String name, Object value, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot set request attribute - request is not active anymore!"); } this.request.setAttribute(name, value); } else { HttpSession session = obtainSession(); this.sessionAttributesToUpdate.remove(name); session.setAttribute(name, value); } }
@Override public void setAttribute(String name, Object value, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot set request attribute - request is not active anymore!"); } this.request.setAttribute(name, value); } else { HttpSession session = obtainSession(); this.sessionAttributesToUpdate.remove(name); session.setAttribute(name, value); } }
/** * Exposes the {@link HttpSession} that we're wrapping. * @param allowCreate whether to allow creation of a new session if none exists yet */ @Nullable protected final HttpSession getSession(boolean allowCreate) { if (isRequestActive()) { HttpSession session = this.request.getSession(allowCreate); this.session = session; return session; } else { // Access through stored session reference, if any... HttpSession session = this.session; if (session == null) { if (allowCreate) { throw new IllegalStateException( "No session found and request already completed - cannot create new session!"); } else { session = this.request.getSession(false); this.session = session; } } return session; } }
/** * Exposes the {@link HttpSession} that we're wrapping. * @param allowCreate whether to allow creation of a new session if none exists yet */ @Nullable protected final HttpSession getSession(boolean allowCreate) { if (isRequestActive()) { HttpSession session = this.request.getSession(allowCreate); this.session = session; return session; } else { // Access through stored session reference, if any... HttpSession session = this.session; if (session == null) { if (allowCreate) { throw new IllegalStateException( "No session found and request already completed - cannot create new session!"); } else { session = this.request.getSession(false); this.session = session; } } return session; } }
@Override public Object getAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attribute - request is not active anymore!"); } return this.request.getAttribute(name); } else { HttpSession session = getSession(false); if (session != null) { try { Object value = session.getAttribute(name); if (value != null) { this.sessionAttributesToUpdate.put(name, value); } return value; } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return null; } }
@Override public Object getAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attribute - request is not active anymore!"); } return this.request.getAttribute(name); } else { HttpSession session = getSession(false); if (session != null) { try { Object value = session.getAttribute(name); if (value != null) { this.sessionAttributesToUpdate.put(name, value); } return value; } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return null; } }
@Override public void removeAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (isRequestActive()) { this.request.removeAttribute(name); removeRequestDestructionCallback(name); } } else { HttpSession session = getSession(false); if (session != null) { this.sessionAttributesToUpdate.remove(name); try { session.removeAttribute(name); // Remove any registered destruction callback as well. session.removeAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } } }
@Override public void removeAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (isRequestActive()) { this.request.removeAttribute(name); removeRequestDestructionCallback(name); } } else { HttpSession session = getSession(false); if (session != null) { this.sessionAttributesToUpdate.remove(name); try { session.removeAttribute(name); // Remove any registered destruction callback as well. session.removeAttribute(DESTRUCTION_CALLBACK_NAME_PREFIX + name); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } } }
@Override public String[] getAttributeNames(int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attributes - request is not active anymore!"); } return StringUtils.toStringArray(this.request.getAttributeNames()); } else { HttpSession session = getSession(false); if (session != null) { try { return StringUtils.toStringArray(session.getAttributeNames()); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return new String[0]; } }
@Override public String[] getAttributeNames(int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( "Cannot ask for request attributes - request is not active anymore!"); } return StringUtils.toStringArray(this.request.getAttributeNames()); } else { HttpSession session = getSession(false); if (session != null) { try { return StringUtils.toStringArray(session.getAttributeNames()); } catch (IllegalStateException ex) { // Session invalidated - shouldn't usually happen. } } return new String[0]; } }