Search in sources :

Example 31 with DocumentedException

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);
    }
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Document(org.w3c.dom.Document)

Example 32 with DocumentedException

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());
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException)

Example 33 with DocumentedException

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());
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) Test(org.junit.Test)

Example 34 with DocumentedException

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());
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) Test(org.junit.Test)

Example 35 with DocumentedException

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;
}
Also used : DocumentedException(org.opendaylight.netconf.api.DocumentedException) XmlElement(org.opendaylight.netconf.api.xml.XmlElement) Element(org.w3c.dom.Element) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DocumentedException (org.opendaylight.netconf.api.DocumentedException)54 Test (org.junit.Test)25 XmlElement (org.opendaylight.netconf.api.xml.XmlElement)14 Document (org.w3c.dom.Document)9 NetconfDocumentedException (org.opendaylight.netconf.api.NetconfDocumentedException)6 ExecutionException (java.util.concurrent.ExecutionException)5 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)5 Element (org.w3c.dom.Element)5 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)4 List (java.util.List)3 XMLNamespace (org.opendaylight.yangtools.yang.common.XMLNamespace)3 XmlNodeConverter (io.lighty.codecs.util.XmlNodeConverter)2 DeserializationException (io.lighty.codecs.util.exception.DeserializationException)2 Response (io.lighty.netconf.device.response.Response)2 ResponseData (io.lighty.netconf.device.response.ResponseData)2 Reader (java.io.Reader)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2