Fix handling of several error cases in the application REST API
Change-Id: I5a18374834b01e7b79b8f874356bf5f76168b66e
diff --git a/core/api/src/main/java/org/onosproject/core/Version.java b/core/api/src/main/java/org/onosproject/core/Version.java
index 379eda2..2183d59 100644
--- a/core/api/src/main/java/org/onosproject/core/Version.java
+++ b/core/api/src/main/java/org/onosproject/core/Version.java
@@ -77,6 +77,7 @@
* @return version descriptor
*/
public static Version version(String string) {
+ checkArgument(string != null, TOO_SHORT);
String[] fields = string.split("[.-]", 4);
checkArgument(fields.length >= 2, TOO_SHORT);
return new Version(parseInt(fields[0]), parseInt(fields[1]),
diff --git a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
index 24ad50a..c73c612 100644
--- a/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
+++ b/web/api/src/main/java/org/onosproject/rest/resources/ApplicationsWebResource.java
@@ -17,6 +17,7 @@
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.onosproject.app.ApplicationAdminService;
+import org.onosproject.app.ApplicationException;
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
@@ -131,11 +132,15 @@
@DefaultValue("false") boolean activate,
InputStream stream) {
ApplicationAdminService service = get(ApplicationAdminService.class);
- Application app = service.install(stream);
- if (activate) {
- service.activate(app.id());
+ try {
+ Application app = service.install(stream);
+ if (activate) {
+ service.activate(app.id());
+ }
+ return ok(codec(Application.class).encode(app, this)).build();
+ } catch (ApplicationException appEx) {
+ throw new IllegalArgumentException(appEx);
}
- return ok(codec(Application.class).encode(app, this)).build();
}
/**