Configure the error Code in action callback for Java

We have created and register an action Callback for some rpc callpoints defined in our YANG model.

For the normal scenarios everything works ok BUT what about the case that we need to respond with an error code ?

The return value for the function
@ActionCallback(callPoint = “xxx_yyyy_zzz”, callType = ActionCBType.ACTION)

is ConfXMLParam[]. Hence a null return value doesn’t really causes any error message to be indicated but rather a 204 response with "no content.

While trying to throw DpCallbackException with a specific error message and code we always get back
500 internal server error !

How can we communicate specific errors back to the clients for rpc calls ?

See ConfD 6.4 UG Section 21 REST API and 21.8.1. User extended error messages:

For data providers, hooks, transforms etc there exist a possibility to add extensions to error messages and change error codes before sending errors back to the server from the callbacks (see: Section 28.14, “Error Message Customization”).

Our issue is that when we throw new DpCallbackExtendedException we always get back 500 Internal Server Error! According to your documenation if I change the errorCode this can be changed. In our case whatever errorCode we use we always get back 500 !!!

Apart from this in the documentation a function is mentioned. format_error() callback
BUT can please assist us on Java equivalent, since there is no correlation between C and Java !

I have tried to modify Java action example (examples.confd/intor/java/7-actions) in a way reboot action
throws DpCallbackExtendedException

/**
 * @see DpActionCallback
 */
public final static class CbRebootPointAction {
    @ActionCallback(callPoint = config.actionpoint_reboot_point, callType =
            ActionCBType.ACTION)
    public ConfXMLParam[] doActionRebootPoint(final DpActionTrans trans,
                                              final ConfTag name,
                                              final ConfObject[] keyPath,
                                              final ConfXMLParam[] params)
            throws DpCallbackException {
        log.info("==> doActionRebootPoint keyPath=" + new ConfPath
                (keyPath) + " name=" + name.toString());
        throw new DpCallbackException("Text description 'reboot failed'!", ErrorCode.ERR_BADPATH);

...

I receive passed text in netconf and cli response (I do not get error code).

steps

modify Actions.java

make all

Other terminal

make query

<?xml version="1.0" encoding="UTF-8"?>
<rpc-reply xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="1">
  <rpc-error>
    <error-type>application</error-type>
    <error-tag>operation-failed</error-tag>
    <error-severity>error</error-severity>
    <error-path xmlns:config="http://tail-f.com/ns/example/config" xmlns:act="http://tail-f.com/ns/netconf/actions/1.0" xmlns:nc="urn:ietf:params:xml:ns:netconf:base:1.0">
    /nc:rpc/act:action/act:data/config:config/config:system/config:reboot
  </error-path>
    <error-message xml:lang="en">Exception from action callback: Text description 'reboot failed'!</error-message>
    <error-info>
      <bad-element>reboot</bad-element>
    </error-info>
  </rpc-error>
</rpc-reply>

CLI terminal

make cli-c

# config
(config)# config system reboot 
Error: Exception from action callback: Text description 'reboot failed'!

If it does not work in your environment, please can you first try steps above?

Hi,

We also receive the passed text !
BUT if you trigger this with an rpc call you get the text but i cannot find a way to trigger the http error code back since confD always reports it with 500 and not something else !

Hello.

in initial message, you did not fully specify which northbound interface do you use. OK, from Conny’s and yours response it can be deduced that it is REST. If DpCallbackExtendedException does not return correct error code, as specified in 21.8., I suggest you file RT ticket with minimal example to illustrate the issue.