@Test public void testSendErrorMessageExceptionHandling() throws Exception { when(connection.getChannelHandlerContext(SxpConnection.ChannelHandlerContextType.SPEAKER_CNTXT)) .thenThrow(ChannelHandlerContextNotFoundException.class); MessageDecoder.sendErrorMessage(null, new ErrorMessageException(ErrorCodeNonExtended.NoError, new Exception()), connection); verify(channelHandlerContext, never()).close(); }
public static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException, SxpConnection connection) { ByteBuf message = null; try { if (messageValidationException.isLegacy()) { message = LegacyMessageFactory.createError(messageValidationException.getErrorCodeNonExtended(), null); } else { message = MessageFactory.createError(messageValidationException.getErrorCode(), messageValidationException.getErrorSubCode(), messageValidationException.getData()); } if (ctx == null) { ctx = connection.getChannelHandlerContext(ChannelHandlerContextType.SPEAKER_CNTXT); } } catch (ErrorCodeDataLengthException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); return; } catch (ChannelHandlerContextNotFoundException | ChannelHandlerContextDiscrepancyException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); if (message != null) { message.release(); } return; } LOG.info("{} Sent ERROR {}", connection, MessageFactory.toString(message)); ctx.writeAndFlush(message); ctx.close(); }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { public static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException, SxpConnection connection) { ByteBuf message = null; try { if (messageValidationException.isLegacy()) { message = LegacyMessageFactory.createError(messageValidationException.getErrorCodeNonExtended(), null); } else { message = MessageFactory.createError(messageValidationException.getErrorCode(), messageValidationException.getErrorSubCode(), messageValidationException.getData()); } if (ctx == null) { ctx = connection.getChannelHandlerContext(ChannelHandlerContextType.SPEAKER_CNTXT); } } catch (ErrorCodeDataLengthException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); return; } catch (ChannelHandlerContextNotFoundException | ChannelHandlerContextDiscrepancyException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); if (message != null) { message.release(); } return; } LOG.info("{} Sent ERROR {}", connection, MessageFactory.toString(message)); ctx.writeAndFlush(message); ctx.close(); } }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { public static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException, SxpConnection connection) { ByteBuf message = null; try { if (messageValidationException.isLegacy()) { message = LegacyMessageFactory.createError(messageValidationException.getErrorCodeNonExtended(), null); } else { message = MessageFactory.createError(messageValidationException.getErrorCode(), messageValidationException.getErrorSubCode(), messageValidationException.getData()); } if (ctx == null) { ctx = connection.getChannelHandlerContext(ChannelHandlerContextType.SPEAKER_CNTXT); } } catch (ErrorCodeDataLengthException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); return; } catch (ChannelHandlerContextNotFoundException | ChannelHandlerContextDiscrepancyException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); if (message != null) { message.release(); } return; } LOG.info("{} Sent ERROR {}", connection, MessageFactory.toString(message)); ctx.writeAndFlush(message); ctx.close(); } private  MessageDecoder(SxpNode owner, Profile profile); }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { public static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException, SxpConnection connection) { ByteBuf message = null; try { if (messageValidationException.isLegacy()) { message = LegacyMessageFactory.createError(messageValidationException.getErrorCodeNonExtended(), null); } else { message = MessageFactory.createError(messageValidationException.getErrorCode(), messageValidationException.getErrorSubCode(), messageValidationException.getData()); } if (ctx == null) { ctx = connection.getChannelHandlerContext(ChannelHandlerContextType.SPEAKER_CNTXT); } } catch (ErrorCodeDataLengthException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); return; } catch (ChannelHandlerContextNotFoundException | ChannelHandlerContextDiscrepancyException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); if (message != null) { message.release(); } return; } LOG.info("{} Sent ERROR {}", connection, MessageFactory.toString(message)); ctx.writeAndFlush(message); ctx.close(); } private  MessageDecoder(SxpNode owner, Profile profile); static ChannelInboundHandler createClientProfile(SxpNode owner); static ChannelInboundHandler createServerProfile(SxpNode owner); static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException,
            SxpConnection connection); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelRead0(ChannelHandlerContext ctx, ByteBuf message); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); }
MessageDecoder extends SimpleChannelInboundHandler<ByteBuf> { public static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException, SxpConnection connection) { ByteBuf message = null; try { if (messageValidationException.isLegacy()) { message = LegacyMessageFactory.createError(messageValidationException.getErrorCodeNonExtended(), null); } else { message = MessageFactory.createError(messageValidationException.getErrorCode(), messageValidationException.getErrorSubCode(), messageValidationException.getData()); } if (ctx == null) { ctx = connection.getChannelHandlerContext(ChannelHandlerContextType.SPEAKER_CNTXT); } } catch (ErrorCodeDataLengthException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); return; } catch (ChannelHandlerContextNotFoundException | ChannelHandlerContextDiscrepancyException e) { LOG.info("{} ERROR sending Error {}", connection, messageValidationException, e); if (message != null) { message.release(); } return; } LOG.info("{} Sent ERROR {}", connection, MessageFactory.toString(message)); ctx.writeAndFlush(message); ctx.close(); } private  MessageDecoder(SxpNode owner, Profile profile); static ChannelInboundHandler createClientProfile(SxpNode owner); static ChannelInboundHandler createServerProfile(SxpNode owner); static void sendErrorMessage(ChannelHandlerContext ctx, ErrorMessageException messageValidationException,
            SxpConnection connection); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void channelRead0(ChannelHandlerContext ctx, ByteBuf message); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }