Class DefaultIdempotentService
java.lang.Object
io.microsphere.spring.web.idempotent.DefaultIdempotentService
- All Implemented Interfaces:
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:
-
IdempotentServiceConcurrentReferenceHashMapConcurrentReferenceHashMap.ReferenceType.WEAK
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, String token) Check the token is existedvoiddestroy()DestroygenerateToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes) Generate a new token.getToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes) Get the token from the request.booleaninvalidate(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, String token) Invalidate the tokenbooleanstoreToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, 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, waitMethods inherited from interface io.microsphere.spring.web.idempotent.IdempotentService
renewToken, validateToken
-
Constructor Details
-
DefaultIdempotentService
public DefaultIdempotentService()
-
-
Method Details
-
generateToken
public String generateToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes) Description copied from interface:IdempotentServiceGenerate a new token.Note : The new token should not be generated twice in one request.
- Specified by:
generateTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributes- Returns:
- the new token
-
getToken
public String getToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes) Description copied from interface:IdempotentServiceGet the token from the request.- Specified by:
getTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributes- Returns:
- the token from the request if exists
-
checkToken
public boolean checkToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, String token) Description copied from interface:IdempotentServiceCheck the token is existed- Specified by:
checkTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributestoken- the token- Returns:
trueif exists
-
invalidate
public boolean invalidate(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, String token) Description copied from interface:IdempotentServiceInvalidate the token- Specified by:
invalidatein interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributestoken- the token- Returns:
trueif invalidated successfully
-
storeToken
public boolean storeToken(org.springframework.web.context.request.NativeWebRequest request, IdempotentAttributes attributes, String newToken) Description copied from interface:IdempotentServiceStore the token into backend storage.- Specified by:
storeTokenin interfaceIdempotentService- Parameters:
request- theNativeWebRequestattributes- theIdempotentAttributesnewToken- the new generated token- Returns:
trueif stored successfully
-
destroy
public void destroy()Description copied from interface:IdempotentServiceDestroy- Specified by:
destroyin interfaceIdempotentService
-