public static void sendErrorMessage(final Channel channel, final NetconfDocumentedException sendErrorException) { LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); ChannelFuture f = channel.writeAndFlush(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); }
private void handleDeserializerException(ChannelHandlerContext ctx, Throwable cause) { Map<String, String> info = Maps.newHashMap(); info.put("cause", cause.getMessage()); NetconfDocumentedException ex = new NetconfDocumentedException(cause.getMessage(), NetconfDocumentedException.ErrorType.rpc, NetconfDocumentedException.ErrorTag.malformed_message, NetconfDocumentedException.ErrorSeverity.error, info); SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), ex); } }
public static void sendErrorMessage(final NetconfSession session, final NetconfDocumentedException sendErrorException, final NetconfMessage incommingMessage) { final Document errorDocument = createDocument(sendErrorException); if (LOG.isTraceEnabled()) { LOG.trace("Sending error {}", XmlUtil.toString(errorDocument)); } tryToCopyAttributes(incommingMessage.getDocument(), errorDocument, sendErrorException); ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); }
public static void sendErrorMessage(final NetconfSession session, final NetconfDocumentedException sendErrorException) { LOG.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); f.addListener(new SendErrorVerifyingListener(sendErrorException)); }
@Override public void onMessage(final NetconfServerSession session, final NetconfMessage netconfMessage) { try { Preconditions.checkState(operationRouter != null, "Cannot handle message, session up was not yet received"); // FIXME: there is no validation since the document may contain yang // schemas final NetconfMessage message = processDocument(netconfMessage, session); LOG.debug("Responding with message {}", message); session.sendMessage(message); } catch (final RuntimeException e) { // TODO: should send generic error or close session? LOG.error("Unexpected exception", e); session.onIncommingRpcFail(); throw new IllegalStateException("Unable to process incoming message " + netconfMessage, e); } catch (NetconfDocumentedException e) { LOG.trace("Error occurred while processing message",e); session.onOutgoingRpcError(); session.onIncommingRpcFail(); SendErrorExceptionUtil.sendErrorMessage(session, e, netconfMessage); } }