Search in sources :

Example 1 with NoSuchCommandException

use of org.apache.dubbo.qos.command.NoSuchCommandException in project dubbo by alibaba.

the class HttpProcessHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception {
    CommandContext commandContext = HttpCommandDecoder.decode(msg);
    // return 404 when fail to construct command context
    FullHttpResponse response;
    if (commandContext == null) {
        log.warn("can not found commandContext url: " + msg.getUri());
        response = http404();
    } else {
        commandContext.setRemote(ctx.channel());
        try {
            String result = commandExecutor.execute(commandContext);
            response = http200(result);
        } catch (NoSuchCommandException ex) {
            log.error("can not find commandContext: " + commandContext, ex);
            response = http404();
        } catch (Exception qosEx) {
            log.error("execute commandContext: " + commandContext + " got exception", qosEx);
            response = http500(qosEx.getMessage());
        }
    }
    ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
Also used : CommandContext(org.apache.dubbo.qos.command.CommandContext) NoSuchCommandException(org.apache.dubbo.qos.command.NoSuchCommandException) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) DefaultFullHttpResponse(io.netty.handler.codec.http.DefaultFullHttpResponse) NoSuchCommandException(org.apache.dubbo.qos.command.NoSuchCommandException)

Example 2 with NoSuchCommandException

use of org.apache.dubbo.qos.command.NoSuchCommandException in project dubbo by alibaba.

the class TelnetProcessHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
    if (StringUtils.isBlank(msg)) {
        ctx.writeAndFlush(QosProcessHandler.PROMPT);
    } else {
        CommandContext commandContext = TelnetCommandDecoder.decode(msg);
        commandContext.setRemote(ctx.channel());
        try {
            String result = commandExecutor.execute(commandContext);
            if (StringUtils.isEquals(QosConstants.CLOSE, result)) {
                ctx.writeAndFlush(getByeLabel()).addListener(ChannelFutureListener.CLOSE);
            } else {
                ctx.writeAndFlush(result + QosConstants.BR_STR + QosProcessHandler.PROMPT);
            }
        } catch (NoSuchCommandException ex) {
            ctx.writeAndFlush(msg + " :no such command");
            ctx.writeAndFlush(QosConstants.BR_STR + QosProcessHandler.PROMPT);
            log.error("can not found command " + commandContext, ex);
        } catch (Exception ex) {
            ctx.writeAndFlush(msg + " :fail to execute commandContext by " + ex.getMessage());
            ctx.writeAndFlush(QosConstants.BR_STR + QosProcessHandler.PROMPT);
            log.error("execute commandContext got exception " + commandContext, ex);
        }
    }
}
Also used : CommandContext(org.apache.dubbo.qos.command.CommandContext) NoSuchCommandException(org.apache.dubbo.qos.command.NoSuchCommandException) NoSuchCommandException(org.apache.dubbo.qos.command.NoSuchCommandException)

Aggregations

CommandContext (org.apache.dubbo.qos.command.CommandContext)2 NoSuchCommandException (org.apache.dubbo.qos.command.NoSuchCommandException)2 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)1