- }
-
- private void executeRpc(ExecuteRpc msg) {
- LOG.debug("Executing rpc for rpc {}", msg.getRpc());
- try {
- Future<RpcResult<CompositeNode>> rpc = brokerSession.rpc(msg.getRpc(), XmlUtils.inputXmlToCompositeNode(msg.getRpc(), msg.getInputCompositeNode(), schemaContext));
- RpcResult<CompositeNode> rpcResult = rpc != null ? rpc.get():null;
- CompositeNode result = rpcResult != null ? rpcResult.getResult() : null;
- getSender().tell(new RpcResponse(XmlUtils.outputCompositeNodeToXml(result, schemaContext)), self());
- } catch (Exception e) {
- LOG.error(e.toString());
- getSender().tell(new ErrorResponse(e), self());
+
+ private void executeRpc(final ExecuteRpc msg) {
+ LOG.debug("Executing rpc {}", msg.getRpc());
+ final NormalizedNode<?, ?> input = RemoteRpcInput.from(msg.getInputNormalizedNode());
+ final SchemaPath schemaPath = SchemaPath.create(true, msg.getRpc());
+ final ActorRef sender = getSender();
+ final ActorRef self = self();
+
+ try {
+ final CheckedFuture<DOMRpcResult, DOMRpcException> future = rpcService.invokeRpc(schemaPath, input);
+
+ Futures.addCallback(future, new FutureCallback<DOMRpcResult>() {
+ @Override
+ public void onSuccess(final DOMRpcResult result) {
+ if (result.getErrors() != null && (!result.getErrors().isEmpty())) {
+ final String message = String.format("Execution of RPC %s failed", msg.getRpc());
+ Collection<RpcError> errors = result.getErrors();
+ if (errors == null || errors.size() == 0) {
+ errors = Arrays.asList(RpcResultBuilder.newError(ErrorType.RPC, null, message));
+ }
+
+ sender.tell(new akka.actor.Status.Failure(new RpcErrorsException(message, errors)), self);
+ } else {
+ final Node serializedResultNode;
+ if (result.getResult() == null) {
+ serializedResultNode = null;
+ } else {
+ serializedResultNode = NormalizedNodeSerializer.serialize(result.getResult());
+ }
+
+ LOG.debug("Sending response for execute rpc : {}", msg.getRpc());
+
+ sender.tell(new RpcResponse(serializedResultNode), self);
+ }
+ }
+
+ @Override
+ public void onFailure(final Throwable t) {
+ LOG.error("executeRpc for {} failed with root cause: {}. For exception details, enable Debug logging.",
+ msg.getRpc(), Throwables.getRootCause(t));
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Detailed exception for execute RPC failure :{}", t);
+ }
+ sender.tell(new akka.actor.Status.Failure(t), self);
+ }
+ });
+ } catch (final Exception e) {
+ sender.tell(new akka.actor.Status.Failure(e), sender);
+ }