RedisHttpSession | HttpSession base on Redis , support RESTful API | REST library
kandi X-RAY | RedisHttpSession Summary
kandi X-RAY | RedisHttpSession Summary
RedisHttpSession provides an way to transparently store http session in redis, which allows multi-clients to share the sessions.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Invokes redis HTTP session
- Get the Redis connection
- Get the max inactive interval
- Check redis connection if available
- Gets a session by token
- Create a RedisHttpSession with the given token
- Gets the scheduler pool configuration
- Gets the connection config
- Add user
- Decode a string
- Check if the connection is connected
- Log out
- Close all connections
- Return all the Hkeys with the given key
- Set an object in the hash table
- Get the value of a key with the specified fields
- Expire a key
- Process Redis session
- Get the value of a field
- Create a new Redis session
- Creates a Redis configuration object
- Saves session
- Encode the given object to a string
- Handles a POST request
- Login
- Get the name of a session
RedisHttpSession Key Features
RedisHttpSession Examples and Code Snippets
Community Discussions
Trending Discussions on RedisHttpSession
QUESTION
I'm trying to implement Spring redis session in an existing Spring MVC (ver 5.1.6) application. In web.xml we have ContextLoaderListener, DispatcherServlet and contextConfigLocation are all defined.
After required dependencies are included and suggested code changes are done, i'm getting below error:
Caused by: java.lang.IllegalStateException: Cannot initialize context because there is already a root application context present - check whether you have multiple ContextLoader definitions in your web.xml!"}}*
As part of code changes i'm extending the class "AbstractHttpSessionApplicationInitializer",(from Spring session core library) which internally implements WebApplicationInitializer. Seems like that is trying to create another context and throwing the above error. We cannot avoid extending this class, as this does the job of registering redisHttpSession to context.
Most of the examples available are all with spring boot. So there they wouldn't have faced this issue.
Any solution, other than completely replacing web.xml and use only WebApplicationInitializer?
...ANSWER
Answered 2021-Mar-07 at 11:49Just want to provide an update. Instead of extending AbstractHttpSessionApplicationInitializer abtract class, i have taken a different approach by initializing bean RedisHttpSessionConfiguration thru XML bean definition.
This approach worked.
Followed the steps mentioned in the below thread; How to configure Spring sessions to work with Redis in xml?
Along with that we need to serialize the cookie as well;
QUESTION
So I'm basically using RedisHttpSession
for session management. I've created this login API which stores the Staff
object in the session when the login is successful. request.getSession().setAttribute("staff", staff);
And in other APIs, I verify if a valid staff is logged in and if not I redirect them to the login page. Staff staff = (Staff) request.getSession().getAttribute("staff");
Now when I tested this whole scenario with Postman, it worked as expected but, I staged it on the server, and request.getSession().getId()
is different in each request.
The other thing that I noticed was that when I was sending requests from Postman, I saw cookies being stored but there were no cookies on the browser.
Why is the sessionId different in each request? How do I solve this issue?
...ANSWER
Answered 2021-Jan-19 at 06:06HttpSession
was creating a new SessionId every time because the cookie wasn't being stored in the browser. And to handle that, I created a new @Configuration
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install RedisHttpSession
You can use RedisHttpSession like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the RedisHttpSession component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page