org.jboss.marshalling.Marshaller Java Examples

The following examples show how to use org.jboss.marshalling.Marshaller. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@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 = (String) ch.readInbound();

    assertEquals(testObject, unmarshalled);

    assertNull(ch.readInbound());
}
 
Example #2
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #3
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #5
Source File: MarshallingCodeCFactory.java    From netty-custom-protocol with MIT License 5 votes vote down vote up
/**
   * 创建Jboss Marshaller编码对象
   * @return Marshaller
   * @throws IOException 
   */
  public static Marshaller buildMarshalling() throws IOException {
  	//首先通过Marshalling工具类的精通方法获取Marshalling实例对象 参数serial标识创建的是java序列化工厂对象。
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
//创建了MarshallingConfiguration对象,配置了版本号为5 
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
return marshaller;
  }
 
Example #6
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@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.readSlice(2);

    ch.writeInbound(slice.retain());
    ch.writeInbound(buffer);
    assertTrue(ch.finish());

    String unmarshalled = (String) ch.readInbound();

    assertEquals(testObject, unmarshalled);

    assertNull(ch.readInbound());
}
 
Example #7
Source File: ThreadLocalMarshallerProvider.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Override
public Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception {
    Marshaller marshaller = marshallers.get();
    if (marshaller == null) {
        marshaller = factory.createMarshaller(config);
        marshallers.set(marshaller);
    }
    return marshaller;
}
 
Example #8
Source File: CompatibleMarshallingEncoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #9
Source File: MarshallingEncoder.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #10
Source File: StreamUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void safeFinish(final Marshaller marshaller) {
    if (marshaller != null) try {
        marshaller.finish();
    } catch (IOException e) {
        ProcessLogger.PROTOCOL_LOGGER.failedToFinishMarshaller(e, marshaller);
    }
}
 
Example #11
Source File: CounterIO.java    From SLP-Core with MIT License 5 votes vote down vote up
public static void writeCounter(Counter counter, File file) {
	System.out.println("Writing counter to: " + file);
	try (FileOutputStream os = new FileOutputStream(file)) {
       	final Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
           marshaller.start(Marshalling.createByteOutput(os));
           marshaller.writeObject(counter);
           marshaller.finish();
           os.close();
       } catch (IOException e) {
           System.err.print("Marshalling failed: ");
           e.printStackTrace();
       }
}
 
Example #12
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #13
Source File: ThreadLocalMarshallerProvider.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception {
    Marshaller marshaller = marshallers.get();
    if (marshaller == null) {
        marshaller = factory.createMarshaller(config);
        marshallers.set(marshaller);
    }
    return marshaller;
}
 
Example #14
Source File: CompatibleMarshallingEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #15
Source File: MarshallingEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #16
Source File: DefaultMarshallerProvider.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
public Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception {
    return factory.createMarshaller(config);
}
 
Example #17
Source File: ProtocolUtils.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static Marshaller getMarshaller(final MarshallingConfiguration config) throws IOException {
    return MARSHALLER_FACTORY.createMarshaller(config);
}
 
Example #18
Source File: DefaultMarshallerProvider.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
public Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception {
    return factory.createMarshaller(config);
}
 
Example #19
Source File: MarshallerProvider.java    From netty4.0.27Learn with Apache License 2.0 2 votes vote down vote up
/**
 * Get a {@link Marshaller} for the given {@link ChannelHandlerContext}
 */
Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception;
 
Example #20
Source File: MarshallerProvider.java    From netty-4.1.22 with Apache License 2.0 2 votes vote down vote up
/**
 * Get a {@link Marshaller} for the given {@link ChannelHandlerContext}
 * 为给定的ChannelHandlerContext获取一个编组器
 */
Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception;
 
Example #21
Source File: ProcessLogger.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Logs an error message indicating a failure to finish the marshaller.
 *
 * @param cause      the cause of the error.
 * @param marshaller the marshaller in error.
 */
@LogMessage(level = ERROR)
@Message(id = 37, value = "Failed to finish the marshaller %s")
void failedToFinishMarshaller(@Cause Throwable cause, Marshaller marshaller);