@Test public void testEncode1() throws Exception { SwallowMessage msg = new SwallowMessage(); msg.setGeneratedTime(new Date()); msg.setMessageId(123L); HashMap<String, String> map = new HashMap<String, String>(); map.put("property-key", "property-value"); msg.setContent("content"); HessianEncoder hessianEncoder = new HessianEncoder(); ChannelBuffer channelBuffer = (ChannelBuffer)hessianEncoder.encode(null, null, msg); InputStream is = new ByteArrayInputStream(channelBuffer.toByteBuffer().array()); Hessian2Input h2i = new Hessian2Input(is); h2i.setSerializerFactory(factory); Message actualMsg = (Message) h2i.readObject(); h2i.close(); Assert.assertEquals(msg, actualMsg); }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg instanceof Message) { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); Hessian2Output h2o = new Hessian2Output(bos); h2o.setSerializerFactory(factory); h2o.writeObject(msg); h2o.flush(); byte[] content = bos.toByteArray(); return ChannelBuffers.wrappedBuffer(content); } return msg; }
HessianEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg instanceof Message) { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); Hessian2Output h2o = new Hessian2Output(bos); h2o.setSerializerFactory(factory); h2o.writeObject(msg); h2o.flush(); byte[] content = bos.toByteArray(); return ChannelBuffers.wrappedBuffer(content); } return msg; } }
HessianEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg instanceof Message) { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); Hessian2Output h2o = new Hessian2Output(bos); h2o.setSerializerFactory(factory); h2o.writeObject(msg); h2o.flush(); byte[] content = bos.toByteArray(); return ChannelBuffers.wrappedBuffer(content); } return msg; } HessianEncoder(); }
HessianEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg instanceof Message) { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); Hessian2Output h2o = new Hessian2Output(bos); h2o.setSerializerFactory(factory); h2o.writeObject(msg); h2o.flush(); byte[] content = bos.toByteArray(); return ChannelBuffers.wrappedBuffer(content); } return msg; } HessianEncoder();  }
HessianEncoder extends OneToOneEncoder { @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { if (msg instanceof Message) { ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); Hessian2Output h2o = new Hessian2Output(bos); h2o.setSerializerFactory(factory); h2o.writeObject(msg); h2o.flush(); byte[] content = bos.toByteArray(); return ChannelBuffers.wrappedBuffer(content); } return msg; } HessianEncoder();   }