Search in sources :

Example 1 with Marshaller

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());
}
Also used : MarshallerFactory(org.jboss.marshalling.MarshallerFactory) Marshaller(org.jboss.marshalling.Marshaller) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.jupiter.api.Test)

Example 2 with Marshaller

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));
}
Also used : MarshallerFactory(org.jboss.marshalling.MarshallerFactory) Marshaller(org.jboss.marshalling.Marshaller) MarshallingConfiguration(org.jboss.marshalling.MarshallingConfiguration) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandler(io.netty.channel.ChannelHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 3 with Marshaller

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

Example 4 with Marshaller

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);
    }
}
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 5 with Marshaller

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

Aggregations

Marshaller (org.jboss.marshalling.Marshaller)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 OutputStreamByteOutput (org.jboss.marshalling.OutputStreamByteOutput)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 IOException (java.io.IOException)3 MarshallerFactory (org.jboss.marshalling.MarshallerFactory)3 MarshallingConfiguration (org.jboss.marshalling.MarshallingConfiguration)3 Test (org.junit.jupiter.api.Test)3 DataOutputStream (java.io.DataOutputStream)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 SimpleDataOutput (org.jboss.marshalling.SimpleDataOutput)2 StartException (org.jboss.msc.service.StartException)2 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelHandler (io.netty.channel.ChannelHandler)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InvalidClassException (java.io.InvalidClassException)1 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1