Search in sources :

Example 6 with Marshaller

use of org.jboss.marshalling.Marshaller in project netty by netty.

the class CompatibleMarshallingEncoder method encode.

@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
    Marshaller marshaller = provider.getMarshaller(ctx);
    marshaller.start(new ChannelBufferByteOutput(out));
    marshaller.writeObject(msg);
    marshaller.finish();
    marshaller.close();
}
Also used : Marshaller(org.jboss.marshalling.Marshaller)

Example 7 with Marshaller

use of org.jboss.marshalling.Marshaller in project netty by netty.

the class MarshallingEncoder method encode.

@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {
    Marshaller marshaller = provider.getMarshaller(ctx);
    int lengthPos = out.writerIndex();
    out.writeBytes(LENGTH_PLACEHOLDER);
    ChannelBufferByteOutput output = new ChannelBufferByteOutput(out);
    marshaller.start(output);
    marshaller.writeObject(msg);
    marshaller.finish();
    marshaller.close();
    out.setInt(lengthPos, out.writerIndex() - lengthPos - 4);
}
Also used : Marshaller(org.jboss.marshalling.Marshaller)

Example 8 with Marshaller

use of org.jboss.marshalling.Marshaller in project netty by netty.

the class ThreadLocalMarshallerProvider method getMarshaller.

@Override
public Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception {
    Marshaller marshaller = marshallers.get();
    if (marshaller == null) {
        marshaller = factory.createMarshaller(config);
        marshallers.set(marshaller);
    }
    return marshaller;
}
Also used : Marshaller(org.jboss.marshalling.Marshaller)

Example 9 with Marshaller

use of org.jboss.marshalling.Marshaller in project netty by netty.

the class AbstractCompatibleMarshallingDecoderTest method testSimpleUnmarshalling.

@Test
public void testSimpleUnmarshalling() 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();
    ch.writeInbound(input(testBytes));
    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) Test(org.junit.Test)

Example 10 with Marshaller

use of org.jboss.marshalling.Marshaller 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) {
                final Marshaller marshaller = factory.createMarshaller(configuration);
                final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                marshaller.start(new OutputStreamByteOutput(stream));
                marshaller.writeObject(((StatefulEJBLocator<?>) locator).getSessionId());
                marshaller.finish();
                return beanReferenceFactory.createReferenceWithId(stream.toByteArray(), beanRepositoryIds[0]);
            } else if (locator instanceof EntityEJBLocator) {
                final Marshaller marshaller = factory.createMarshaller(configuration);
                final ByteArrayOutputStream stream = new ByteArrayOutputStream();
                marshaller.start(new OutputStreamByteOutput(stream));
                marshaller.writeObject(((EntityEJBLocator<?>) locator).getPrimaryKey());
                marshaller.finish();
                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) StartException(org.jboss.msc.service.StartException)

Aggregations

Marshaller (org.jboss.marshalling.Marshaller)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 OutputStreamByteOutput (org.jboss.marshalling.OutputStreamByteOutput)6 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)3 MarshallerFactory (org.jboss.marshalling.MarshallerFactory)3 MarshallingConfiguration (org.jboss.marshalling.MarshallingConfiguration)3 Test (org.junit.Test)3 DataOutputStream (java.io.DataOutputStream)2 IOException (java.io.IOException)2 XMLStreamException (javax.xml.stream.XMLStreamException)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 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1 EJBComponent (org.jboss.as.ejb3.component.EJBComponent)1