Search in sources :

Example 6 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project cdap by caskdata.

the class HttpRequestHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    Throwable cause = e.getCause();
    // avoid handling exception more than once from a handler, to avoid a possible infinite recursion
    switch(exceptionsHandled.incrementAndGet()) {
        case 1:
            // if this is the first error, break and handle the error normally (below)
            break;
        case 2:
            // if its the second time, log and return
            LOG.error("Not handling exception due to already having handled an exception in Request Handler {}", ctx.getChannel(), cause);
        // fall through
        default:
            // in an exception and cause recursion
            return;
    }
    if (cause instanceof HandlerException && ((HandlerException) cause).getFailureStatus() != HttpResponseStatus.INTERNAL_SERVER_ERROR) {
        LOG.debug("Exception raised in Request Handler {}", ctx.getChannel(), cause);
    } else {
        LOG.error("Exception raised in Request Handler {}", ctx.getChannel(), cause);
    }
    if (ctx.getChannel().isConnected() && !channelClosed) {
        HttpResponse response = cause instanceof HandlerException ? ((HandlerException) cause).createFailureResponse() : new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
        Channels.write(ctx, e.getFuture(), response);
        e.getFuture().addListener(ChannelFutureListener.CLOSE);
    }
}
Also used : HandlerException(co.cask.cdap.common.HandlerException) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse)

Example 7 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project cdap by caskdata.

the class AuthenticationChannelHandler method exceptionCaught.

@Override
public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) {
    LOG.error("Got exception: ", e.getCause());
    ChannelFuture future = Channels.future(ctx.getChannel());
    future.addListener(ChannelFutureListener.CLOSE);
    // TODO: add WWW-Authenticate header for 401 response -  REACTOR-900
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.UNAUTHORIZED);
    Channels.write(ctx, future, response);
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse)

Example 8 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project traccar by traccar.

the class Mta6ProtocolDecoder method sendResponse.

private void sendResponse(Channel channel, short packetId, short packetCount) {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    ChannelBuffer begin = ChannelBuffers.copiedBuffer("#ACK#", StandardCharsets.US_ASCII);
    ChannelBuffer end = ChannelBuffers.directBuffer(3);
    end.writeByte(packetId);
    end.writeByte(packetCount);
    end.writeByte(0);
    response.setContent(ChannelBuffers.wrappedBuffer(begin, end));
    channel.write(response);
}
Also used : DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer)

Example 9 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project traccar by traccar.

the class Mta6ProtocolDecoder method sendContinue.

private void sendContinue(Channel channel) {
    HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE);
    channel.write(response);
}
Also used : DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse)

Example 10 with DefaultHttpResponse

use of org.jboss.netty.handler.codec.http.DefaultHttpResponse in project traccar by traccar.

the class PathAwayProtocolDecoder method decode.

@Override
protected Object decode(Channel channel, SocketAddress remoteAddress, Object msg) throws Exception {
    HttpRequest request = (HttpRequest) msg;
    QueryStringDecoder decoder = new QueryStringDecoder(request.getUri());
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, decoder.getParameters().get("UserName").get(0));
    if (deviceSession == null) {
        return null;
    }
    Parser parser = new Parser(PATTERN, decoder.getParameters().get("LOC").get(0));
    if (!parser.matches()) {
        return null;
    }
    Position position = new Position(getProtocolName());
    position.setDeviceId(deviceSession.getDeviceId());
    position.setTime(parser.nextDateTime(Parser.DateTimeFormat.DMY_HMS));
    position.setValid(true);
    position.setLatitude(parser.nextDouble(0));
    position.setLongitude(parser.nextDouble(0));
    position.setAltitude(parser.nextDouble(0));
    position.setSpeed(parser.nextDouble(0));
    position.setCourse(parser.nextDouble(0));
    if (channel != null) {
        HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        channel.write(response).addListener(ChannelFutureListener.CLOSE);
    }
    return position;
}
Also used : HttpRequest(org.jboss.netty.handler.codec.http.HttpRequest) QueryStringDecoder(org.jboss.netty.handler.codec.http.QueryStringDecoder) DeviceSession(org.traccar.DeviceSession) Position(org.traccar.model.Position) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpResponse(org.jboss.netty.handler.codec.http.HttpResponse) Parser(org.traccar.helper.Parser)

Aggregations

DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)146 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)113 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)67 DefaultHttpChunk (org.jboss.netty.handler.codec.http.DefaultHttpChunk)58 Test (org.testng.annotations.Test)54 HttpChunk (org.jboss.netty.handler.codec.http.HttpChunk)51 DefaultHttpChunkTrailer (org.jboss.netty.handler.codec.http.DefaultHttpChunkTrailer)38 HttpChunkTrailer (org.jboss.netty.handler.codec.http.HttpChunkTrailer)34 ChannelFuture (org.jboss.netty.channel.ChannelFuture)33 Test (org.junit.Test)32 Checkpoint (com.linkedin.databus.core.Checkpoint)25 BootstrapDatabaseTooOldException (com.linkedin.databus2.core.container.request.BootstrapDatabaseTooOldException)25 DefaultHttpRequest (org.jboss.netty.handler.codec.http.DefaultHttpRequest)23 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)23 Channel (org.jboss.netty.channel.Channel)21 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)18 InetSocketAddress (java.net.InetSocketAddress)17 SocketAddress (java.net.SocketAddress)17 Logger (org.apache.log4j.Logger)15 SucceededChannelFuture (org.jboss.netty.channel.SucceededChannelFuture)10