org.jboss.marshalling.MarshallerFactory Java Examples

The following examples show how to use org.jboss.marshalling.MarshallerFactory. 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 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 #2
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 #3
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 #4
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 #5
Source File: MarshallingCodeCFactory.java    From netty-custom-protocol with MIT License 5 votes vote down vote up
/**
   * 创建Jboss Unmarshaller解码对象
   * @return Unmarshaller
   * @throws IOException 
   */
  public static Unmarshaller buildUnMarshalling() throws IOException {
final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
return unmarshaller;
  }
 
Example #6
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 #7
Source File: MarshallingCodeCFactory.java    From fileserver with Apache License 2.0 5 votes vote down vote up
/**
    * 创建Jboss Marshalling解码器MarshallingDecoder
    * 
    * @return
    */
   public static MarshallingDecoder buildMarshallingDecoder() {
final MarshallerFactory marshallerFactory = Marshalling
	.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
UnmarshallerProvider provider = new DefaultUnmarshallerProvider(
	marshallerFactory, configuration);
MarshallingDecoder decoder = new MarshallingDecoder(provider, 1024*1024*10);
return decoder;
   }
 
Example #8
Source File: MarshallingCodeCFactory.java    From fileserver with Apache License 2.0 5 votes vote down vote up
/**
    * 创建Jboss Marshalling编码器MarshallingEncoder
    * 
    * @return
    */
   public static MarshallingEncoder buildMarshallingEncoder() {
final MarshallerFactory marshallerFactory = Marshalling
	.getProvidedMarshallerFactory("serial");
final MarshallingConfiguration configuration = new MarshallingConfiguration();
configuration.setVersion(5);
MarshallerProvider provider = new DefaultMarshallerProvider(
	marshallerFactory, configuration);
MarshallingEncoder encoder = new MarshallingEncoder(provider);
return encoder;
   }
 
Example #9
Source File: AbstractCompatibleMarshallingEncoderTest.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshalling() throws Exception {
    @SuppressWarnings("RedundantStringConstructorCall")
    String testObject = new String("test");

    final MarshallerFactory marshallerFactory = createMarshallerFactory();
    final MarshallingConfiguration configuration = createMarshallingConfig();

    EmbeddedChannel ch = new EmbeddedChannel(createEncoder());

    ch.writeOutbound(testObject);
    assertTrue(ch.finish());

    ByteBuf buffer = ch.readOutbound();

    Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
    unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
    String read = (String) unmarshaller.readObject();
    assertEquals(testObject, read);

    assertEquals(-1, unmarshaller.read());

    assertNull(ch.readOutbound());

    unmarshaller.finish();
    unmarshaller.close();
    buffer.release();
}
 
Example #10
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 #11
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 #12
Source File: AbstractCompatibleMarshallingEncoderTest.java    From netty4.0.27Learn with Apache License 2.0 5 votes vote down vote up
@Test
public void testMarshalling() throws IOException, ClassNotFoundException {
    @SuppressWarnings("RedundantStringConstructorCall")
    String testObject = new String("test");

    final MarshallerFactory marshallerFactory = createMarshallerFactory();
    final MarshallingConfiguration configuration = createMarshallingConfig();

    EmbeddedChannel ch = new EmbeddedChannel(createEncoder());

    ch.writeOutbound(testObject);
    assertTrue(ch.finish());

    ByteBuf buffer = (ByteBuf) ch.readOutbound();

    Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(configuration);
    unmarshaller.start(Marshalling.createByteInput(truncate(buffer).nioBuffer()));
    String read = (String) unmarshaller.readObject();
    assertEquals(testObject, read);

    assertEquals(-1, unmarshaller.read());

    assertNull(ch.readOutbound());

    unmarshaller.finish();
    unmarshaller.close();
    buffer.release();
}
 
Example #13
Source File: AbstractCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new DefaultUnmarshallerProvider(factory, config);
}
 
Example #14
Source File: SerialCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("serial");
}
 
Example #15
Source File: SerialThreadLocalCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ThreadLocalUnmarshallerProvider(factory, config);
}
 
Example #16
Source File: SerialCompatibleMarshallingEncoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("serial");
}
 
Example #17
Source File: RiverThreadLocalCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ThreadLocalUnmarshallerProvider(factory, config);
}
 
Example #18
Source File: SerialThreadLocalMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ThreadLocalUnmarshallerProvider(factory, config);
}
 
Example #19
Source File: RiverContextBoundCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ContextBoundUnmarshallerProvider(factory, config);
}
 
Example #20
Source File: RiverCompatibleMarshallingEncoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("river");
}
 
Example #21
Source File: RiverCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory("river");
}
 
Example #22
Source File: ContextBoundUnmarshallerProvider.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
public ContextBoundUnmarshallerProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    super(factory, config);
}
 
Example #23
Source File: SerialContextBoundMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ContextBoundUnmarshallerProvider(factory, config);
}
 
Example #24
Source File: RiverThreadLocalMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ThreadLocalUnmarshallerProvider(factory, config);
}
 
Example #25
Source File: RiverContextBoundMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ContextBoundUnmarshallerProvider(factory, config);
}
 
Example #26
Source File: SerialContextBoundCompatibleMarshallingDecoderTest.java    From netty4.0.27Learn with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ContextBoundUnmarshallerProvider(factory, config);
}
 
Example #27
Source File: RiverContextBoundMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
protected UnmarshallerProvider createProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    return new ContextBoundUnmarshallerProvider(factory, config);
}
 
Example #28
Source File: ContextBoundUnmarshallerProvider.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
public ContextBoundUnmarshallerProvider(MarshallerFactory factory, MarshallingConfiguration config) {
    super(factory, config);
}
 
Example #29
Source File: RiverCompatibleMarshallingDecoderTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory(RIVER_FACTORY);
}
 
Example #30
Source File: RiverCompatibleMarshallingEncoderTest.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
@Override
protected MarshallerFactory createMarshallerFactory() {
    return Marshalling.getProvidedMarshallerFactory(RIVER_FACTORY);
}