Class SafeSessionManager


  • public class SafeSessionManager
    extends Object
    This class allows handling a session safely against the different request calls.

    Some synchronized access are performed around session creation and session attribute accesses.

    Author:
    silveryocha
    • Constructor Detail

      • SafeSessionManager

        public SafeSessionManager​(javax.servlet.http.HttpServletRequest request)
    • Method Detail

      • getAttribute

        public <T> T getAttribute​(String attributeName,
                                  Class<T> aClass)
        Gets the specified attribute value from the session.

        If the session does not exists, it is not created.

        If no value exists, null is returned.

        Type Parameters:
        T - the type of the value.
        Parameters:
        attributeName - the name of the attribute to fetch.
        aClass - the class of the value fetched.
        Returns:
        the value if any, null otherwise.
      • getAttribute

        public <T> T getAttribute​(String attributeName,
                                  Class<T> aClass,
                                  T defaultValue)
        Gets the specified attribute value from the session.

        If the session does not exists, it is not created.

        If no value exists, default one is returned.

        Type Parameters:
        T - the type of the value.
        Parameters:
        attributeName - the name of the attribute to fetch.
        aClass - the class of the value fetched.
        defaultValue - default value of no value fetched from session.
        Returns:
        the value if any, default value otherwise.
      • setAttribute

        public <T> void setAttribute​(String attributeName,
                                     T value)
        Sets the specified attribute value into the session.

        If the session does not exist, it is created.

        Type Parameters:
        T - the type of the value.
        Parameters:
        attributeName - the name of the attribute to fetch.
        value - the value to put.
      • removeAttribute

        public <T> T removeAttribute​(String attributeName,
                                     Class<T> aClass)
        Removes from the session the specified attribute.

        If the session does not exist, nothing is performed.

        Type Parameters:
        T - the type of the value.
        Parameters:
        attributeName - the name of the attribute to fetch.
        aClass - the class of the value fetched.
        Returns:
        the removed value if any, null otherwise.