- final XmlCodecProvider codecProvider = XmlDocumentUtils.defaultValueCodecProvider();
- if(schemaContext.isPresent()) {
- if (NetconfMessageTransformUtil.isDataEditOperation(rpc)) {
- final DataNodeContainer schemaForEdit = NetconfMessageTransformUtil.createSchemaForEdit(schemaContext.get());
- w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForEdit, codecProvider);
- } else if (NetconfMessageTransformUtil.isGetOperation(rpc)) {
- final DataNodeContainer schemaForGet = NetconfMessageTransformUtil.createSchemaForGet(schemaContext.get());
- w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForGet, codecProvider);
- } else if (NetconfMessageTransformUtil.isGetConfigOperation(rpc)) {
- final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForGetConfig(schemaContext.get());
- w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForGetConfig, codecProvider);
- } else {
- final Optional<RpcDefinition> schemaForRpc = NetconfMessageTransformUtil.findSchemaForRpc(rpc, schemaContext.get());
- if(schemaForRpc.isPresent()) {
- final DataNodeContainer schemaForGetConfig = NetconfMessageTransformUtil.createSchemaForRpc(schemaForRpc.get());
- w3cPayload = XmlDocumentUtils.toDocument(rpcPayload, schemaContext.get(), schemaForGetConfig, codecProvider);
- } else {
- w3cPayload = toRpcRequestWithoutSchema(rpcPayload, codecProvider);
- }
- }
- } else {
- w3cPayload = toRpcRequestWithoutSchema(rpcPayload, codecProvider);
- }
- } catch (final UnsupportedDataTypeException e) {
- throw new IllegalArgumentException("Unable to create message", e);
+ writeNormalizedRpc(payload, result, rpc, schemaContext);
+ } catch (final XMLStreamException | IOException | IllegalStateException e) {
+ throw new IllegalStateException("Unable to serialize " + rpc, e);