Bug 1003: Restconf - remove whitespace on input
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / restconf / rpc / impl / AbstractRpcExecutor.java
index 0bc8428d76f85fae184b577040ee4d52f9cc682d..417cca653365bf96e925925226ee313513a79417 100644 (file)
@@ -30,6 +30,28 @@ public abstract class AbstractRpcExecutor implements RpcExecutor {
         return rpcDef;
     }
 
         return rpcDef;
     }
 
+    @Override
+    public RpcResult<CompositeNode> invokeRpc( CompositeNode rpcRequest )
+                                                   throws RestconfDocumentedException {
+        try {
+            return getRpcResult( invokeRpcUnchecked( rpcRequest ) );
+        }
+        catch( IllegalArgumentException e ) {
+            throw new RestconfDocumentedException(
+                                e.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE );
+        }
+        catch( UnsupportedOperationException e ) {
+            throw new RestconfDocumentedException(
+                                e.getMessage(), ErrorType.RPC, ErrorTag.OPERATION_NOT_SUPPORTED );
+        }
+        catch( Exception e ) {
+            throw new RestconfDocumentedException(
+                    "The operation encountered an unexpected error while executing.", e );
+        }
+    }
+
+    protected abstract Future<RpcResult<CompositeNode>> invokeRpcUnchecked( CompositeNode rpcRequest );
+
     protected RpcResult<CompositeNode> getRpcResult(
                                             Future<RpcResult<CompositeNode>> fromFuture ) {
         try {
     protected RpcResult<CompositeNode> getRpcResult(
                                             Future<RpcResult<CompositeNode>> fromFuture ) {
         try {