+
+ @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 (RestconfDocumentedException e) {
+ throw e;
+ } 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 {
+ return fromFuture.get();
+ } catch (InterruptedException e) {
+ throw new RestconfDocumentedException(
+ "The operation was interrupted while executing and did not complete.", ErrorType.RPC,
+ ErrorTag.PARTIAL_OPERATION);
+ } catch (ExecutionException e) {
+ Throwable cause = e.getCause();
+ if (cause instanceof CancellationException) {
+ throw new RestconfDocumentedException("The operation was cancelled while executing.", ErrorType.RPC,
+ ErrorTag.PARTIAL_OPERATION);
+ } else if (cause != null) {
+ while (cause.getCause() != null) {
+ cause = cause.getCause();
+ }
+
+ if (cause instanceof IllegalArgumentException) {
+ throw new RestconfDocumentedException(cause.getMessage(), ErrorType.PROTOCOL,
+ ErrorTag.INVALID_VALUE);
+ }
+
+ throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.",
+ cause);
+ } else {
+ throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.",
+ e);
+ }
+ }
+ }