Search in sources :

Example 1 with InputStreamByteInput

use of org.jboss.marshalling.InputStreamByteInput 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 2 with InputStreamByteInput

use of org.jboss.marshalling.InputStreamByteInput in project wildfly by wildfly.

the class LegacyFileStore method loadTimersFromFile.

static Map<String, TimerImpl> loadTimersFromFile(final String timedObjectId, final TimerServiceImpl timerService, String directory, MarshallerFactory factory, MarshallingConfiguration configuration) {
    final Map<String, TimerImpl> timers = new HashMap<String, TimerImpl>();
    Unmarshaller unmarshaller = null;
    try {
        final File file = new File(directory);
        if (!file.exists()) {
            // no timers exist yet
            return timers;
        } else if (!file.isDirectory()) {
            EJB3_TIMER_LOGGER.failToRestoreTimers(file);
            return timers;
        }
        File marker = new File(file, MIGRATION_MARKER);
        if (marker.exists()) {
            return timers;
        }
        unmarshaller = factory.createUnmarshaller(configuration);
        for (File timerFile : file.listFiles()) {
            if (timerFile.getName().endsWith(".xml")) {
                continue;
            }
            FileInputStream in = null;
            try {
                in = new FileInputStream(timerFile);
                unmarshaller.start(new InputStreamByteInput(in));
                final TimerEntity entity = unmarshaller.readObject(TimerEntity.class);
                // we load the legacy timer entity class, and turn it into a timer state
                TimerImpl.Builder builder;
                if (entity instanceof CalendarTimerEntity) {
                    CalendarTimerEntity c = (CalendarTimerEntity) entity;
                    final ScheduleExpression scheduleExpression = new ScheduleExpression();
                    scheduleExpression.second(c.getSecond()).minute(c.getMinute()).hour(c.getHour()).dayOfWeek(c.getDayOfWeek()).dayOfMonth(c.getDayOfMonth()).month(c.getMonth()).year(c.getYear()).start(c.getStartDate()).end(c.getEndDate()).timezone(c.getTimezone());
                    builder = CalendarTimer.builder().setScheduleExpression(scheduleExpression).setAutoTimer(c.isAutoTimer()).setTimeoutMethod(CalendarTimer.getTimeoutMethod(c.getTimeoutMethod(), timerService.getTimedObjectInvoker().getValue().getClassLoader()));
                } else {
                    builder = TimerImpl.builder();
                }
                builder.setId(entity.getId()).setTimedObjectId(entity.getTimedObjectId()).setInitialDate(entity.getInitialDate()).setRepeatInterval(entity.getInterval()).setNextDate(entity.getNextDate()).setPreviousRun(entity.getPreviousRun()).setInfo(entity.getInfo()).setTimerState(entity.getTimerState()).setPersistent(true);
                timers.put(entity.getId(), builder.build(timerService));
                unmarshaller.finish();
            } catch (Exception e) {
                EJB3_TIMER_LOGGER.failToRestoreTimersFromFile(timerFile, e);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        EJB3_TIMER_LOGGER.failToCloseFile(e);
                    }
                }
            }
        }
        if (!timers.isEmpty()) {
            Files.write(marker.toPath(), new Date().toString().getBytes(StandardCharsets.UTF_8));
        }
    } catch (Exception e) {
        EJB3_TIMER_LOGGER.failToRestoreTimersForObjectId(timedObjectId, e);
    } finally {
        VFSUtils.safeClose(unmarshaller);
    }
    return timers;
}
Also used : ScheduleExpression(javax.ejb.ScheduleExpression) HashMap(java.util.HashMap) CalendarTimerEntity(org.jboss.as.ejb3.timerservice.persistence.CalendarTimerEntity) TimerEntity(org.jboss.as.ejb3.timerservice.persistence.TimerEntity) CalendarTimerEntity(org.jboss.as.ejb3.timerservice.persistence.CalendarTimerEntity) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) Date(java.util.Date) InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) TimerImpl(org.jboss.as.ejb3.timerservice.TimerImpl) Unmarshaller(org.jboss.marshalling.Unmarshaller) File(java.io.File)

Example 3 with InputStreamByteInput

use of org.jboss.marshalling.InputStreamByteInput 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 | ClassNotFoundException e) {
        throw new RuntimeException(e);
    } finally {
        safeClose(in);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) IOException(java.io.IOException) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 4 with InputStreamByteInput

use of org.jboss.marshalling.InputStreamByteInput in project wildfly by wildfly.

the class EjbCorbaServant method unmarshalIdentifier.

private Object unmarshalIdentifier() throws IOException, ClassNotFoundException {
    final Object id;
    try (final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration)) {
        final byte[] idData = poaCurrent.get_object_id();
        unmarshaller.start(new InputStreamByteInput(new ByteArrayInputStream(idData)));
        id = unmarshaller.readObject();
    } catch (NoContext noContext) {
        throw new RuntimeException(noContext);
    }
    return id;
}
Also used : NoContext(org.omg.PortableServer.CurrentPackage.NoContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) Unmarshaller(org.jboss.marshalling.Unmarshaller)

Example 5 with InputStreamByteInput

use of org.jboss.marshalling.InputStreamByteInput in project wildfly by wildfly.

the class DiskBasedModularPersistentSessionManager method loadSerializedSessions.

@Override
protected Map<String, SessionEntry> loadSerializedSessions(String deploymentName) throws IOException {
    File file = new File(baseDir, deploymentName);
    if (!file.exists()) {
        return null;
    }
    FileInputStream in = new FileInputStream(file);
    try {
        Unmarshaller unMarshaller = createUnmarshaller();
        try {
            try {
                unMarshaller.start(new InputStreamByteInput(in));
                return (Map<String, SessionEntry>) unMarshaller.readObject();
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            } finally {
                unMarshaller.finish();
            }
        } finally {
            unMarshaller.close();
        }
    } finally {
        IoUtils.safeClose(in);
    }
}
Also used : InputStreamByteInput(org.jboss.marshalling.InputStreamByteInput) Unmarshaller(org.jboss.marshalling.Unmarshaller) File(java.io.File) Map(java.util.Map) FileInputStream(java.io.FileInputStream)

Aggregations

InputStreamByteInput (org.jboss.marshalling.InputStreamByteInput)5 Unmarshaller (org.jboss.marshalling.Unmarshaller)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ScheduleExpression (javax.ejb.ScheduleExpression)1 TimerImpl (org.jboss.as.ejb3.timerservice.TimerImpl)1 CalendarTimerEntity (org.jboss.as.ejb3.timerservice.persistence.CalendarTimerEntity)1 TimerEntity (org.jboss.as.ejb3.timerservice.persistence.TimerEntity)1 ATTest (org.jboss.eap.additional.testsuite.annotations.ATTest)1 MarshallingConfiguration (org.jboss.marshalling.MarshallingConfiguration)1 OutputStreamByteOutput (org.jboss.marshalling.OutputStreamByteOutput)1 RiverMarshaller (org.jboss.marshalling.river.RiverMarshaller)1 RiverMarshallerFactory (org.jboss.marshalling.river.RiverMarshallerFactory)1