use of org.jboss.marshalling.OutputStreamByteOutput 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.OutputStreamByteOutput 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.OutputStreamByteOutput 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);
}
}
use of org.jboss.marshalling.OutputStreamByteOutput in project eap-additional-testsuite by jboss-set.
the class MarshallingTestCase method deserializationTest.
@ATTest({ "modules/testcases/jdkAll/Wildfly/core/src/main/java#10.0.0.Final*11.0.0.Beta1" })
public void deserializationTest() throws Exception {
RiverMarshallerFactory factory = new RiverMarshallerFactory();
MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(2);
// Create a marshaller on some stream we have
RiverMarshaller marshaller = (RiverMarshaller) factory.createMarshaller(configuration);
final ByteArrayOutputStream fileOutputStream = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(fileOutputStream));
Bar bar = new Bar("Hello");
Foo foo = new Foo(bar);
// Write lots of stuff
marshaller.writeObject(foo);
// Done
marshaller.finish();
RiverUnmarshaller unmarshaller = (RiverUnmarshaller) factory.createUnmarshaller(configuration);
ByteArrayInputStream fileInputStream = new ByteArrayInputStream(fileOutputStream.toByteArray());
unmarshaller.start(new InputStreamByteInput(fileInputStream));
try {
Foo f = unmarshaller.readObject(Foo.class);
Assert.assertEquals(f.bar.aString, "Hello");
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
unmarshaller.finish();
}
use of org.jboss.marshalling.OutputStreamByteOutput in project wildfly by wildfly.
the class EjbIIOPService method referenceForLocator.
/**
* Returns a corba reference for the given locator
*
* @param locator The locator
* @return The corba reference
*/
public org.omg.CORBA.Object referenceForLocator(final EJBLocator<?> locator) {
final EJBComponent ejbComponent = ejbComponentInjectedValue.getValue();
try {
final String earApplicationName = ejbComponent.getEarApplicationName() == null ? "" : ejbComponent.getEarApplicationName();
if (locator.getBeanName().equals(ejbComponent.getComponentName()) && locator.getAppName().equals(earApplicationName) && locator.getModuleName().equals(ejbComponent.getModuleName()) && locator.getDistinctName().equals(ejbComponent.getDistinctName())) {
if (locator instanceof EJBHomeLocator) {
return (org.omg.CORBA.Object) ejbHome;
} else if (locator instanceof StatelessEJBLocator) {
return beanReferenceFactory.createReference(beanRepositoryIds[0]);
} else if (locator instanceof StatefulEJBLocator) {
try (final Marshaller marshaller = factory.createMarshaller(configuration)) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(stream));
marshaller.writeObject(((StatefulEJBLocator<?>) locator).getSessionId());
marshaller.flush();
return beanReferenceFactory.createReferenceWithId(stream.toByteArray(), beanRepositoryIds[0]);
}
} else if (locator instanceof EntityEJBLocator) {
try (final Marshaller marshaller = factory.createMarshaller(configuration)) {
final ByteArrayOutputStream stream = new ByteArrayOutputStream();
marshaller.start(new OutputStreamByteOutput(stream));
marshaller.writeObject(((EntityEJBLocator<?>) locator).getPrimaryKey());
marshaller.flush();
return beanReferenceFactory.createReferenceWithId(stream.toByteArray(), beanRepositoryIds[0]);
}
}
throw EjbLogger.ROOT_LOGGER.unknownEJBLocatorType(locator);
} else {
throw EjbLogger.ROOT_LOGGER.incorrectEJBLocatorForBean(locator, ejbComponent.getComponentName());
}
} catch (Exception e) {
throw EjbLogger.ROOT_LOGGER.couldNotCreateCorbaObject(e, locator);
}
}
Aggregations