use of org.jboss.marshalling.Marshaller in project netty by netty.
the class AbstractCompatibleMarshallingDecoderTest method testFragmentedUnmarshalling.
@Test
public void testFragmentedUnmarshalling() throws IOException {
MarshallerFactory marshallerFactory = createMarshallerFactory();
MarshallingConfiguration configuration = createMarshallingConfig();
EmbeddedChannel ch = new EmbeddedChannel(createDecoder(Integer.MAX_VALUE));
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(bout));
marshaller.writeObject(testObject);
marshaller.finish();
marshaller.close();
byte[] testBytes = bout.toByteArray();
ByteBuf buffer = input(testBytes);
ByteBuf slice = buffer.readRetainedSlice(2);
ch.writeInbound(slice);
ch.writeInbound(buffer);
assertTrue(ch.finish());
String unmarshalled = ch.readInbound();
assertEquals(testObject, unmarshalled);
assertNull(ch.readInbound());
}
use of org.jboss.marshalling.Marshaller in project netty by netty.
the class AbstractCompatibleMarshallingDecoderTest method testTooBigObject.
@Test
public void testTooBigObject() throws IOException {
MarshallerFactory marshallerFactory = createMarshallerFactory();
MarshallingConfiguration configuration = createMarshallingConfig();
ChannelHandler mDecoder = createDecoder(4);
EmbeddedChannel ch = new EmbeddedChannel(mDecoder);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
marshaller.start(Marshalling.createByteOutput(bout));
marshaller.writeObject(testObject);
marshaller.finish();
marshaller.close();
byte[] testBytes = bout.toByteArray();
onTooBigFrame(ch, input(testBytes));
}
use of org.jboss.marshalling.Marshaller in project wildfly by wildfly.
the class EjbTimerXmlPersister method writeCalendarTimer.
private void writeCalendarTimer(XMLExtendedStreamWriter writer, CalendarTimer timer) throws XMLStreamException {
String info = null;
if (timer.getInfo() != null) {
try (final Marshaller marshaller = factory.createMarshaller(configuration)) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(out));
marshaller.writeObject(timer.getInfo());
marshaller.flush();
info = Base64.getEncoder().encodeToString(out.toByteArray());
} catch (Exception e) {
EjbLogger.EJB3_TIMER_LOGGER.failedToPersistTimer(timer, e);
return;
}
}
writer.writeStartElement(CALENDAR_TIMER);
writer.writeAttribute(TIMED_OBJECT_ID, timer.getTimedObjectId());
writer.writeAttribute(TIMER_ID, timer.getId());
if (timer.getInitialExpiration() != null) {
writer.writeAttribute(INITIAL_DATE, Long.toString(timer.getInitialExpiration().getTime()));
}
if (timer.getNextExpiration() != null) {
writer.writeAttribute(NEXT_DATE, Long.toString(timer.getNextExpiration().getTime()));
}
writer.writeAttribute(TIMER_STATE, timer.getState().name());
writer.writeAttribute(SCHEDULE_EXPR_SECOND, timer.getScheduleExpression().getSecond());
writer.writeAttribute(SCHEDULE_EXPR_MINUTE, timer.getScheduleExpression().getMinute());
writer.writeAttribute(SCHEDULE_EXPR_HOUR, timer.getScheduleExpression().getHour());
writer.writeAttribute(SCHEDULE_EXPR_DAY_OF_WEEK, timer.getScheduleExpression().getDayOfWeek());
writer.writeAttribute(SCHEDULE_EXPR_DAY_OF_MONTH, timer.getScheduleExpression().getDayOfMonth());
writer.writeAttribute(SCHEDULE_EXPR_MONTH, timer.getScheduleExpression().getMonth());
writer.writeAttribute(SCHEDULE_EXPR_YEAR, timer.getScheduleExpression().getYear());
if (timer.getScheduleExpression().getStart() != null) {
writer.writeAttribute(SCHEDULE_EXPR_START_DATE, Long.toString(timer.getScheduleExpression().getStart().getTime()));
}
if (timer.getScheduleExpression().getEnd() != null) {
writer.writeAttribute(SCHEDULE_EXPR_END_DATE, Long.toString(timer.getScheduleExpression().getEnd().getTime()));
}
if (timer.getScheduleExpression().getTimezone() != null) {
writer.writeAttribute(SCHEDULE_EXPR_TIMEZONE, timer.getScheduleExpression().getTimezone());
}
if (info != null) {
writer.writeStartElement(INFO);
writer.writeCharacters(info);
writer.writeEndElement();
}
if (timer.isAutoTimer()) {
writer.writeStartElement(TIMEOUT_METHOD);
writer.writeAttribute(DECLARING_CLASS, timer.getTimeoutMethod().getDeclaringClass().getName());
writer.writeAttribute(NAME, timer.getTimeoutMethod().getName());
for (Class<?> param : timer.getTimeoutMethod().getParameterTypes()) {
writer.writeStartElement(PARAMETER);
writer.writeAttribute(TYPE, param.getName());
writer.writeEndElement();
}
writer.writeEndElement();
}
writer.writeEndElement();
}
use of org.jboss.marshalling.Marshaller in project wildfly by wildfly.
the class AbstractPersistentSessionManager method persistSessions.
@Override
public void persistSessions(String deploymentName, Map<String, PersistentSession> sessionData) {
try {
final Marshaller marshaller = createMarshaller();
try {
final Map<String, SessionEntry> serializedData = new HashMap<String, SessionEntry>();
for (Map.Entry<String, PersistentSession> sessionEntry : sessionData.entrySet()) {
Map<String, byte[]> data = new HashMap<String, byte[]>();
for (Map.Entry<String, Object> sessionAttribute : sessionEntry.getValue().getSessionData().entrySet()) {
try {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(out));
marshaller.writeObject(sessionAttribute.getValue());
marshaller.finish();
data.put(sessionAttribute.getKey(), out.toByteArray());
} catch (Exception e) {
UndertowLogger.ROOT_LOGGER.failedToPersistSessionAttribute(sessionAttribute.getKey(), sessionAttribute.getValue(), sessionEntry.getKey(), e);
}
}
serializedData.put(sessionEntry.getKey(), new SessionEntry(sessionEntry.getValue().getExpiration(), data));
}
persistSerializedSessions(deploymentName, serializedData);
} finally {
marshaller.close();
}
} catch (Exception e) {
UndertowServletLogger.ROOT_LOGGER.failedToPersistSessions(e);
}
}
use of org.jboss.marshalling.Marshaller in project wildfly by wildfly.
the class DiskBasedModularPersistentSessionManager method persistSerializedSessions.
@Override
protected void persistSerializedSessions(String deploymentName, Map<String, SessionEntry> serializedData) throws IOException {
File file = new File(baseDir, deploymentName);
FileOutputStream out = new FileOutputStream(file, false);
try {
Marshaller marshaller = createMarshaller();
try {
marshaller.start(new OutputStreamByteOutput(out));
marshaller.writeObject(serializedData);
marshaller.finish();
} finally {
marshaller.close();
}
} finally {
IoUtils.safeClose(out);
}
}
Aggregations