why i set session attribute value and then i get it is null?

167 views
Skip to first unread message

miwucc

unread,
Dec 26, 2011, 1:55:15 AM12/26/11
to memcached-session-manager
last week,i find memcached-session-manager can help me to store
session in memcached.so i had a try.

i use spring-mvc as my web controler.

when the customer login on the web i did this:

----------------------------------------------------------------------------------------
User loginUser = userService.dealLogin(user);
System.out.println("sessionId: "+request.getSession().getId());
HttpSession session = request.getSession();
session.setAttribute(Constant.CURRENT_USER, loginUser);
System.out.println("user:
"+session.getAttribute(Constant.CURRENT_USER));

---------------------------------------------------------------------------------------------------------------------

from now on,the session is ok and i can get the attirbute
"Constant.CURRENT_USER".

But then i send another request,the request was catched by zhe
springmvc‘s interceptor(i use it for authfilter).

------------------------------------
System.out.println("sessionId: "+sesion.getId());
System.out.println("user:
"+sesion.getAttribute(Constant.CURRENT_USER));
---------------------------------------------------

i get the session and the sessionId equal the first sessionId.

but i get the attribute Constant.CURRENT_USER,it return null ~ !

this is why?somebody who can help me !

Martin Grotzke

unread,
Dec 26, 2011, 2:04:00 AM12/26/11
to memcached-se...@googlegroups.com

Please provide details regarding the configuration. Are there any warnings in the logs? Is the user object serializable?

Cheers,
Martin

miwucc

unread,
Dec 26, 2011, 2:28:19 AM12/26/11
to memcached-session-manager
this is my tomcat option:

in the context.xml is:

<Context>

<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>

<!-- Uncomment this to disable session persistence across Tomcat
restarts -->
<!--
<Manager pathname="" />
-->
<!-- -->
<Manager
className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211"
requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$"
sessionBackupAsync="false"
sticky="true"
sessionBackupTimeout="100"

transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
copyCollectionsForSerialization="false"
/>


<!-- Uncomment this to enable Comet connection tacking (provides
events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve
className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->

</Context>

i did a whalin memcached java client and get the session by sessionId
as key but throwe exception:

58 MemCachedClient mcc = new MemCachedClient();
59 MemcachedItem item = mcc.gets("166066000F3726BC85FFE8426F978AF8-
n1.tomcat1");
60 HttpSession session = (HttpSession)item.getValue();
61 System.out.println("sessionID: "+session.getId());
62 System.out.println("current_user:
"+session.getAttribute("current_user"));


83 [main] ERROR com.danga.MemCached.MemCachedClient - ++++ exception
thrown while trying to get object from cache for key:
166066000F3726BC85FFE8426F978AF8-n1.tomcat1
114 [main] ERROR com.danga.MemCached.MemCachedClient - Value out of
range. Value:"2048" Radix:10
java.lang.NumberFormatException: Value out of range. Value:"2048"
Radix:10
at java.lang.Byte.parseByte(Byte.java:153)
at java.lang.Byte.parseByte(Byte.java:108)
at com.schooner.MemCached.AscIIClient.gets(AscIIClient.java:881)
at com.schooner.MemCached.AscIIClient.gets(AscIIClient.java:638)
at com.schooner.MemCached.AscIIClient.gets(AscIIClient.java:634)
at com.danga.MemCached.MemCachedClient.gets(MemCachedClient.java:
1087)
at Test2.main(Test2.java:59)
Exception in thread "main" java.lang.NullPointerException
at Test2.main(Test2.java:60)











On 12月26日, 下午3时04分, Martin Grotzke <martin.grot...@googlemail.com>
wrote:
> Please provide details regarding the configuration. Are there any warnings
> in the logs? Is the user object serializable?
>
> Cheers,
> Martin
>

miwucc

unread,
Dec 26, 2011, 2:34:47 AM12/26/11
to memcached-session-manager
the jar i set in tomcat's lib folder is :

javolution-5.4.3.1.jar
memcached-2.4.2.jar
msm-javolution-serializer-cglib-1.3.0.jar
msm-javolution-serializer-jodatime-1.3.0.jar
memcached-session-manager-1.3.0.jar


On 12月26日, 下午3时04分, Martin Grotzke <martin.grot...@googlemail.com>
wrote:
> Please provide details regarding the configuration. Are there any warnings
> in the logs? Is the user object serializable?
>
> Cheers,
> Martin
>

miwucc

unread,
Dec 26, 2011, 2:59:05 AM12/26/11
to memcached-session-manager
it is ok now. my use a old config. i read the wiki again and config
is.it works now.thank you very much Martin Grotzke

On 12月26日, 下午3时04分, Martin Grotzke <martin.grot...@googlemail.com>
wrote:
> Please provide details regarding the configuration. Are there any warnings
> in the logs? Is the user object serializable?
>
> Cheers,
> Martin
>

Martin Grotzke

unread,
Dec 26, 2011, 3:19:17 AM12/26/11
to memcached-se...@googlegroups.com

Ok, great it's working for you now.

Btw, you cannot load the session from memcached, only msm can do this as it knows how to deserialize it (no standard object serialization due to some optimizations). So you must only use the servlet api.

Another hint: if you want to get the best performance you should use the kryo transcoder.

Cheers,
Martin

Reply all
Reply to author
Forward
0 new messages