X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=netconf%2Fnetconf-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetconf%2Fimpl%2Fosgi%2FNetconfOperationRouterImpl.java;h=b1ab4b26de966af71f94fdeb8019d8eed1ebf04e;hb=a33c5a6dce59e7fde138a873500861b06116b3bc;hp=7dd0c2ad6b74d336732d7fb964b8edd4ae324f9a;hpb=276fb1df2ffee67a9ee7fb5e7c9a78d1cb62bdc8;p=netconf.git diff --git a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java index 7dd0c2ad6b..b1ab4b26de 100644 --- a/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java +++ b/netconf/netconf-impl/src/main/java/org/opendaylight/netconf/impl/osgi/NetconfOperationRouterImpl.java @@ -31,6 +31,7 @@ import org.opendaylight.netconf.mapping.api.NetconfOperationChainedExecution; import org.opendaylight.netconf.mapping.api.NetconfOperationService; import org.opendaylight.netconf.mapping.api.SessionAwareNetconfOperation; import org.opendaylight.yangtools.yang.common.ErrorSeverity; +import org.opendaylight.yangtools.yang.common.ErrorTag; import org.opendaylight.yangtools.yang.common.ErrorType; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,16 +70,31 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { final String messageAsString = XmlUtil.toString(message); LOG.warn("Unable to handle rpc {} on session {}", messageAsString, session, e); - final DocumentedException.ErrorTag tag; - if (e instanceof IllegalArgumentException) { - tag = DocumentedException.ErrorTag.OPERATION_NOT_SUPPORTED; - } else { - tag = DocumentedException.ErrorTag.OPERATION_FAILED; - } + final ErrorTag tag = e instanceof IllegalArgumentException ? ErrorTag.OPERATION_NOT_SUPPORTED + : ErrorTag.OPERATION_FAILED; throw new DocumentedException( - String.format("Unable to handle rpc %s on session %s", messageAsString, session), - e, ErrorType.APPLICATION, tag, ErrorSeverity.ERROR, Map.of(tag.toString(), e.getMessage())); + String.format("Unable to handle rpc %s on session %s", messageAsString, session), e, + ErrorType.APPLICATION, tag, ErrorSeverity.ERROR, + // FIXME: i.e. in what namespace are we providing these tags? why is this not just: + // + // + // e.getMessage() + // + // + // for each place where we are mapping Exception.getMessage() ? We probably do not want to propagate + // stack traces out, but suppressed exceptions and causal list might be interesting: + // + // + // reported exception + // + // + // cause of reported exception + // + // + // cause of cause of reported exception + // + Map.of(tag.elementBody(), e.getMessage())); } catch (final RuntimeException e) { throw handleUnexpectedEx("sort", e); } @@ -98,8 +114,9 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { private static DocumentedException handleUnexpectedEx(final String op, final Exception exception) { LOG.error("Unexpected exception during netconf operation {}", op, exception); return new DocumentedException("Unexpected error", - ErrorType.APPLICATION, DocumentedException.ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, - Map.of(ErrorSeverity.ERROR.toString(), exception.toString())); + ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, + // FIXME: i.e. exception.toString()? That looks wrong on a few levels. + Map.of(ErrorSeverity.ERROR.elementBody(), exception.toString())); } private static Document executeOperationWithHighestPriority(final Document message, @@ -133,11 +150,11 @@ public class NetconfOperationRouterImpl implements NetconfOperationRouter { for (final NetconfOperation netconfOperation : allNetconfOperations) { final HandlingPriority handlingPriority = netconfOperation.canHandle(message); - if (netconfOperation instanceof DefaultNetconfOperation) { - ((DefaultNetconfOperation) netconfOperation).setNetconfSession(session); + if (netconfOperation instanceof DefaultNetconfOperation defaultOperation) { + defaultOperation.setNetconfSession(session); } - if (netconfOperation instanceof SessionAwareNetconfOperation) { - ((SessionAwareNetconfOperation) netconfOperation).setSession(session); + if (netconfOperation instanceof SessionAwareNetconfOperation sessionAwareOperation) { + sessionAwareOperation.setSession(session); } if (!handlingPriority.equals(HandlingPriority.CANNOT_HANDLE)) {