在getPipeline()方法中配置处理程序的正确方法

时间:2011-12-26 00:07:45

标签: netty

有人可以建议在getPipeline()方法中配置处理程序的最佳/正确方法。 当客户端向服务器发送消息时,它由自定义对象组成,其中包含服务器所需的数据。 我已经配置了处理程序,如下所示:

public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = pipeline();

SSLEngine engine = SecureSslContextFactory.getServerContext().createSSLEngine();
engine.setUseClientMode(false);

pipeline.addLast("ssl", new SslHandler(engine));

pipeline.addLast("decoder", new ObjectDecoder());
pipeline.addLast("encoder", new ObjectEncoder());

pipeline.addLast("pipelineExecutor", new ExecutionHandler(pipelineExecutor));

// and then business logic.
pipeline.addLast("handler", new SecureServerHandler());

return pipeline;
}

当我使用Netty 3.2.7 Final编译时,我收到以下警告:

警告(78,33):org.jboss.netty.handler.codec.serialization.ObjectDecoder中的ObjectDecoder()已被弃用

当客户端发送消息时,我收到以下运行时错误:

  

警告:下游出现意外异常   java.io.InvalidClassException:无法读取类描述符
          at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1567)
          at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496)
          at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1732)
          在java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329)
          在java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
          在org.jboss.netty.handler.codec.serialization.ObjectDecoder.decode(ObjectDecoder.java:129)
          在org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:282)
          在org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)
          在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
          在org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:321)
          在org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)
          在org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)
          在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:274)
          在org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:261)
          在org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:351)
          在org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:282)
          在org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:202)
          at java.util.concurrent.ThreadPoolExecutor $ Worker.runTask(ThreadPoolExecutor.java:886)
          在java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:908)
          在java.lang.Thread.run(Thread.java:619)

1 个答案:

答案 0 :(得分:0)

您的问题可能与以下问题相同:How to implement ObjectDecoder(ClassResolver) in Netty 3.2.7

尝试将ObjectDecoder实例化为new ObjectDecoder(ClassResolvers.weakCachingConcurrentResolver(null))以消除警告。

如果您的类没有加载,请尝试指定类加载器。请参阅http://markmail.org/message/4ftws33dxehbzbwd

希望这有帮助。