package org.yamcs.http;

import org.yamcs.logging.Log;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.FullHttpRequest;

public abstract class Handler extends SimpleChannelInboundHandler<FullHttpRequest> {

    private static final Log log = new Log(Handler.class);

    // TODO make abstract once plugins have migrated
    public /* abstract */ void handle(HandlerContext ctx) {
    }

    /**
     * Implement {@link #handle(HandlerContext)} instead
     */
    @Deprecated
    public void handle(ChannelHandlerContext ctx, FullHttpRequest msg) {
        String contextPath = ctx.channel().attr(HttpRequestHandler.CTX_CONTEXT_PATH).get();
        handle(new HandlerContext(contextPath, ctx, msg));
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
        try {
            handle(ctx, msg);
        } catch (Throwable t) {
            if (!(t instanceof HttpException)) {
                t = new InternalServerErrorException(t);
            }

            HttpException e = (HttpException) t;
            if (e.isServerError()) {
                log.error("Responding '{}': {}", e.getStatus(), e.getMessage(), e);
            } else {
                log.warn("Responding '{}': {}", e.getStatus(), e.getMessage());
            }
            HttpRequestHandler.sendPlainTextError(ctx, msg, e.getStatus());
        }
    }
}

@@ -352,61 +352,8 @@
 );%0A%0A
-    // TODO make abstract once plugins have migrated%0A
     
@@ -358,19 +358,16 @@
   public
- /*
  abstrac
@@ -367,19 +367,16 @@
 abstract
- */
  void ha
@@ -403,129 +403,56 @@
 ctx)
- %7B%0A    %7D%0A%0A    /**%0A     * Implement %7B@link #handle(HandlerContext)%7D instead%0A     */%0A    @Depr
+;%0A%0A    @Override%0A    prot
 ec
-a
 ted
-%0A    public
  void 
+c
 han
-dle
+nelRead0
 (Cha
@@ -496,18 +496,53 @@
 st msg) 
-%7B%0A
+throws Exception %7B%0A        try %7B%0A    
         
@@ -629,24 +629,28 @@
 ();%0A        
+    
 handle(new H
@@ -692,172 +692,8 @@
 ));%0A
-    %7D%0A%0A    @Override%0A    protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception %7B%0A        try %7B%0A            handle(ctx, msg);%0A
     

Remove deprecated Handler.handle method