Example usage for io.netty.handler.codec.http HttpResponseStatus MISDIRECTED_REQUEST

List of usage examples for io.netty.handler.codec.http HttpResponseStatus MISDIRECTED_REQUEST

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpResponseStatus MISDIRECTED_REQUEST.

Prototype

HttpResponseStatus MISDIRECTED_REQUEST

To view the source code for io.netty.handler.codec.http HttpResponseStatus MISDIRECTED_REQUEST.

Click Source Link

Document

421 Misdirected Request

Usage

From source file:com.heliosapm.webrpc.websocket.WebSocketServiceHandler.java

License:Apache License

/**
 * Processes an HTTP request//from  www  . ja  v a2  s  .c o m
 * @param ctx The channel handler context
 * @param req The HTTP request
 */
public void handleRequest(final ChannelHandlerContext ctx, final FullHttpRequest req) {
    log.warn("HTTP Request: {}", req);
    if (req.method() != GET) {
        sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN));
        return;
    }
    String uri = req.uri();
    if (!"/ws".equals(uri)) {
        //channelRead(ctx, req);
        final WebSocketServerProtocolHandler wsProto = ctx.pipeline().get(WebSocketServerProtocolHandler.class);
        if (wsProto != null) {
            try {
                wsProto.acceptInboundMessage(req);
                return;
            } catch (Exception ex) {
                log.error("Failed to dispatch http request to WebSocketServerProtocolHandler on channel [{}]",
                        ctx.channel(), ex);
            }
        }
    }
    log.error("Failed to handle HTTP Request [{}] on channel [{}]", req, ctx.channel());
    sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.MISDIRECTED_REQUEST));
}