AmadeusITGroup / HttpSessionReplacer

Store JEE Servlet HttpSessions in Redis
MIT License
49 stars 33 forks source link

HttpServletRequest.getSession() always return a new session #43

Open vlcheong opened 6 years ago

vlcheong commented 6 years ago

I'm testing HttpSessionReplacer using a simple webapp. My problem is the HttpSession seems return a new session whenever I post a request to the Servlet, all my previous data was removed. The webapp work as expected without HttpSessionReplacer. Am I missing something in the config ?

Servlet 3.0.1 Tomcat7 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot; version="3.0">

<!--distributable/-->

<context-param>
    <param-name>com.amadeus.session.id</param-name>
    <param-value>uuid</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.noHyphensInId</param-name>
    <param-value>true</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.namespace</param-name>
    <param-value>test</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.timeout</param-name>
    <param-value>1800</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.sticky</param-name>
    <param-value>false</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.debug</param-name>
    <param-value>false</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.distributable.force</param-name>
    <param-value>true</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.distributable</param-name>
    <param-value>true</param-value>
</context-param>

<!-- Redis server -->
<context-param>
    <param-name>com.amadeus.session.repository.factory</param-name>
    <param-value>redis</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.redis.mode</param-name>
    <param-value>SINGLE</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.redis.host</param-name>
    <param-value>localhost</param-value>
</context-param>

<context-param>
    <param-name>com.amadeus.session.redis.port</param-name>
    <param-value>6379</param-value>
</context-param>

<!-- Expiration startegy -->
<context-param>
    <param-name>com.amadeus.session.redis.expiration</param-name>
    <param-value>ZRANGE</param-value>
</context-param>

<jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <trim-directive-whitespaces>true</trim-directive-whitespaces>
    </jsp-property-group>
</jsp-config>

<session-config>
    <session-timeout>30</session-timeout>
    <cookie-config>
        <!--<secure>true</secure>-->
        <http-only>false</http-only>
    </cookie-config>
    <tracking-mode>COOKIE</tracking-mode>
</session-config>

<!--<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>-->

</web-app>

nbogojevic commented 6 years ago

Hi vlcheong,

Do you have an example of your Servlet code and of the HTTP requests and responses your are sending?

AntonPotapenko commented 4 years ago

Seems like container and Replacer uses the same cookie name "JSESSIONID". Setting com.amadeus.session.sessionName prop could help.