Class DefaultIdempotentService

  • All Implemented Interfaces:
    IdempotentService

    public class DefaultIdempotentService
    extends java.lang.Object
    implements IdempotentService
    The default IdempotentService implementation which uses a weak reference ConcurrentReferenceHashMap to store the new generated token and session context to check the duplicated request with same token.
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    IdempotentService, ConcurrentReferenceHashMap, ConcurrentReferenceHashMap.ReferenceType.WEAK
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean checkToken​(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String token)
      Check the token is existed
      void destroy()
      Destroy
      java.lang.String generateToken​(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes)
      Generate a new token.
      java.lang.String getToken​(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes)
      Get the token from the request.
      boolean invalidate​(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String token)
      Invalidate the token
      boolean storeToken​(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, java.lang.String newToken)
      Store the token into backend storage.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultIdempotentService

        public DefaultIdempotentService()
    • Method Detail

      • generateToken

        public java.lang.String generateToken​(org.springframework.web.context.request.NativeWebRequest request,
                                              IdempotentAttributes attributes)
        Description copied from interface: IdempotentService
        Generate a new token.

        Note : The new token should not be generated twice in one request.

        Specified by:
        generateToken in interface IdempotentService
        Parameters:
        request - the NativeWebRequest
        attributes - the IdempotentAttributes
        Returns:
        the new token
      • getToken

        public java.lang.String getToken​(org.springframework.web.context.request.NativeWebRequest request,
                                         IdempotentAttributes attributes)
        Description copied from interface: IdempotentService
        Get the token from the request.
        Specified by:
        getToken in interface IdempotentService
        Parameters:
        request - the NativeWebRequest
        attributes - the IdempotentAttributes
        Returns:
        the token from the request if exists
      • checkToken

        public boolean checkToken​(org.springframework.web.context.request.NativeWebRequest request,
                                  IdempotentAttributes attributes,
                                  java.lang.String token)
        Description copied from interface: IdempotentService
        Check the token is existed
        Specified by:
        checkToken in interface IdempotentService
        Parameters:
        request - the NativeWebRequest
        attributes - the IdempotentAttributes
        token - the token
        Returns:
        true if exists
      • invalidate

        public boolean invalidate​(org.springframework.web.context.request.NativeWebRequest request,
                                  IdempotentAttributes attributes,
                                  java.lang.String token)
        Description copied from interface: IdempotentService
        Invalidate the token
        Specified by:
        invalidate in interface IdempotentService
        Parameters:
        request - the NativeWebRequest
        attributes - the IdempotentAttributes
        token - the token
        Returns:
        true if invalidated successfully
      • storeToken

        public boolean storeToken​(org.springframework.web.context.request.NativeWebRequest request,
                                  IdempotentAttributes attributes,
                                  java.lang.String newToken)
        Description copied from interface: IdempotentService
        Store the token into backend storage.
        Specified by:
        storeToken in interface IdempotentService
        Parameters:
        request - the NativeWebRequest
        attributes - the IdempotentAttributes
        newToken - the new generated token
        Returns:
        true if stored successfully