Avoid ClassCastException in remote-rpc-connector
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / RemoteRpcImplementation.java
index 23d1e85e23c355721c31e22bda7d6e7232c9cfd1..2a4ea2e3e6d6208a371cdb163de9ec3344df89df 100644 (file)
@@ -64,10 +64,14 @@ public class RemoteRpcImplementation implements DOMRpcImplementation {
                         LOG.debug("Detailed Error", failure);
                     }
 
-                    final String message = String.format("Execution of RPC %s failed",  rpcMsg.getRpc());
-                    Collection<RpcError> errors = ((RpcErrorsException)failure).getRpcErrors();
-                    if(errors == null || errors.size() == 0) {
-                        errors = Arrays.asList(RpcResultBuilder.newError(ErrorType.RPC, null, message));
+                    final String message = String.format("Execution of RPC %s failed because of %s",
+                            rpcMsg.getRpc(), failure.getMessage());
+                    Collection<RpcError> errors = Arrays.asList(RpcResultBuilder.newError(ErrorType.RPC, null, message));
+                    if(failure instanceof RpcErrorsException) {
+                        errors = ((RpcErrorsException) failure).getRpcErrors();
+                        if (errors == null || errors.size() == 0) {
+                            errors = Arrays.asList(RpcResultBuilder.newError(ErrorType.RPC, null, message));
+                        }
                     }
                     final DOMRpcResult rpcResult = new DefaultDOMRpcResult(errors);