Search in sources :

Example 1 with OutputStreamByteOutput

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();
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) ByteArrayOutputStream(java.io.ByteArrayOutputStream) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 2 with OutputStreamByteOutput

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);
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StartException(org.jboss.msc.service.StartException) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with OutputStreamByteOutput

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);
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 4 with OutputStreamByteOutput

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();
}
Also used : RiverUnmarshaller(org.jboss.marshalling.river.RiverUnmarshaller) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) ByteArrayInputStream(java.io.ByteArrayInputStream) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) RiverMarshallerFactory(org.jboss.marshalling.river.RiverMarshallerFactory) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RiverMarshaller(org.jboss.marshalling.river.RiverMarshaller) ATTest(org.jboss.eap.additional.testsuite.annotations.ATTest)

Example 5 with OutputStreamByteOutput

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);
    }
}
Also used : Marshaller(org.jboss.marshalling.Marshaller) StatelessEJBLocator(org.jboss.ejb.client.StatelessEJBLocator) OutputStreamByteOutput(org.jboss.marshalling.OutputStreamByteOutput) EJBHomeLocator(org.jboss.ejb.client.EJBHomeLocator) StatefulEJBLocator(org.jboss.ejb.client.StatefulEJBLocator) PortableRemoteObject(javax.rmi.PortableRemoteObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) EntityEJBLocator(org.jboss.ejb.client.EntityEJBLocator) InvalidClassException(java.io.InvalidClassException) StartException(org.jboss.msc.service.StartException) IOException(java.io.IOException)

Aggregations

OutputStreamByteOutput (org.jboss.marshalling.OutputStreamByteOutput)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Marshaller (org.jboss.marshalling.Marshaller)6 IOException (java.io.IOException)3 XMLStreamException (javax.xml.stream.XMLStreamException)2 StartException (org.jboss.msc.service.StartException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InvalidClassException (java.io.InvalidClassException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)1 EJBHomeLocator (org.jboss.ejb.client.EJBHomeLocator)1 EntityEJBLocator (org.jboss.ejb.client.EntityEJBLocator)1 StatefulEJBLocator (org.jboss.ejb.client.StatefulEJBLocator)1 StatelessEJBLocator (org.jboss.ejb.client.StatelessEJBLocator)1 InputStreamByteInput (org.jboss.marshalling.InputStreamByteInput)1