HONEYCOMB-67 Introduce exception handling into JVPP
Send calls throws VppInvocationException on failure
Failed requests (negative retval) reported over onError callback interface method
Removed retval attributes from dto/xxxReply.java calls
Change-Id: Ibd4e90c320d080e02d75b4bd056a7b11c8e37aa7
Signed-off-by: Tibor Sirovatka <tsirovat@cisco.com>
diff --git a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
index 4e408c3..dfec6a7 100644
--- a/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
+++ b/vpp-api/java/jvpp/gen/jvpp_impl_gen.py
@@ -39,8 +39,10 @@
/**
* Generic dispatch method for sending requests to VPP
+ *
+ * @throws org.openvpp.jvpp.VppInvocationException if send request had failed
*/
- int send($base_package.$dto_package.JVppRequest request);
+ int send($base_package.$dto_package.JVppRequest request) throws org.openvpp.jvpp.VppInvocationException;
@Override
void close();
@@ -76,7 +78,7 @@
}
@Override
- public int send($base_package.$dto_package.JVppRequest request) {
+ public int send($base_package.$dto_package.JVppRequest request) throws org.openvpp.jvpp.VppInvocationException {
return request.send(this);
}
@@ -84,23 +86,29 @@
}
""")
-method_template = Template(""" int $name($base_package.$dto_package.$request request);""")
+method_template = Template(""" int $name($base_package.$dto_package.$request request) throws org.openvpp.jvpp.VppInvocationException;""")
method_native_template = Template(
""" private static native int ${name}0($base_package.$dto_package.$request request);""")
-method_impl_template = Template(""" public final int $name($base_package.$dto_package.$request request) {
- if(request == null) {
- throw new java.lang.NullPointerException("Null request object");
- }
+method_impl_template = Template(""" public final int $name($base_package.$dto_package.$request request) throws org.openvpp.jvpp.VppInvocationException {
+ java.util.Objects.requireNonNull(request,"Null request object");
connection.checkActive();
- return ${name}0(request);
+ int result=${name}0(request);
+ if(result<0){
+ throw new org.openvpp.jvpp.VppInvocationException("${name}",result);
+ }
+ return result;
}
""")
-no_arg_method_template = Template(""" int $name();""")
-no_arg_method_native_template = Template(""" private static native int ${name}0();""")
-no_arg_method_impl_template = Template(""" public final int $name() {
+no_arg_method_template = Template(""" int $name() throws org.openvpp.jvpp.VppInvocationException;""")
+no_arg_method_native_template = Template(""" private static native int ${name}0() throws org.openvpp.jvpp.VppInvocationException;""")
+no_arg_method_impl_template = Template(""" public final int $name() throws org.openvpp.jvpp.VppInvocationException {
connection.checkActive();
- return ${name}0();
+ int result=${name}0();
+ if(result<0){
+ throw new org.openvpp.jvpp.VppInvocationException("${name}",result);
+ }
+ return result;
}
""")