Binary WebSockets Messaging with Hessian

From Resin 4.0 Wiki

Revision as of 00:00, 13 January 2012 by Ferg (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Email-48.pngCookbook-48.png

HessianEchoListener implements WebSocketListener

import com.caucho.websocket.*;
import com.caucho.hessian.io.*;

public class HessianEchoListener extends AbstractWebSocketListener {
  Hessian2Input _hIn;
  Hessian2Output _hOut;

  HessianEchoListener(HessianFactory factory)
  {
    _hIn = factory.createHessian2Input(null);
    _hOut = factory.createHessian2Output(null);
  }

  @Override
  public void onReadBinary(WebSocketContext context, InputStream is)
    throws IOException
  {
    _hIn.initPacket(is);

    Object obj = _hIn.readObject();

    OutputStream os = context.beginBinaryMessage();
    _hOut.initPacket(os);
    _hOut.writeObject(obj);
    _hOut.close();
  }
}
Personal tools
TOOLBOX
LANGUAGES