Hi All,
We have a Rest API Integration with AEM and Before Hitting the actual API we hit a API which generates a Token and Token needs to be passed to actual API to get the Response.
So first time once API is hit to get the token ,token is valid for 10 minutes so within 10 min same token should be used for all the API's and should be saved Server Side.
What is the best way to store the Token in AEM at server Side.
Do we need to use any Java Cache like (Ehcache) or what is the correct approach to handle such sceanrios.
Thanks in Advance.
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Sb2512 ,
I would use JavaBean which adhere to an extremely simple coding convention to cache response.
public interface Response { String getToken(); }Implementation
public class TokenResponse implements Response { public String getToken() { if (null != this.getToken) { return this.getToken(); } return null; } }Invoking
TokenResponse tokenResponse = callYourHttpAPI(); if (null ! = tokenResponse { //Do Something (Call to 2nd API by passing tokenResponse as a param) .......... }
Hope that helps!
Regards,
Santosh
Hi
You can use in memory cache or jcr node to store but if you have multiple instance, in that case the storage will not guaranty that the token will be available.
but if you just want to improve this in term of performance then yes, you can use in memory cache.
Hi Arun,
Thanks for the reply...
If there are multiple publish instance how the token will be synced....
Any thoughts @arunpatidar
Hi @Sb2512 ,
I would use JavaBean which adhere to an extremely simple coding convention to cache response.
public interface Response { String getToken(); }Implementation
public class TokenResponse implements Response { public String getToken() { if (null != this.getToken) { return this.getToken(); } return null; } }Invoking
TokenResponse tokenResponse = callYourHttpAPI(); if (null ! = tokenResponse { //Do Something (Call to 2nd API by passing tokenResponse as a param) .......... }
Hope that helps!
Regards,
Santosh
Views
Likes
Replies
Views
Like
Replies