public class VibeServerCodec extends ChannelInboundHandlerAdapter
HttpRequest and HttpResponse into
NettyServerHttpExchange and NettyServerWebSocket. You need to
configure this handler and provide your action to receive
ServerHttpExchange and ServerWebSocket by overriding
httpAction() and wsAction()
like the following usage. When you configure handler, you must add
HttpServerCodec in front of this handler.
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new HttpServerCodec())
.addLast(new VibeServerCodec() {
@Override
protected boolean accept(HttpRequest req) {
return URI.create(req.getUri()).getPath().equals("/vibe");
}
@Override
protected Action<ServerHttpExchange> httpAction() {
return server.httpAction();
}
@Override
public Action<ServerWebSocket> wsAction() {
return server.websocketAction();
}
});
ChannelHandler.Sharable| Constructor and Description |
|---|
VibeServerCodec() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
accept(HttpRequest req)
Whether to process this request or not.
|
void |
channelInactive(ChannelHandlerContext ctx) |
void |
channelRead(ChannelHandlerContext ctx,
Object msg) |
void |
exceptionCaught(ChannelHandlerContext ctx,
Throwable cause) |
protected Action<ServerHttpExchange> |
httpAction()
An
Action to consume ServerHttpExchange. |
Action<ServerWebSocket> |
wsAction()
An
Action to consume ServerWebSocket. |
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, userEventTriggeredhandlerAdded, handlerRemoved, isSharableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waithandlerAdded, handlerRemovedpublic void channelRead(ChannelHandlerContext ctx, Object msg)
channelRead in interface ChannelInboundHandlerchannelRead in class ChannelInboundHandlerAdapterprotected boolean accept(HttpRequest req)
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
exceptionCaught in interface ChannelHandlerexceptionCaught in interface ChannelInboundHandlerexceptionCaught in class ChannelInboundHandlerAdapterpublic void channelInactive(ChannelHandlerContext ctx)
channelInactive in interface ChannelInboundHandlerchannelInactive in class ChannelInboundHandlerAdapterprotected Action<ServerHttpExchange> httpAction()
Action to consume ServerHttpExchange. By default, it
throws IllegalStateException so you should provide your action by
overriding it.public Action<ServerWebSocket> wsAction()
Action to consume ServerWebSocket. By default, it
throws IllegalStateException so you should provide your action by
overriding it.Copyright 2014, The Vibe Project