use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class SettableRpc method handle.
@Override
public Document handle(final Document requestMessage, final NetconfOperationChainedExecution subsequentOperation) throws DocumentedException {
final XmlElement requestElement = XmlElement.fromDomDocument(requestMessage);
final XmlElement rpcElement = requestElement.getOnlyChildElement();
final String msgId = requestElement.getAttribute(XmlNetconfConstants.MESSAGE_ID);
final Optional<Document> response = mapping.getResponse(rpcElement);
if (response.isPresent()) {
final Document document = response.get();
checkForError(document);
document.getDocumentElement().setAttribute(XmlNetconfConstants.MESSAGE_ID, msgId);
return document;
} else if (subsequentOperation.isExecutionTermination()) {
throw new DocumentedException("Mapping not found " + XmlUtil.toString(requestMessage), ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED, ErrorSeverity.ERROR);
} else {
return subsequentOperation.execute(requestMessage);
}
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class ProxyReadWriteTransactionTest method verifyDocumentedException.
private static void verifyDocumentedException(final Throwable cause) {
assertTrue("Unexpected cause " + cause, cause instanceof DocumentedException);
final DocumentedException de = (DocumentedException) cause;
assertEquals(ErrorSeverity.WARNING, de.getErrorSeverity());
assertEquals(ErrorTag.OPERATION_FAILED, de.getErrorTag());
assertEquals(ErrorType.APPLICATION, de.getErrorType());
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class ValidateTest method testSourceRunning.
@Test
public void testSourceRunning() throws Exception {
whenUsingValidator(noopValidator);
final DocumentedException e = assertThrows(DocumentedException.class, () -> validate("messages/mapping/validate/validate_running.xml"));
assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
assertEquals(ErrorTag.OPERATION_NOT_SUPPORTED, e.getErrorTag());
assertEquals(ErrorType.PROTOCOL, e.getErrorType());
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class ValidateTest method testSourceMissing.
@Test
public void testSourceMissing() throws Exception {
whenUsingValidator(noopValidator);
final DocumentedException e = assertThrows(DocumentedException.class, () -> validate("messages/mapping/validate/validate_no_source.xml"));
assertEquals(ErrorSeverity.ERROR, e.getErrorSeverity());
assertEquals(ErrorTag.MISSING_ELEMENT, e.getErrorTag());
assertEquals(ErrorType.PROTOCOL, e.getErrorType());
}
use of org.opendaylight.netconf.api.DocumentedException in project netconf by opendaylight.
the class GetSchema method handleWithNoSubsequentOperations.
@Override
protected Element handleWithNoSubsequentOperations(final Document document, final XmlElement xml) throws DocumentedException {
final GetSchemaEntry entry;
entry = new GetSchemaEntry(xml);
final String schema;
try {
schema = cap.getSchemaForCapability(entry.identifier, entry.version);
} catch (final IllegalStateException e) {
final Map<String, String> errorInfo = new HashMap<>();
// FIXME: so we have an <operation-failed>e.getMessage()</operation-failed> ??? In which namespace? Why?
errorInfo.put(ErrorTag.OPERATION_FAILED.elementBody(), e.getMessage());
LOG.warn("Rpc error: {}", ErrorTag.OPERATION_FAILED, e);
throw new DocumentedException(e.getMessage(), e, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, ErrorSeverity.ERROR, errorInfo);
}
final Element getSchemaResult;
getSchemaResult = XmlUtil.createTextElement(document, XmlNetconfConstants.DATA_KEY, schema, Optional.of(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_YANG_IETF_NETCONF_MONITORING));
LOG.trace("{} operation successful", GET_SCHEMA);
return getSchemaResult;
}
Aggregations