X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fmessages%2FSendErrorExceptionUtil.java;h=fdcaa2a5b8c98616385231d5c6c8c0f7e39c0adc;hb=2f034183cfcbaacf2a287f1ddf00d367674868af;hp=de2d6d7e0c354ada3bcf1fb4f1b630b186c34e3c;hpb=8f15fef884bc20239625850c4a2fcdaf36395526;p=controller.git diff --git a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java index de2d6d7e0c..fdcaa2a5b8 100644 --- a/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java +++ b/opendaylight/netconf/netconf-util/src/main/java/org/opendaylight/controller/netconf/util/messages/SendErrorExceptionUtil.java @@ -10,6 +10,8 @@ package org.opendaylight.controller.netconf.util.messages; import com.google.common.base.Preconditions; import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; import org.opendaylight.controller.netconf.api.NetconfSession; import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; @@ -38,13 +40,15 @@ public final class SendErrorExceptionUtil { final NetconfDocumentedException sendErrorException) { logger.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); - session.sendMessage(new NetconfMessage(errorDocument)); + ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); + f.addListener(new SendErrorVerifyingListener(sendErrorException)); } public static void sendErrorMessage(Channel channel, NetconfDocumentedException sendErrorException) { logger.trace("Sending error {}", sendErrorException.getMessage(), sendErrorException); final Document errorDocument = createDocument(sendErrorException); - channel.writeAndFlush(new NetconfMessage(errorDocument)); + ChannelFuture f = channel.writeAndFlush(new NetconfMessage(errorDocument)); + f.addListener(new SendErrorVerifyingListener(sendErrorException)); } public static void sendErrorMessage(NetconfSession session, NetconfDocumentedException sendErrorException, @@ -52,7 +56,8 @@ public final class SendErrorExceptionUtil { final Document errorDocument = createDocument(sendErrorException); logger.trace("Sending error {}", XmlUtil.toString(errorDocument)); tryToCopyAttributes(incommingMessage.getDocument(), errorDocument, sendErrorException); - session.sendMessage(new NetconfMessage(errorDocument)); + ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument)); + f.addListener(new SendErrorVerifyingListener(sendErrorException)); } private static void tryToCopyAttributes(final Document incommingDocument, final Document errorDocument, @@ -112,7 +117,7 @@ public final class SendErrorExceptionUtil { XPathConstants.NODE); errorSeverityNode.setTextContent(sendErrorException.getErrorSeverity().getTagValue()); - if (sendErrorException.getErrorInfo() != null && sendErrorException.getErrorInfo().isEmpty() == false) { + if (sendErrorException.getErrorInfo() != null && !sendErrorException.getErrorInfo().isEmpty()) { /* * message-id * rpc @@ -133,4 +138,20 @@ public final class SendErrorExceptionUtil { return errorDocument; } + /** + * Checks if netconf error was sent successfully. + */ + private static final class SendErrorVerifyingListener implements ChannelFutureListener { + private final NetconfDocumentedException sendErrorException; + + public SendErrorVerifyingListener(final NetconfDocumentedException sendErrorException) { + this.sendErrorException = sendErrorException; + } + + @Override + public void operationComplete(final ChannelFuture channelFuture) throws Exception { + Preconditions.checkState(channelFuture.isSuccess(), "Unable to send exception {}", sendErrorException, + channelFuture.cause()); + } + } }