Search in sources :

Example 1 with SocketRequest

use of com.github.dreamhead.moco.SocketRequest in project moco by dreamhead.

the class MocoSocketHandler method channelRead0.

@Override
protected void channelRead0(final ChannelHandlerContext ctx, final ByteBuf msg) {
    MessageContent content = content().withContent(new ByteBufInputStream(msg)).build();
    SocketRequest request = new DefaultSocketRequest(content);
    SessionContext context = new SessionContext(request, new DefaultSocketResponse());
    Optional<Response> response = server.getResponse(context);
    Response actual = response.orElseThrow(() -> new MocoException(format("No handler found for request: %s", context.getRequest().getContent())));
    ctx.write(ByteBufs.toByteBuf(actual.getContent().getContent()));
}
Also used : DefaultSocketResponse(com.github.dreamhead.moco.model.DefaultSocketResponse) Response(com.github.dreamhead.moco.Response) MessageContent(com.github.dreamhead.moco.model.MessageContent) DefaultSocketRequest(com.github.dreamhead.moco.model.DefaultSocketRequest) SocketRequest(com.github.dreamhead.moco.SocketRequest) DefaultSocketRequest(com.github.dreamhead.moco.model.DefaultSocketRequest) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) MocoException(com.github.dreamhead.moco.MocoException) DefaultSocketResponse(com.github.dreamhead.moco.model.DefaultSocketResponse)

Aggregations

MocoException (com.github.dreamhead.moco.MocoException)1 Response (com.github.dreamhead.moco.Response)1 SocketRequest (com.github.dreamhead.moco.SocketRequest)1 DefaultSocketRequest (com.github.dreamhead.moco.model.DefaultSocketRequest)1 DefaultSocketResponse (com.github.dreamhead.moco.model.DefaultSocketResponse)1 MessageContent (com.github.dreamhead.moco.model.MessageContent)1 ByteBufInputStream (io.netty.buffer.ByteBufInputStream)1