import org.opendaylight.controller.config.util.xml.DocumentedException;
import org.opendaylight.controller.config.util.xml.XmlElement;
import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.opendaylight.netconf.api.FailedNetconfMessage;
import org.opendaylight.netconf.api.NetconfDocumentedException;
import org.opendaylight.netconf.api.NetconfMessage;
import org.opendaylight.netconf.notifications.NetconfNotification;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.data.api.ModifyAction;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
-public class NetconfMessageTransformUtil {
+public final class NetconfMessageTransformUtil {
private static final Logger LOG = LoggerFactory.getLogger(NetconfMessageTransformUtil.class);
final String inputMsgId = input.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
final String outputMsgId = output.getDocument().getDocumentElement().getAttribute(MESSAGE_ID_ATTR);
- if (inputMsgId.equals(outputMsgId) == false) {
+ if (!inputMsgId.equals(outputMsgId)) {
final Map<String, String> errorInfo = ImmutableMap.<String, String>builder()
.put("actual-message-id", outputMsgId)
.put("expected-message-id", inputMsgId)
} else {
final Entry<QName, ModifyAction> modifyOperation = operation.isPresent()
? new AbstractMap.SimpleEntry<>(NETCONF_OPERATION_QNAME, operation.get()) : null;
- configContent = ImmutableNodes
- .fromInstanceId(ctx, dataPath, lastChildOverride, Optional.fromNullable(modifyOperation));
+ configContent = ImmutableNodes.fromInstanceId(ctx, dataPath, lastChildOverride.toJavaUtil(),
+ java.util.Optional.ofNullable(modifyOperation));
}
final Element element = XmlUtil.createElement(BLANK_DOCUMENT, NETCONF_CONFIG_QNAME.getLocalName(),
NetconfNotification.RFC3339_DATE_PARSER.apply(eventTimeElement.getTextContent()),
notificationElement);
} catch (final DocumentedException e) {
- throw new IllegalArgumentException("Notification payload does not contain " + EVENT_TIME + " " + message);
+ throw new IllegalArgumentException("Notification payload does not contain " + EVENT_TIME + " " + message,
+ e);
} catch (final DateTimeParseException e) {
LOG.warn("Unable to parse event time from {}. Setting time to {}", eventTimeElement,
NetconfNotification.UNKNOWN_EVENT_TIME, e);
}
}
}
+
+ public static RpcResult<NetconfMessage> toRpcResult(final FailedNetconfMessage message) {
+ return RpcResultBuilder.<NetconfMessage>failed()
+ .withRpcError(
+ toRpcError(
+ new NetconfDocumentedException(
+ message.getException().getMessage(),
+ DocumentedException.ErrorType.APPLICATION,
+ DocumentedException.ErrorTag.MALFORMED_MESSAGE,
+ DocumentedException.ErrorSeverity.ERROR)))
+ .build();
+ }
}