// Path: netty-http/src/main/java/http/exception/BadRequestException.java
// public class BadRequestException  extends Exception{
// 
//     public BadRequestException(Throwable throwable) {
//         super(throwable);
//     }
// }


import http.exception.BadRequestException;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.CharsetUtil;
import org.apache.log4j.Logger;
import java.io.PrintWriter;
import java.io.StringWriter;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;

package http;




/**
 * Created by i311352 on 2/13/2017.
 */
public class DefaultExceptionHandler extends ChannelInboundHandlerAdapter {
    private final Logger logger = Logger.getLogger(DefaultExceptionHandler.class);

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        logger.error("Exception caught: " + cause);

        HttpResponseStatus status = (cause instanceof BadRequestException) ? HttpResponseStatus.BAD_REQUEST :

// Path: netty-http/src/main/java/http/exception/BadRequestException.java
// public class BadRequestException  extends Exception{
// 
//     public BadRequestException(Throwable throwable) {
//         super(throwable);
//     }
// }


// Path: netty-http/src/main/java/http/DefaultExceptionHandler.java
import http.exception.BadRequestException;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.codec.http.DefaultFullHttpResponse;
import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.CharsetUtil;
import org.apache.log4j.Logger;
import java.io.PrintWriter;
import java.io.StringWriter;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_LENGTH;
import static io.netty.handler.codec.http.HttpHeaders.Names.CONTENT_TYPE;
import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1;

package http;




/**
 * Created by i311352 on 2/13/2017.
 */
public class DefaultExceptionHandler extends ChannelInboundHandlerAdapter {
    private final Logger logger = Logger.getLogger(DefaultExceptionHandler.class);

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        logger.error("Exception caught: " + cause);

        HttpResponseStatus status = (cause instanceof BadRequestException) ? HttpResponseStatus.BAD_REQUEST :

                 HttpResponseStatus.INTERNAL_SERVER_ERROR;
