X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Futil%2Fmessages%2FSendErrorExceptionUtil.java;h=6604834fe42c02b3b3188fd7cd7f85c7b887ff3d;hp=fdcaa2a5b8c98616385231d5c6c8c0f7e39c0adc;hb=d206d27042eef2185c875f85cf6eac61a1bd77c4;hpb=87837c5398976e1f44418e9f161efea9d5fa4e7c 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 fdcaa2a5b8..6604834fe4 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 @@ -9,14 +9,15 @@ 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; -import org.opendaylight.controller.netconf.util.xml.XMLNetconfUtil; -import org.opendaylight.controller.netconf.util.xml.XmlNetconfConstants; +import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,12 +25,6 @@ import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import java.io.InputStream; -import java.util.Map.Entry; public final class SendErrorExceptionUtil { private static final Logger logger = LoggerFactory.getLogger(SendErrorExceptionUtil.class); @@ -64,12 +59,12 @@ public final class SendErrorExceptionUtil { final NetconfDocumentedException sendErrorException) { try { final Element incommingRpc = incommingDocument.getDocumentElement(); - Preconditions.checkState(incommingRpc.getTagName().equals(XmlNetconfConstants.RPC_KEY), "Missing " - + XmlNetconfConstants.RPC_KEY + " " + "element"); + Preconditions.checkState(incommingRpc.getTagName().equals(XmlNetconfConstants.RPC_KEY), "Missing %s element", + XmlNetconfConstants.RPC_KEY); final Element rpcReply = errorDocument.getDocumentElement(); - Preconditions.checkState(rpcReply.getTagName().equals(XmlNetconfConstants.RPC_REPLY_KEY), "Missing " - + XmlNetconfConstants.RPC_REPLY_KEY + " element"); + 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++) { @@ -86,56 +81,8 @@ public final class SendErrorExceptionUtil { } } - private static XPathExpression rpcErrorExpression = XMLNetconfUtil - .compileXPath("/netconf:rpc-reply/netconf:rpc-error"); - private static XPathExpression errorTypeExpression = XMLNetconfUtil.compileXPath("netconf:error-type"); - private static XPathExpression errorTagExpression = XMLNetconfUtil.compileXPath("netconf:error-tag"); - private static XPathExpression errorSeverityExpression = XMLNetconfUtil.compileXPath("netconf:error-severity"); - private static Document createDocument(final NetconfDocumentedException sendErrorException) { - - final InputStream errIS = SendErrorExceptionUtil.class.getResourceAsStream("server_error.xml"); - Document originalErrorDocument; - try { - originalErrorDocument = XmlUtil.readXmlToDocument(errIS); - } catch (final Exception e) { - throw new IllegalStateException(e); - } - - final Document errorDocument = XmlUtil.createDocumentCopy(originalErrorDocument); - final Node rootNode = errorDocument.getFirstChild(); - - final Node rpcErrorNode = (Node) XmlUtil.evaluateXPath(rpcErrorExpression, rootNode, XPathConstants.NODE); - - final Node errorTypeNode = (Node) XmlUtil.evaluateXPath(errorTypeExpression, rpcErrorNode, XPathConstants.NODE); - errorTypeNode.setTextContent(sendErrorException.getErrorType().getTagValue()); - - final Node errorTagNode = (Node) XmlUtil.evaluateXPath(errorTagExpression, rpcErrorNode, XPathConstants.NODE); - errorTagNode.setTextContent(sendErrorException.getErrorTag().getTagValue()); - - final Node errorSeverityNode = (Node) XmlUtil.evaluateXPath(errorSeverityExpression, rpcErrorNode, - XPathConstants.NODE); - errorSeverityNode.setTextContent(sendErrorException.getErrorSeverity().getTagValue()); - - if (sendErrorException.getErrorInfo() != null && !sendErrorException.getErrorInfo().isEmpty()) { - /* - * message-id - * rpc - */ - final Node errorInfoNode = errorDocument.createElementNS( - XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, "error-info"); - - errorInfoNode.setPrefix(rootNode.getPrefix()); - rpcErrorNode.appendChild(errorInfoNode); - for (final Entry errorInfoEntry : sendErrorException.getErrorInfo().entrySet()) { - final Node node = errorDocument.createElementNS( - XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, errorInfoEntry.getKey()); - node.setTextContent(errorInfoEntry.getValue()); - errorInfoNode.appendChild(node); - } - - } - return errorDocument; + return sendErrorException.toXMLDocument(); } /** @@ -150,7 +97,7 @@ public final class SendErrorExceptionUtil { @Override public void operationComplete(final ChannelFuture channelFuture) throws Exception { - Preconditions.checkState(channelFuture.isSuccess(), "Unable to send exception {}", sendErrorException, + Preconditions.checkState(channelFuture.isSuccess(), "Unable to send exception %s", sendErrorException, channelFuture.cause()); } }