[370377] add classloadingobjectinputstream to mongodb session manager, contribution by david, thanks much
This commit is contained in:
parent
33a73c69fd
commit
b665beeb64
|
@ -115,8 +115,6 @@ public class MongoSessionManager extends NoSqlSessionManager
|
||||||
{
|
{
|
||||||
__log.debug("MongoSessionManager:save:" + session);
|
__log.debug("MongoSessionManager:save:" + session);
|
||||||
session.willPassivate();
|
session.willPassivate();
|
||||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
|
||||||
ObjectOutputStream out = new ObjectOutputStream(bout);
|
|
||||||
|
|
||||||
// Form query for upsert
|
// Form query for upsert
|
||||||
BasicDBObject key = new BasicDBObject(__ID,session.getClusterId());
|
BasicDBObject key = new BasicDBObject(__ID,session.getClusterId());
|
||||||
|
@ -159,7 +157,7 @@ public class MongoSessionManager extends NoSqlSessionManager
|
||||||
if (value == null)
|
if (value == null)
|
||||||
unsets.put(getContextKey() + "." + encodeName(name),1);
|
unsets.put(getContextKey() + "." + encodeName(name),1);
|
||||||
else
|
else
|
||||||
sets.put(getContextKey() + "." + encodeName(name),encodeName(out,bout,value));
|
sets.put(getContextKey() + "." + encodeName(name),encodeName(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -403,7 +401,7 @@ public class MongoSessionManager extends NoSqlSessionManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------ */
|
/*------------------------------------------------------------ */
|
||||||
protected Object encodeName(ObjectOutputStream out, ByteArrayOutputStream bout, Object value) throws IOException
|
protected Object encodeName(Object value) throws IOException
|
||||||
{
|
{
|
||||||
if (value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof Date)
|
if (value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof Date)
|
||||||
{
|
{
|
||||||
|
@ -419,13 +417,15 @@ public class MongoSessionManager extends NoSqlSessionManager
|
||||||
o = null;
|
o = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
o.append(encodeName(entry.getKey().toString()),encodeName(out,bout,entry.getValue()));
|
o.append(encodeName(entry.getKey().toString()),encodeName(entry.getValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o != null)
|
if (o != null)
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
|
ObjectOutputStream out = new ObjectOutputStream(bout);
|
||||||
out.reset();
|
out.reset();
|
||||||
out.writeUnshared(value);
|
out.writeUnshared(value);
|
||||||
out.flush();
|
out.flush();
|
||||||
|
@ -433,30 +433,32 @@ public class MongoSessionManager extends NoSqlSessionManager
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------------------------------------------------------------ */
|
/*------------------------------------------------------------ */
|
||||||
protected Object decodeValue(Object value) throws IOException, ClassNotFoundException
|
protected Object decodeValue(final Object valueToDecode) throws IOException, ClassNotFoundException
|
||||||
{
|
{
|
||||||
if (value == null || value instanceof Number || value instanceof String || value instanceof Boolean || value instanceof Date)
|
if (valueToDecode == null || valueToDecode instanceof Number || valueToDecode instanceof String || valueToDecode instanceof Boolean || valueToDecode instanceof Date)
|
||||||
{
|
{
|
||||||
return value;
|
return valueToDecode;
|
||||||
}
|
}
|
||||||
else if (value instanceof byte[])
|
else if (valueToDecode instanceof byte[])
|
||||||
{
|
{
|
||||||
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream((byte[])value));
|
final byte[] decodeObject = (byte[])valueToDecode;
|
||||||
return in.readObject();
|
final ByteArrayInputStream bais = new ByteArrayInputStream(decodeObject);
|
||||||
|
final ClassLoadingObjectInputStream objectInputStream = new ClassLoadingObjectInputStream(bais);
|
||||||
|
return objectInputStream.readUnshared();
|
||||||
}
|
}
|
||||||
else if (value instanceof DBObject)
|
else if (valueToDecode instanceof DBObject)
|
||||||
{
|
{
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
for (String name : ((DBObject)value).keySet())
|
for (String name : ((DBObject)valueToDecode).keySet())
|
||||||
{
|
{
|
||||||
String attr = decodeName(name);
|
String attr = decodeName(name);
|
||||||
map.put(attr,decodeValue(((DBObject)value).get(name)));
|
map.put(attr,decodeValue(((DBObject)valueToDecode).get(name)));
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(value.getClass().toString());
|
throw new IllegalStateException(valueToDecode.getClass().toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -546,4 +548,36 @@ public class MongoSessionManager extends NoSqlSessionManager
|
||||||
return temp.get(keyChain[keyChain.length - 1]);
|
return temp.get(keyChain[keyChain.length - 1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ClassLoadingObjectInputStream
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected class ClassLoadingObjectInputStream extends ObjectInputStream
|
||||||
|
{
|
||||||
|
public ClassLoadingObjectInputStream(java.io.InputStream in) throws IOException
|
||||||
|
{
|
||||||
|
super(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassLoadingObjectInputStream () throws IOException
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class<?> resolveClass (java.io.ObjectStreamClass cl) throws IOException, ClassNotFoundException
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Class.forName(cl.getName(), false, Thread.currentThread().getContextClassLoader());
|
||||||
|
}
|
||||||
|
catch (ClassNotFoundException e)
|
||||||
|
{
|
||||||
|
return super.resolveClass(cl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue