import java.util.Optional;
import java.util.concurrent.CancellationException;
import javax.ws.rs.core.Response.Status;
+import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMActionResult;
import org.opendaylight.mdsal.dom.api.DOMActionService;
import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
import org.opendaylight.restconf.nb.rfc8040.handlers.ActionServiceHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
+import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Util class for rpc.
- *
*/
public final class RestconfInvokeOperationsUtil {
-
private static final Logger LOG = LoggerFactory.getLogger(RestconfInvokeOperationsUtil.class);
private RestconfInvokeOperationsUtil() {
final SchemaPath schemaPath) {
final Optional<DOMRpcService> mountPointService = mountPoint.getService(DOMRpcService.class);
if (mountPointService.isPresent()) {
- final ListenableFuture<DOMRpcResult> rpc = mountPointService.get().invokeRpc(schemaPath, data);
- return prepareResult(rpc);
+ return prepareResult(mountPointService.get().invokeRpc(schemaPath, nonnullInput(schemaPath, data)));
}
final String errmsg = "RPC service is missing.";
LOG.debug(errmsg);
throw new RestconfDocumentedException(Status.SERVICE_UNAVAILABLE);
}
- final ListenableFuture<DOMRpcResult> rpc = rpcService.invokeRpc(schemaPath, data);
- return prepareResult(rpc);
+ return prepareResult(rpcService.invokeRpc(schemaPath, nonnullInput(schemaPath, data)));
+ }
+
+ private static @NonNull NormalizedNode<?, ?> nonnullInput(final SchemaPath type, final NormalizedNode<?, ?> input) {
+ return input != null ? input
+ : ImmutableNodes.containerNode(YangConstants.operationInputQName(type.getLastComponent().getModule()));
}
/**
}
}
- private static DOMRpcResult prepareResult(final ListenableFuture<DOMRpcResult> rpc) {
+ private static DOMRpcResult prepareResult(final ListenableFuture<? extends DOMRpcResult> rpc) {
final RpcResultFactory dataFactory = new RpcResultFactory();
FutureCallbackTx.addCallback(rpc, RestconfDataServiceConstant.PostData.POST_TX_TYPE, dataFactory);
return dataFactory.build();