use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class SchemalessRpcStructureTransformer method checkKeyValuesValidForPath.
private static void checkKeyValuesValidForPath(final XmlElement dataElement, final PathArgument lastPathArgument) {
final NodeIdentifierWithPredicates keyedId = (NodeIdentifierWithPredicates) lastPathArgument;
for (Entry<QName, Object> entry : keyedId.entrySet()) {
QName qualifiedName = entry.getKey();
final List<XmlElement> key = dataElement.getChildElementsWithinNamespace(qualifiedName.getLocalName(), qualifiedName.getNamespace().toString());
if (key.isEmpty()) {
throw new IllegalStateException("No key present in xml");
}
if (key.size() > 1) {
throw new IllegalStateException("Multiple values for same key present");
}
final String textContent;
try {
textContent = key.get(0).getTextContent();
} catch (DocumentedException e) {
throw new IllegalStateException("Key value not present in key element", e);
}
if (!entry.getValue().equals(textContent)) {
throw new IllegalStateException("Key value in path not equal to key value in xml");
}
}
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class DefaultCloseSessionTest method testDefaultCloseSession2.
@Test
public void testDefaultCloseSession2() throws Exception {
final NetconfDocumentedException expectedCause = new NetconfDocumentedException("testMessage");
final AutoCloseable res = mock(AutoCloseable.class);
doThrow(expectedCause).when(res).close();
final DefaultCloseSession session = new DefaultCloseSession("testSession", res);
XmlElement elem = XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"));
final DocumentedException ex = assertThrows(DocumentedException.class, () -> session.handleWithNoSubsequentOperations(XmlUtil.newDocument(), elem));
assertEquals("Unable to properly close session testSession", ex.getMessage());
assertSame(expectedCause, ex.getCause());
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class NetconfOperationRouterImplTest method testOnNetconfMessageFail.
@Test
public void testOnNetconfMessageFail() throws Exception {
final DocumentedException ex = assertThrows(DocumentedException.class, () -> emptyOperationRouter.onNetconfMessage(TEST_RPC_DOC, null));
assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, ex.getErrorTag());
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class NetconfOperationRouterImpl method onNetconfMessage.
@SuppressWarnings("checkstyle:IllegalCatch")
@Override
public Document onNetconfMessage(final Document message, final NetconfServerSession session) throws DocumentedException {
requireNonNull(allNetconfOperations, "Operation router was not initialized properly");
final NetconfOperationExecution netconfOperationExecution;
try {
netconfOperationExecution = getNetconfOperationWithHighestPriority(message, session);
} catch (IllegalArgumentException | IllegalStateException e) {
final String messageAsString = XmlUtil.toString(message);
LOG.warn("Unable to handle rpc {} on session {}", messageAsString, session, e);
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, // </java-throwable>
Map.of(tag.elementBody(), e.getMessage()));
} catch (final RuntimeException e) {
throw handleUnexpectedEx("sort", e);
}
try {
return executeOperationWithHighestPriority(message, netconfOperationExecution);
} catch (final RuntimeException e) {
throw handleUnexpectedEx("execution", e);
}
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class DeserializerExceptionHandler method handleDeserializerException.
private static void handleDeserializerException(final ChannelHandlerContext ctx, final Throwable cause) {
final String message = cause.getMessage();
SendErrorExceptionUtil.sendErrorMessage(ctx.channel(), new DocumentedException(message, ErrorType.RPC, ErrorTag.MALFORMED_MESSAGE, ErrorSeverity.ERROR, message != null ? Map.of("cause", message) : Map.of()));
}
Aggregations