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);
}
}
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);
}
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);
}
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);
}
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;
}
Aggregations