Remove unused exceptions
[netconf.git] / netconf / netconf-util / src / main / java / org / opendaylight / netconf / util / messages / SendErrorExceptionUtil.java
index 8b72bb836b90d61d78419dd659572c8c7e5bbf38..f89d2848ef3cae6f52d11a19b1ce5e2b4738b496 100644 (file)
@@ -12,12 +12,11 @@ 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.config.util.xml.DocumentedException;
-import org.opendaylight.controller.config.util.xml.XmlMappingConstants;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.netconf.api.DocumentedException;
 import org.opendaylight.netconf.api.NetconfMessage;
 import org.opendaylight.netconf.api.NetconfSession;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Attr;
@@ -34,15 +33,15 @@ public final class SendErrorExceptionUtil {
             final DocumentedException 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));
+        ChannelFuture channelFuture = session.sendMessage(new NetconfMessage(errorDocument));
+        channelFuture.addListener(new SendErrorVerifyingListener(sendErrorException));
     }
 
     public static void sendErrorMessage(final Channel channel, final DocumentedException 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));
+        ChannelFuture channelFuture = channel.writeAndFlush(new NetconfMessage(errorDocument));
+        channelFuture.addListener(new SendErrorVerifyingListener(sendErrorException));
     }
 
     public static void sendErrorMessage(final NetconfSession session, final DocumentedException sendErrorException,
@@ -53,20 +52,23 @@ public final class SendErrorExceptionUtil {
         }
 
         tryToCopyAttributes(incommingMessage.getDocument(), errorDocument, sendErrorException);
-        ChannelFuture f = session.sendMessage(new NetconfMessage(errorDocument));
-        f.addListener(new SendErrorVerifyingListener(sendErrorException));
+        ChannelFuture channelFuture = session.sendMessage(new NetconfMessage(errorDocument));
+        channelFuture.addListener(new SendErrorVerifyingListener(sendErrorException));
     }
 
+    @SuppressWarnings("checkstyle:IllegalCatch")
     private static void tryToCopyAttributes(final Document incommingDocument, final Document errorDocument,
             final DocumentedException sendErrorException) {
         try {
             final Element incommingRpc = incommingDocument.getDocumentElement();
-            Preconditions.checkState(incommingRpc.getTagName().equals(XmlNetconfConstants.RPC_KEY), "Missing %s element",
-                    XmlNetconfConstants.RPC_KEY);
+            Preconditions.checkState(
+                XmlNetconfConstants.RPC_KEY.equals(incommingRpc.getLocalName())
+                && XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0.equals(incommingRpc.getNamespaceURI()),
+                    "Missing %s element", XmlNetconfConstants.RPC_KEY);
 
             final Element rpcReply = errorDocument.getDocumentElement();
-            Preconditions.checkState(rpcReply.getTagName().equals(XmlMappingConstants.RPC_REPLY_KEY), "Missing %s element",
-                    XmlMappingConstants.RPC_REPLY_KEY);
+            Preconditions.checkState(rpcReply.getTagName().equals(XmlNetconfConstants.RPC_REPLY_KEY),
+                    "Missing %s element", XmlNetconfConstants.RPC_REPLY_KEY);
 
             final NamedNodeMap incomingAttributes = incommingRpc.getAttributes();
             for (int i = 0; i < incomingAttributes.getLength(); i++) {
@@ -93,12 +95,12 @@ public final class SendErrorExceptionUtil {
     private static final class SendErrorVerifyingListener implements ChannelFutureListener {
         private final DocumentedException sendErrorException;
 
-        public SendErrorVerifyingListener(final DocumentedException sendErrorException) {
+        SendErrorVerifyingListener(final DocumentedException sendErrorException) {
             this.sendErrorException = sendErrorException;
         }
 
         @Override
-        public void operationComplete(final ChannelFuture channelFuture) throws Exception {
+        public void operationComplete(final ChannelFuture channelFuture) {
             Preconditions.checkState(channelFuture.isSuccess(), "Unable to send exception %s", sendErrorException,
                     channelFuture.cause());
         }