use of org.eclipse.jetty.util.ClassLoadingObjectInputStream in project jetty.project by eclipse.
the class JDBCSessionDataStore method load.
/**
* @see org.eclipse.jetty.server.session.SessionDataStore#load(java.lang.String)
*/
@Override
public SessionData load(String id) throws Exception {
final AtomicReference<SessionData> reference = new AtomicReference<SessionData>();
final AtomicReference<Exception> exception = new AtomicReference<Exception>();
Runnable r = new Runnable() {
public void run() {
try (Connection connection = _dbAdaptor.getConnection();
PreparedStatement statement = _sessionTableSchema.getLoadStatement(connection, id, _context);
ResultSet result = statement.executeQuery()) {
SessionData data = null;
if (result.next()) {
data = newSessionData(id, result.getLong(_sessionTableSchema.getCreateTimeColumn()), result.getLong(_sessionTableSchema.getAccessTimeColumn()), result.getLong(_sessionTableSchema.getLastAccessTimeColumn()), result.getLong(_sessionTableSchema.getMaxIntervalColumn()));
data.setCookieSet(result.getLong(_sessionTableSchema.getCookieTimeColumn()));
data.setLastNode(result.getString(_sessionTableSchema.getLastNodeColumn()));
data.setLastSaved(result.getLong(_sessionTableSchema.getLastSavedTimeColumn()));
data.setExpiry(result.getLong(_sessionTableSchema.getExpiryTimeColumn()));
//TODO needed? this is part of the key now
data.setContextPath(result.getString(_sessionTableSchema.getContextPathColumn()));
//TODO needed??? this is part of the key now
data.setVhost(result.getString(_sessionTableSchema.getVirtualHostColumn()));
try (InputStream is = _dbAdaptor.getBlobInputStream(result, _sessionTableSchema.getMapColumn());
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(is)) {
Object o = ois.readObject();
data.putAllAttributes((Map<String, Object>) o);
} catch (Exception e) {
throw new UnreadableSessionDataException(id, _context, e);
}
if (LOG.isDebugEnabled())
LOG.debug("LOADED session {}", data);
} else if (LOG.isDebugEnabled())
LOG.debug("No session {}", id);
reference.set(data);
} catch (Exception e) {
exception.set(e);
}
}
};
//ensure this runs with context classloader set
_context.run(r);
if (exception.get() != null)
throw exception.get();
return reference.get();
}
use of org.eclipse.jetty.util.ClassLoadingObjectInputStream in project jetty.project by eclipse.
the class FileSessionDataStore method restoreAttributes.
/**
* @param is inputstream containing session data
* @param size number of attributes
* @param data the data to restore to
* @throws Exception
*/
private void restoreAttributes(InputStream is, int size, SessionData data) throws Exception {
if (size > 0) {
// input stream should not be closed here
Map<String, Object> attributes = new HashMap<String, Object>();
ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(is);
for (int i = 0; i < size; i++) {
String key = ois.readUTF();
Object value = ois.readObject();
attributes.put(key, value);
}
data.putAllAttributes(attributes);
}
}
use of org.eclipse.jetty.util.ClassLoadingObjectInputStream in project jetty.project by eclipse.
the class MongoSessionDataStore method decodeValue.
/*------------------------------------------------------------ */
protected Object decodeValue(final Object valueToDecode) throws IOException, ClassNotFoundException {
if (valueToDecode == null || valueToDecode instanceof Number || valueToDecode instanceof String || valueToDecode instanceof Boolean || valueToDecode instanceof Date) {
return valueToDecode;
} else if (valueToDecode instanceof byte[]) {
final byte[] decodeObject = (byte[]) valueToDecode;
final ByteArrayInputStream bais = new ByteArrayInputStream(decodeObject);
final ClassLoadingObjectInputStream objectInputStream = new ClassLoadingObjectInputStream(bais);
return objectInputStream.readUnshared();
} else if (valueToDecode instanceof DBObject) {
Map<String, Object> map = new HashMap<String, Object>();
for (String name : ((DBObject) valueToDecode).keySet()) {
String attr = decodeName(name);
map.put(attr, decodeValue(((DBObject) valueToDecode).get(name)));
}
return map;
} else {
throw new IllegalStateException(valueToDecode.getClass().toString());
}
}
use of org.eclipse.jetty.util.ClassLoadingObjectInputStream in project jetty.project by eclipse.
the class GCloudSessionDataStore method sessionFromEntity.
/**
* Generate SessionData from an Entity retrieved from gcloud datastore.
* @param entity the entity
* @return the session data
* @throws Exception if unable to get the entity
*/
protected SessionData sessionFromEntity(Entity entity) throws Exception {
if (entity == null)
return null;
final AtomicReference<SessionData> reference = new AtomicReference<SessionData>();
final AtomicReference<Exception> exception = new AtomicReference<Exception>();
Runnable load = new Runnable() {
public void run() {
try {
//turn an Entity into a Session
String id = entity.getString(_model.getId());
String contextPath = entity.getString(_model.getContextPath());
String vhost = entity.getString(_model.getVhost());
long accessed = entity.getLong(_model.getAccessed());
long lastAccessed = entity.getLong(_model.getLastAccessed());
long createTime = entity.getLong(_model.getCreateTime());
long cookieSet = entity.getLong(_model.getCookieSetTime());
String lastNode = entity.getString(_model.getLastNode());
long lastSaved = 0;
//for compatibility with previously saved sessions, lastSaved may not be present
try {
lastSaved = entity.getLong(_model.getLastSaved());
} catch (DatastoreException e) {
LOG.ignore(e);
}
long expiry = entity.getLong(_model.getExpiry());
long maxInactive = entity.getLong(_model.getMaxInactive());
Blob blob = (Blob) entity.getBlob(_model.getAttributes());
SessionData session = newSessionData(id, createTime, accessed, lastAccessed, maxInactive);
session.setLastNode(lastNode);
session.setContextPath(contextPath);
session.setVhost(vhost);
session.setCookieSet(cookieSet);
session.setLastNode(lastNode);
session.setLastSaved(lastSaved);
session.setExpiry(expiry);
try (ClassLoadingObjectInputStream ois = new ClassLoadingObjectInputStream(blob.asInputStream())) {
Object o = ois.readObject();
session.putAllAttributes((Map<String, Object>) o);
} catch (Exception e) {
throw new UnreadableSessionDataException(id, _context, e);
}
reference.set(session);
} catch (Exception e) {
exception.set(e);
}
}
};
//ensure this runs in the context classloader
_context.run(load);
if (exception.get() != null)
throw exception.get();
return reference.get();
}
Aggregations