Open GoogleCodeExporter opened 9 years ago
i use grails 1.3.7,memcached-2.5.jar,
domain class implements Serializable.
it will show this warn ..
Original comment by young.ji...@gmail.com
on 24 Mar 2011 at 2:12
Hi,
I had this issue in the past and I found a solution. The occurs because the
memcached client it is loaded using a classloader and the serialized object
class is loaded using another classloader. To fix this you must pass to the
memcahed client connector factory a custom transcoder.
public class CustomSerializingTranscoder extends SerializingTranscoder{
@Override
protected Object deserialize(byte[] bytes) {
final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
ObjectInputStream in = null;
try {
ByteArrayInputStream bs = new ByteArrayInputStream(bytes);
in = new ObjectInputStream(bs) {
@Override
protected Class<?> resolveClass(ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException {
try {
return currentClassLoader.loadClass(objectStreamClass.getName());
} catch (Exception e) {
return super.resolveClass(objectStreamClass);
}
}
};
return in.readObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
closeStream(in);
}
}
private static void closeStream(Closeable c) {
if (c != null) {
try {
c.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Original comment by octavr@gmail.com
on 27 Oct 2011 at 8:06
Nope, did not work for me. I changed
Object value = cache.get(key) ;
To
Object value = cache.get(key, SuperCache.customTranscoder) ;
And below is the code for CustomSerializingTranscoder
What am I doing wrong. The exception is crazy, its in completely different part
of the code.
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamClass;
import net.spy.memcached.transcoders.SerializingTranscoder;
public class CustomSerializingTranscoder extends SerializingTranscoder{
@Override
protected Object deserialize(byte[] bytes) {
final ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
ObjectInputStream in = null;
try {
ByteArrayInputStream bs = new ByteArrayInputStream(bytes);
in = new ObjectInputStream(bs) {
@Override
protected Class<ObjectStreamClass> resolveClass(ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException {
try {
return (Class<ObjectStreamClass>) currentClassLoader.loadClass(objectStreamClass.getName());
} catch (Exception e) {
return (Class<ObjectStreamClass>) super.resolveClass(objectStreamClass);
}
}
};
return in.readObject();
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
closeStream(in);
}
}
private static void closeStream(Closeable c) {
if (c != null) {
try {
c.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Original comment by mcon...@gmail.com
on 30 Nov 2011 at 5:44
I had the same issue on Glassfish 2.1
and the comment 2 worked like a charm!
Thank you
Original comment by simao...@gmail.com
on 11 Jan 2013 at 3:31
To save you some time searching about how you will apply the custom class in
comment # 2 ... here's some sample code which shows that you can just add
.setTranscoder(new CustomSerializingTranscoder())
when you're building the client:
MemcachedClient mc =
new MemcachedClient(
new ConnectionFactoryBuilder()
.setTranscoder(new CustomSerializingTranscoder()) // use this line
.setProtocol(ConnectionFactoryBuilder.Protocol.BINARY)
...
Original comment by pulkitsi...@gmail.com
on 5 Feb 2013 at 10:05
[deleted comment]
If you are using spymemcached alone (without MSM), just place the
spymemcached.jar in the WEB-INF/lib folder inside your webapp, and not in
/$CATALINA_HOME/lib/ and it will be fine.
Solution 2 + 5 works, but if possible just moving the jar is preferable.
Original comment by tomcat.r...@gmail.com
on 28 Aug 2013 at 8:17
#2 worked for me!
Original comment by thysmich...@gmail.com
on 1 Mar 2014 at 4:22
#2 answer is correct. I fix this bug follow his instruction. Thank you very
much~^0^~
Original comment by davidjef...@gmail.com
on 17 Apr 2014 at 3:46
i had the same issue and comment #7 worked for me Thanks
Original comment by dj8ap...@gmail.com
on 31 Aug 2014 at 7:28
Nope, didn't work for me. I use 1 memcached with multi project
Original comment by ntric...@gmail.com
on 9 Oct 2014 at 4:04
Original issue reported on code.google.com by
taowend...@gmail.com
on 9 Oct 2010 at 1:46