use of org.jboss.marshalling.Unmarshaller in project wildfly by wildfly.
the class AbstractPersistentSessionManager method loadSessionAttributes.
@Override
public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) {
try {
Unmarshaller unmarshaller = createUnmarshaller();
try {
long time = System.currentTimeMillis();
Map<String, SessionEntry> data = loadSerializedSessions(deploymentName);
if (data != null) {
Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>();
for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) {
if (sessionEntry.getValue().expiry.getTime() > time) {
Map<String, Object> session = new HashMap<String, Object>();
for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) {
unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue())));
session.put(sessionAttribute.getKey(), unmarshaller.readObject());
unmarshaller.finish();
}
ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session));
}
}
return ret;
}
} finally {
unmarshaller.close();
}
} catch (Exception e) {
UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e);
}
return null;
}
use of org.jboss.marshalling.Unmarshaller in project netty by netty.
the class ContextBoundUnmarshallerProvider method getUnmarshaller.
@Override
public Unmarshaller getUnmarshaller(ChannelHandlerContext ctx) throws Exception {
Attribute<Unmarshaller> attr = ctx.attr(UNMARSHALLER);
Unmarshaller unmarshaller = attr.get();
if (unmarshaller == null) {
unmarshaller = super.getUnmarshaller(ctx);
attr.set(unmarshaller);
}
return unmarshaller;
}
use of org.jboss.marshalling.Unmarshaller in project netty by netty.
the class MarshallingDecoder method decode.
@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
ByteBuf frame = (ByteBuf) super.decode(ctx, in);
if (frame == null) {
return null;
}
Unmarshaller unmarshaller = provider.getUnmarshaller(ctx);
ByteInput input = new ChannelBufferByteInput(frame);
try {
unmarshaller.start(input);
Object obj = unmarshaller.readObject();
unmarshaller.finish();
return obj;
} finally {
// Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are
// readable. This helps to be sure that we do not leak resource
unmarshaller.close();
}
}
use of org.jboss.marshalling.Unmarshaller in project netty by netty.
the class AbstractCompatibleMarshallingEncoderTest method testMarshalling.
@Test
public void testMarshalling() throws Exception {
@SuppressWarnings("RedundantStringConstructorCall") String testObject = new String("test");
final MarshallerFactory marshallerFactory = createMarshallerFactory();
final MarshallingConfiguration configuration = createMarshallingConfig();
EmbeddedChannel ch = new EmbeddedChannel(createEncoder());
ch.writeOutbound(testObject);
assertTrue(ch.finish());
ByteBuf buffer = ch.readOutbound();
Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
String read = (String) unmarshaller.readObject();
assertEquals(testObject, read);
assertEquals(-1, unmarshaller.read());
assertNull(ch.readOutbound());
unmarshaller.finish();
unmarshaller.close();
buffer.release();
}
use of org.jboss.marshalling.Unmarshaller in project wildfly by wildfly.
the class DatabaseTimerPersistence method deSerialize.
public Object deSerialize(final String data) throws SQLException {
if (data == null) {
return null;
}
InputStream in = new ByteArrayInputStream(Base64.getDecoder().decode(data));
try {
final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration);
unmarshaller.start(new InputStreamByteInput(in));
Object ret = unmarshaller.readObject();
unmarshaller.finish();
return ret;
} catch (IOException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} finally {
safeClose(in);
}
}
Aggregations