so I have a javax.servlet.filter class that does a lot of things. one of the first things it does is change the value of a cookie (example: cookieX was originally set to "ABC" and I changed it to "ABC,DEF").
Before the browser gets a response (the filter has completed already but a Sling model is running this time), another piece of code retrieves the value of cookieX and checks if "DEF" is in the cookie. When the cookie is retrieve via the request object, I still see the original value (which is "ABC") and not the new one.
Thank you.
Solved! Go to Solution.
Hi @jayv25585659,
It depends on why you need the updated cookie during the same request:
Store the updated value in a request attribute
After you update the cookie on the response, also do:
Then, in your Sling Model (or later code in the same request), check the attribute first, falling back to request.getCookies() if it’s not present.
Wrap the request
You can implement a HttpServletRequestWrapper inside your Filter that overrides getCookies() (or getHeader("Cookie")) to return the updated value. Then pass this wrapped request down the chain:
This way, downstream code sees the updated cookie value.
Avoid relying on cookies within the same request
If the “DEF” flag is needed only for server-side flow control, you might skip cookies altogether and rely on request attributes, thread-locals, or another context mechanism. Cookies are meant for persisting state between requests, not within one.
Hi @jayv25585659,
It depends on why you need the updated cookie during the same request:
Store the updated value in a request attribute
After you update the cookie on the response, also do:
Then, in your Sling Model (or later code in the same request), check the attribute first, falling back to request.getCookies() if it’s not present.
Wrap the request
You can implement a HttpServletRequestWrapper inside your Filter that overrides getCookies() (or getHeader("Cookie")) to return the updated value. Then pass this wrapped request down the chain:
This way, downstream code sees the updated cookie value.
Avoid relying on cookies within the same request
If the “DEF” flag is needed only for server-side flow control, you might skip cookies altogether and rely on request attributes, thread-locals, or another context mechanism. Cookies are meant for persisting state between requests, not within one.
question please. do you know if option1 persist across multiple publishers where sticky sessions is not set/disabled?
Views
Replies
Total Likes
Views
Replies
Total Likes
Cara reschedule Batik Air
_
Cs batik air Telepon 081944399827
Views
Replies
Total Likes
Cara reschedule Air Asia
_
Telepon cs Air Asia (+62081944399827)
Views
Replies
Total Likes
Cara reschedule Lion air
_
Cs lion air Telepon 0819.4439.827
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies