Eliminate NormalizedNodePayload
[netconf.git] / restconf / restconf-nb / src / main / java / org / opendaylight / restconf / nb / jaxrs / JaxRsRestconf.java
index d593a6ccbd34f0bd09665704dfd2f237dbb3dd56..8e8135ad4ef4d803d8a79d46d6aadaa66170e2cc 100644 (file)
@@ -17,8 +17,8 @@ import java.lang.reflect.Type;
 import java.text.ParseException;
 import java.util.Date;
 import java.util.List;
-import java.util.function.Function;
 import javax.inject.Singleton;
+import javax.ws.rs.BadRequestException;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.Encoded;
@@ -38,43 +38,47 @@ import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
-import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.ext.ParamConverter;
 import javax.ws.rs.ext.ParamConverterProvider;
 import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.restconf.api.ApiPath;
+import org.opendaylight.restconf.api.FormattableBody;
+import org.opendaylight.restconf.api.HttpStatusCode;
 import org.opendaylight.restconf.api.MediaTypes;
+import org.opendaylight.restconf.api.QueryParameters;
+import org.opendaylight.restconf.api.query.PrettyPrintParam;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.errors.RestconfFuture;
-import org.opendaylight.restconf.common.patch.PatchStatusContext;
+import org.opendaylight.restconf.nb.rfc8040.ErrorTagMapping;
 import org.opendaylight.restconf.nb.rfc8040.URLConstants;
-import org.opendaylight.restconf.nb.rfc8040.databind.JsonChildBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.JsonDataPostBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.JsonOperationInputBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.JsonPatchBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.JsonResourceBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.OperationInputBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.XmlChildBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.XmlDataPostBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.XmlOperationInputBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.XmlPatchBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.XmlResourceBody;
-import org.opendaylight.restconf.nb.rfc8040.databind.jaxrs.QueryParams;
-import org.opendaylight.restconf.nb.rfc8040.legacy.ErrorTags;
-import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.server.api.ConfigurationMetadata;
+import org.opendaylight.restconf.server.api.CreateResourceResult;
 import org.opendaylight.restconf.server.api.DataGetResult;
+import org.opendaylight.restconf.server.api.DataPatchResult;
 import org.opendaylight.restconf.server.api.DataPostResult;
-import org.opendaylight.restconf.server.api.DataPostResult.CreateResource;
-import org.opendaylight.restconf.server.api.DataPostResult.InvokeOperation;
 import org.opendaylight.restconf.server.api.DataPutResult;
+import org.opendaylight.restconf.server.api.DataYangPatchResult;
+import org.opendaylight.restconf.server.api.InvokeResult;
+import org.opendaylight.restconf.server.api.JsonChildBody;
+import org.opendaylight.restconf.server.api.JsonDataPostBody;
+import org.opendaylight.restconf.server.api.JsonOperationInputBody;
+import org.opendaylight.restconf.server.api.JsonPatchBody;
+import org.opendaylight.restconf.server.api.JsonResourceBody;
 import org.opendaylight.restconf.server.api.ModulesGetResult;
-import org.opendaylight.restconf.server.api.OperationsGetResult;
-import org.opendaylight.restconf.server.api.OperationsPostResult;
+import org.opendaylight.restconf.server.api.OperationInputBody;
+import org.opendaylight.restconf.server.api.PatchStatusContext;
 import org.opendaylight.restconf.server.api.RestconfServer;
+import org.opendaylight.restconf.server.api.ServerRequest;
+import org.opendaylight.restconf.server.api.XmlChildBody;
+import org.opendaylight.restconf.server.api.XmlDataPostBody;
+import org.opendaylight.restconf.server.api.XmlOperationInputBody;
+import org.opendaylight.restconf.server.api.XmlPatchBody;
+import org.opendaylight.restconf.server.api.XmlResourceBody;
+import org.opendaylight.restconf.server.spi.YangPatchStatusBody;
 import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.YangConstants;
 import org.slf4j.Logger;
@@ -114,10 +118,32 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         }
     };
 
-    private final RestconfServer server;
+    private final @NonNull RestconfServer server;
+    private final @NonNull ServerRequest emptyRequest;
+    private final @NonNull PrettyPrintParam prettyPrint;
+    private final @NonNull ErrorTagMapping errorTagMapping;
 
-    public JaxRsRestconf(final RestconfServer server) {
+    public JaxRsRestconf(final RestconfServer server, final ErrorTagMapping errorTagMapping,
+            final PrettyPrintParam prettyPrint) {
         this.server = requireNonNull(server);
+        this.errorTagMapping = requireNonNull(errorTagMapping);
+        this.prettyPrint = requireNonNull(prettyPrint);
+        emptyRequest = ServerRequest.of(QueryParameters.of(), prettyPrint);
+
+        LOG.info("RESTCONF data-missing condition is reported as HTTP status {}", switch (errorTagMapping) {
+            case ERRATA_5565 -> "404 (Errata 5565)";
+            case RFC8040 -> "409 (RFC8040)";
+        });
+    }
+
+    private @NonNull ServerRequest requestOf(final UriInfo uriInfo) {
+        final QueryParameters params;
+        try {
+            params = QueryParameters.ofMultiValue(uriInfo.getQueryParameters());
+        } catch (IllegalArgumentException e) {
+            throw new BadRequestException(e.getMessage(), e);
+        }
+        return params.isEmpty() ? emptyRequest : ServerRequest.of(params, prettyPrint);
     }
 
     @Override
@@ -138,7 +164,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     @SuppressWarnings("checkstyle:abbreviationAsWordInName")
     public void dataDELETE(@Encoded @PathParam("identifier") final ApiPath identifier,
             @Suspended final AsyncResponse ar) {
-        server.dataDELETE(identifier).addCallback(new JaxRsRestconfCallback<>(ar) {
+        server.dataDELETE(emptyRequest, identifier).addCallback(new JaxRsRestconfCallback<>(ar) {
             @Override
             Response transform(final Empty result) {
                 return Response.noContent().build();
@@ -162,7 +188,8 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaType.TEXT_XML
     })
     public void dataGET(@Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
-        completeDataGET(server.dataGET(QueryParams.newDataGetParams(uriInfo)), ar);
+        final var request = requestOf(uriInfo);
+        completeDataGET(server.dataGET(request), request.prettyPrint(), ar);
     }
 
     /**
@@ -183,15 +210,18 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void dataGET(@Encoded @PathParam("identifier") final ApiPath identifier, @Context final UriInfo uriInfo,
             @Suspended final AsyncResponse ar) {
-        completeDataGET(server.dataGET(identifier, QueryParams.newDataGetParams(uriInfo)), ar);
+        final var request = requestOf(uriInfo);
+        completeDataGET(server.dataGET(request, identifier), request.prettyPrint(), ar);
     }
 
-    private static void completeDataGET(final RestconfFuture<DataGetResult> future, final AsyncResponse ar) {
+    @NonNullByDefault
+    private static void completeDataGET(final RestconfFuture<DataGetResult> future, final PrettyPrintParam prettyPrint,
+            final AsyncResponse ar) {
         future.addCallback(new JaxRsRestconfCallback<>(ar) {
             @Override
             Response transform(final DataGetResult result) {
-                final var builder = Response.status(Status.OK)
-                    .entity(result.payload())
+                final var builder = Response.ok()
+                    .entity(new JaxRsFormattableBody(result.body(), prettyPrint))
                     .cacheControl(NO_CACHE);
                 fillConfigurationMetadata(builder, result);
                 return builder.build();
@@ -226,7 +256,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void dataXmlPATCH(final InputStream body, @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlResourceBody(body)) {
-            completeDataPATCH(server.dataPATCH(xmlBody), ar);
+            completeDataPATCH(server.dataPATCH(emptyRequest, xmlBody), ar);
         }
     }
 
@@ -248,7 +278,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     public void dataXmlPATCH(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
             @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlResourceBody(body)) {
-            completeDataPATCH(server.dataPATCH(identifier, xmlBody), ar);
+            completeDataPATCH(server.dataPATCH(emptyRequest, identifier, xmlBody), ar);
         }
     }
 
@@ -267,7 +297,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void dataJsonPATCH(final InputStream body, @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonResourceBody(body)) {
-            completeDataPATCH(server.dataPATCH(jsonBody), ar);
+            completeDataPATCH(server.dataPATCH(emptyRequest, jsonBody), ar);
         }
     }
 
@@ -288,15 +318,17 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     public void dataJsonPATCH(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
             @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonResourceBody(body)) {
-            completeDataPATCH(server.dataPATCH(identifier, jsonBody), ar);
+            completeDataPATCH(server.dataPATCH(emptyRequest, identifier, jsonBody), ar);
         }
     }
 
-    private static void completeDataPATCH(final RestconfFuture<Empty> future, final AsyncResponse ar) {
+    private static void completeDataPATCH(final RestconfFuture<DataPatchResult> future, final AsyncResponse ar) {
         future.addCallback(new JaxRsRestconfCallback<>(ar) {
             @Override
-            Response transform(final Empty result) {
-                return Response.ok().build();
+            Response transform(final DataPatchResult result) {
+                final var builder = Response.ok();
+                fillConfigurationMetadata(builder, result);
+                return builder.build();
             }
         });
     }
@@ -306,6 +338,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
      * @param body YANG Patch body
+     * @param uriInfo URI info
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
     @PATCH
@@ -315,9 +348,10 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_JSON,
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
-    public void dataYangJsonPATCH(final InputStream body, @Suspended final AsyncResponse ar) {
+    public void dataYangJsonPATCH(final InputStream body, @Context final UriInfo uriInfo,
+            @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(jsonBody), ar);
+            completeDataYangPATCH(server.dataPATCH(requestOf(uriInfo), jsonBody), ar);
         }
     }
 
@@ -327,6 +361,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      *
      * @param identifier path to target
      * @param body YANG Patch body
+     * @param uriInfo URI info
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
     @PATCH
@@ -337,9 +372,9 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
     public void dataYangJsonPATCH(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
-            @Suspended final AsyncResponse ar) {
+            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(identifier, jsonBody), ar);
+            completeDataYangPATCH(server.dataPATCH(requestOf(uriInfo), identifier, jsonBody), ar);
         }
     }
 
@@ -348,6 +383,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
      * @param body YANG Patch body
+     * @param uriInfo URI info
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
     @PATCH
@@ -357,9 +393,10 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_JSON,
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
-    public void dataYangXmlPATCH(final InputStream body, @Suspended final AsyncResponse ar) {
+    public void dataYangXmlPATCH(final InputStream body, @Context final UriInfo uriInfo,
+            @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(xmlBody), ar);
+            completeDataYangPATCH(server.dataPATCH(requestOf(uriInfo), xmlBody), ar);
         }
     }
 
@@ -368,6 +405,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * <a href="https://www.rfc-editor.org/rfc/rfc8072#section-2">RFC8072, section 2</a>.
      *
      * @param identifier path to target
+     * @param uriInfo URI info
      * @param body YANG Patch body
      * @param ar {@link AsyncResponse} which needs to be completed with a {@link PatchStatusContext}
      */
@@ -379,22 +417,28 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaTypes.APPLICATION_YANG_DATA_XML
     })
     public void dataYangXmlPATCH(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
-            @Suspended final AsyncResponse ar) {
+            @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlPatchBody(body)) {
-            completeDataYangPATCH(server.dataPATCH(identifier, xmlBody), ar);
+            completeDataYangPATCH(server.dataPATCH(requestOf(uriInfo), identifier, xmlBody), ar);
         }
     }
 
-    private static void completeDataYangPATCH(final RestconfFuture<PatchStatusContext> future, final AsyncResponse ar) {
+    private void completeDataYangPATCH(final RestconfFuture<DataYangPatchResult> future,
+            final AsyncResponse ar) {
         future.addCallback(new JaxRsRestconfCallback<>(ar) {
             @Override
-            Response transform(final PatchStatusContext result) {
-                return Response.status(statusOf(result)).entity(result).build();
+            Response transform(final DataYangPatchResult result) {
+                final var patchStatus = result.status();
+                final var statusCode = statusOf(patchStatus);
+                final var builder = Response.status(statusCode.code(), statusCode.phrase())
+                    .entity(new YangPatchStatusBody(patchStatus));
+                fillConfigurationMetadata(builder, result);
+                return builder.build();
             }
 
-            private static Status statusOf(final PatchStatusContext result) {
+            private HttpStatusCode statusOf(final PatchStatusContext result) {
                 if (result.ok()) {
-                    return Status.OK;
+                    return HttpStatusCode.OK;
                 }
                 final var globalErrors = result.globalErrors();
                 if (globalErrors != null && !globalErrors.isEmpty()) {
@@ -408,11 +452,11 @@ public final class JaxRsRestconf implements ParamConverterProvider {
                         }
                     }
                 }
-                return Status.INTERNAL_SERVER_ERROR;
+                return HttpStatusCode.INTERNAL_SERVER_ERROR;
             }
 
-            private static Status statusOfFirst(final List<RestconfError> error) {
-                return ErrorTags.statusOf(error.get(0).getErrorTag());
+            private @NonNull HttpStatusCode statusOfFirst(final List<RestconfError> error) {
+                return errorTagMapping.statusOf(error.get(0).getErrorTag());
             }
         });
     }
@@ -433,7 +477,8 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     public void postDataJSON(final InputStream body, @Context final UriInfo uriInfo,
             @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonChildBody(body)) {
-            completeDataPOST(server.dataPOST(jsonBody, QueryParams.normalize(uriInfo)), uriInfo, ar);
+            final var request = requestOf(uriInfo);
+            completeDataPOST(server.dataPOST(request, jsonBody), request.prettyPrint(), uriInfo, ar);
         }
     }
 
@@ -453,7 +498,8 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void postDataJSON(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
             @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
-        completeDataPOST(server.dataPOST(identifier, new JsonDataPostBody(body), QueryParams.normalize(uriInfo)),
+        final var request = requestOf(uriInfo);
+        completeDataPOST(server.dataPOST(request, identifier, new JsonDataPostBody(body)), request.prettyPrint(),
             uriInfo, ar);
     }
 
@@ -473,7 +519,8 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void postDataXML(final InputStream body, @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlChildBody(body)) {
-            completeDataPOST(server.dataPOST(xmlBody, QueryParams.normalize(uriInfo)), uriInfo, ar);
+            final var request = requestOf(uriInfo);
+            completeDataPOST(server.dataPOST(request, xmlBody), request.prettyPrint(), uriInfo, ar);
         }
     }
 
@@ -494,27 +541,28 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void postDataXML(@Encoded @PathParam("identifier") final ApiPath identifier, final InputStream body,
             @Context final UriInfo uriInfo, @Suspended final AsyncResponse ar) {
-        completeDataPOST(server.dataPOST(identifier, new XmlDataPostBody(body), QueryParams.normalize(uriInfo)),
+        final var request = requestOf(uriInfo);
+        completeDataPOST(server.dataPOST(request, identifier, new XmlDataPostBody(body)), request.prettyPrint(),
             uriInfo, ar);
     }
 
-    private static void completeDataPOST(final RestconfFuture<? extends DataPostResult> future, final UriInfo uriInfo,
-            final AsyncResponse ar) {
+    private static void completeDataPOST(final RestconfFuture<? extends DataPostResult> future,
+            final PrettyPrintParam prettyPrint, final UriInfo uriInfo, final AsyncResponse ar) {
         future.addCallback(new JaxRsRestconfCallback<DataPostResult>(ar) {
             @Override
             Response transform(final DataPostResult result) {
-                if (result instanceof CreateResource createResource) {
+                if (result instanceof CreateResourceResult createResource) {
                     final var builder = Response.created(uriInfo.getBaseUriBuilder()
                         .path("data")
-                        .path(createResource.createdPath())
+                        .path(createResource.createdPath().toString())
                         .build());
                     fillConfigurationMetadata(builder, createResource);
                     return builder.build();
                 }
-                if (result instanceof InvokeOperation invokeOperation) {
+                if (result instanceof InvokeResult invokeOperation) {
                     final var output = invokeOperation.output();
-                    return output == null ? Response.status(Status.NO_CONTENT).build()
-                        : Response.status(Status.OK).entity(output).build();
+                    return output == null ? Response.noContent().build()
+                        : Response.ok().entity(new JaxRsFormattableBody(output, prettyPrint)).build();
                 }
                 LOG.error("Unhandled result {}", result);
                 return Response.serverError().build();
@@ -537,7 +585,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void dataJsonPUT(@Context final UriInfo uriInfo, final InputStream body, @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonResourceBody(body)) {
-            completeDataPUT(server.dataPUT(jsonBody, QueryParams.normalize(uriInfo)), ar);
+            completeDataPUT(server.dataPUT(requestOf(uriInfo), jsonBody), ar);
         }
     }
 
@@ -558,7 +606,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     public void dataJsonPUT(@Encoded @PathParam("identifier") final ApiPath identifier, @Context final UriInfo uriInfo,
             final InputStream body, @Suspended final AsyncResponse ar) {
         try (var jsonBody = new JsonResourceBody(body)) {
-            completeDataPUT(server.dataPUT(identifier, jsonBody, QueryParams.normalize(uriInfo)), ar);
+            completeDataPUT(server.dataPUT(requestOf(uriInfo), identifier, jsonBody), ar);
         }
     }
 
@@ -578,7 +626,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     })
     public void dataXmlPUT(@Context final UriInfo uriInfo, final InputStream body, @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlResourceBody(body)) {
-            completeDataPUT(server.dataPUT(xmlBody, QueryParams.normalize(uriInfo)), ar);
+            completeDataPUT(server.dataPUT(requestOf(uriInfo), xmlBody), ar);
         }
     }
 
@@ -600,7 +648,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     public void dataXmlPUT(@Encoded @PathParam("identifier") final ApiPath identifier, @Context final UriInfo uriInfo,
             final InputStream body, @Suspended final AsyncResponse ar) {
         try (var xmlBody = new XmlResourceBody(body)) {
-            completeDataPUT(server.dataPUT(identifier, xmlBody, QueryParams.normalize(uriInfo)), ar);
+            completeDataPUT(server.dataPUT(requestOf(uriInfo), identifier, xmlBody), ar);
         }
     }
 
@@ -609,7 +657,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
             @Override
             Response transform(final DataPutResult result) {
                 // Note: no Location header, as it matches the request path
-                final var builder = result.created() ? Response.status(Status.CREATED) : Response.noContent();
+                final var builder = result.created() ? Response.created(null) : Response.noContent();
                 fillConfigurationMetadata(builder, result);
                 return builder.build();
             }
@@ -617,73 +665,35 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     }
 
     /**
-     * List RPC and action operations in RFC7951 format.
-     *
-     * @param ar {@link AsyncResponse} which needs to be completed
-     */
-    @GET
-    @Path("/operations")
-    @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
-    public void operationsJsonGET(@Suspended final AsyncResponse ar) {
-        completeOperationsJsonGet(server.operationsGET(), ar);
-    }
-
-    /**
-     * Retrieve list of operations and actions supported by the server or device in JSON format.
-     *
-     * @param operation path parameter to identify device and/or operation
-     * @param ar {@link AsyncResponse} which needs to be completed
-     */
-    @GET
-    @Path("/operations/{operation:.+}")
-    @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
-    public void operationsJsonGET(@PathParam("operation") final ApiPath operation, @Suspended final AsyncResponse ar) {
-        completeOperationsGet(server.operationsGET(operation), ar, OperationsGetResult::toJSON);
-    }
-
-    private static void completeOperationsJsonGet(final RestconfFuture<OperationsGetResult> future,
-            final AsyncResponse ar) {
-        completeOperationsGet(future, ar, OperationsGetResult::toJSON);
-    }
-
-    /**
-     * List RPC and action operations in RFC8040 XML format.
+     * List RPC and action operations.
      *
      * @param ar {@link AsyncResponse} which needs to be completed
      */
     @GET
     @Path("/operations")
-    @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
-    public void operationsXmlGET(@Suspended final AsyncResponse ar) {
-        completeOperationsXmlGet(server.operationsGET(), ar);
+    @Produces({
+        MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML,
+        MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON
+    })
+    public void operationsGET(@Suspended final AsyncResponse ar) {
+        server.operationsGET(emptyRequest).addCallback(new FormattableBodyCallback(ar, prettyPrint));
     }
 
     /**
-     * Retrieve list of operations and actions supported by the server or device in XML format.
+     * Retrieve list of operations and actions supported by the server or device.
      *
      * @param operation path parameter to identify device and/or operation
      * @param ar {@link AsyncResponse} which needs to be completed
      */
     @GET
     @Path("/operations/{operation:.+}")
-    @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
-    public void operationsXmlGET(@PathParam("operation") final ApiPath operation, @Suspended final AsyncResponse ar) {
-        completeOperationsXmlGet(server.operationsGET(operation), ar);
-    }
-
-    private static void completeOperationsXmlGet(final RestconfFuture<OperationsGetResult> future,
-            final AsyncResponse ar) {
-        completeOperationsGet(future, ar, OperationsGetResult::toXML);
-    }
-
-    private static void completeOperationsGet(final RestconfFuture<OperationsGetResult> future, final AsyncResponse ar,
-            final Function<OperationsGetResult, String> toString) {
-        future.addCallback(new JaxRsRestconfCallback<OperationsGetResult>(ar) {
-            @Override
-            Response transform(final OperationsGetResult result) {
-                return Response.ok().entity(toString.apply(result)).build();
-            }
-        });
+    @Produces({
+        MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML,
+        MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON
+    })
+    public void operationsGET(@PathParam("operation") final ApiPath operation, @Suspended final AsyncResponse ar) {
+        server.operationsGET(emptyRequest, operation)
+            .addCallback(new FormattableBodyCallback(ar, prettyPrint));
     }
 
     /**
@@ -692,7 +702,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * @param identifier module name and rpc identifier string for the desired operation
      * @param body the body of the operation
      * @param uriInfo URI info
-     * @param ar {@link AsyncResponse} which needs to be completed with a {@link NormalizedNodePayload} output
+     * @param ar {@link AsyncResponse} which needs to be completed with a {@link FormattableBody} output
      */
     @POST
     // FIXME: identifier is just a *single* QName
@@ -722,7 +732,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
      * @param identifier module name and rpc identifier string for the desired operation
      * @param body the body of the operation
      * @param uriInfo URI info
-     * @param ar {@link AsyncResponse} which needs to be completed with a {@link NormalizedNodePayload} output
+     * @param ar {@link AsyncResponse} which needs to be completed with a {@link FormattableBody} output
      */
     @POST
     // FIXME: identifier is just a *single* QName
@@ -747,13 +757,13 @@ public final class JaxRsRestconf implements ParamConverterProvider {
 
     private void operationsPOST(final ApiPath identifier, final UriInfo uriInfo, final AsyncResponse ar,
             final OperationInputBody body) {
-        server.operationsPOST(uriInfo.getBaseUri(), identifier, body)
-            .addCallback(new JaxRsRestconfCallback<OperationsPostResult>(ar) {
+        server.operationsPOST(requestOf(uriInfo), uriInfo.getBaseUri(), identifier, body)
+            .addCallback(new JaxRsRestconfCallback<>(ar) {
                 @Override
-                Response transform(final OperationsPostResult result) {
+                Response transform(final InvokeResult result) {
                     final var body = result.output();
                     return body == null ? Response.noContent().build()
-                        : Response.ok().entity(new NormalizedNodePayload(result.operation(), body)).build();
+                        : Response.ok().entity(body).build();
                 }
             });
     }
@@ -773,12 +783,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
         MediaType.TEXT_XML
     })
     public void yangLibraryVersionGET(@Suspended final AsyncResponse ar) {
-        server.yangLibraryVersionGET().addCallback(new JaxRsRestconfCallback<NormalizedNodePayload>(ar) {
-            @Override
-            Response transform(final NormalizedNodePayload result) {
-                return Response.ok().entity(result).build();
-            }
-        });
+        server.yangLibraryVersionGET(emptyRequest).addCallback(new FormattableBodyCallback(ar, prettyPrint));
     }
 
     // FIXME: References to these resources are generated by our yang-library implementation. That means:
@@ -808,7 +813,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     @Path("/" + URLConstants.MODULES_SUBPATH + "/{fileName : [^/]+}")
     public void modulesYangGET(@PathParam("fileName") final String fileName,
             @QueryParam("revision") final String revision, @Suspended final AsyncResponse ar) {
-        completeModulesGET(server.modulesYangGET(fileName, revision), ar);
+        completeModulesGET(server.modulesYangGET(emptyRequest, fileName, revision), ar);
     }
 
     /**
@@ -825,7 +830,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     public void modulesYangGET(@Encoded @PathParam("mountPath") final ApiPath mountPath,
             @PathParam("fileName") final String fileName, @QueryParam("revision") final String revision,
             @Suspended final AsyncResponse ar) {
-        completeModulesGET(server.modulesYangGET(mountPath, fileName, revision), ar);
+        completeModulesGET(server.modulesYangGET(emptyRequest, mountPath, fileName, revision), ar);
     }
 
     /**
@@ -840,7 +845,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     @Path("/" + URLConstants.MODULES_SUBPATH + "/{fileName : [^/]+}")
     public void modulesYinGET(@PathParam("fileName") final String fileName,
             @QueryParam("revision") final String revision, @Suspended final AsyncResponse ar) {
-        completeModulesGET(server.modulesYinGET(fileName, revision), ar);
+        completeModulesGET(server.modulesYinGET(emptyRequest, fileName, revision), ar);
     }
 
     /**
@@ -857,7 +862,7 @@ public final class JaxRsRestconf implements ParamConverterProvider {
     public void modulesYinGET(@Encoded @PathParam("mountPath") final ApiPath mountPath,
             @PathParam("fileName") final String fileName, @QueryParam("revision") final String revision,
             @Suspended final AsyncResponse ar) {
-        completeModulesGET(server.modulesYinGET(mountPath, fileName, revision), ar);
+        completeModulesGET(server.modulesYinGET(emptyRequest, mountPath, fileName, revision), ar);
     }
 
     private static void completeModulesGET(final RestconfFuture<ModulesGetResult> future, final AsyncResponse ar) {