+ NetconfOperationExecution netconfOperationExecution;
+
+ String messageAsString = XmlUtil.toString(message);
+
+ try {
+ netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session);
+ } catch (IllegalArgumentException | IllegalStateException e) {
+ logger.warn("Unable to handle rpc {} on session {}", messageAsString, session, e);
+
+ String errorMessage = String.format("Unable to handle rpc %s on session %s", messageAsString, session);
+ Map<String, String> errorInfo = Maps.newHashMap();
+
+ NetconfDocumentedException.ErrorTag tag = null;
+ if (e instanceof IllegalArgumentException) {
+ errorInfo.put(NetconfDocumentedException.ErrorTag.operation_not_supported.toString(), e.getMessage());
+ tag = NetconfDocumentedException.ErrorTag.operation_not_supported;
+ } else if (e instanceof IllegalStateException) {
+ errorInfo.put(NetconfDocumentedException.ErrorTag.operation_failed.toString(), e.getMessage());
+ tag = NetconfDocumentedException.ErrorTag.operation_failed;
+ }
+
+ throw new NetconfDocumentedException(errorMessage, e, NetconfDocumentedException.ErrorType.application,
+ tag, NetconfDocumentedException.ErrorSeverity.error, errorInfo);
+ } catch (RuntimeException e) {
+ throw handleUnexpectedEx("Unexpected exception during netconf operation sort", e);
+ }
+
+ try {
+ return executeOperationWithHighestPriority(message, netconfOperationExecution, messageAsString);
+ } catch (RuntimeException e) {
+ throw handleUnexpectedEx("Unexpected exception during netconf operation execution", e);
+ }
+ }
+
+ private NetconfDocumentedException handleUnexpectedEx(String s, Exception e) throws NetconfDocumentedException {
+ logger.error(s, e);
+
+ Map<String, String> info = Maps.newHashMap();
+ info.put(NetconfDocumentedException.ErrorSeverity.error.toString(), e.toString());
+ return new NetconfDocumentedException("Unexpected error",
+ NetconfDocumentedException.ErrorType.application,
+ NetconfDocumentedException.ErrorTag.operation_failed,
+ NetconfDocumentedException.ErrorSeverity.error, info);
+ }
+
+ private Document executeOperationWithHighestPriority(Document message, NetconfOperationExecution netconfOperationExecution, String messageAsString) throws NetconfDocumentedException {
+ logger.debug("Forwarding netconf message {} to {}", messageAsString,