diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2014-07-14 14:13:26 -0230 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2014-07-14 14:13:26 -0230 |
commit | 2486afcdaca3adc4983a516fd47fb67ccc7284cb (patch) | |
tree | f69af8e2f093719c89bf9d114293d1b8c8d2d17c /java/demo/Database/library | |
parent | Increase the IceDiscovery.Timeout (diff) | |
download | ice-2486afcdaca3adc4983a516fd47fb67ccc7284cb.tar.bz2 ice-2486afcdaca3adc4983a516fd47fb67ccc7284cb.tar.xz ice-2486afcdaca3adc4983a516fd47fb67ccc7284cb.zip |
ICE-5462 library demo doesn't validate input data
Diffstat (limited to 'java/demo/Database/library')
-rw-r--r-- | java/demo/Database/library/Library.ice | 11 | ||||
-rw-r--r-- | java/demo/Database/library/LibraryI.java | 7 | ||||
-rw-r--r-- | java/demo/Database/library/Parser.java | 4 | ||||
-rw-r--r-- | java/demo/Database/library/createTypes.sql | 2 |
4 files changed, 21 insertions, 3 deletions
diff --git a/java/demo/Database/library/Library.ice b/java/demo/Database/library/Library.ice index 0c2e7a1b39c..37dc6e308a7 100644 --- a/java/demo/Database/library/Library.ice +++ b/java/demo/Database/library/Library.ice @@ -54,6 +54,15 @@ exception InvalidCustomerException /** * + * This exception is raised if the ISBN is invalid. + * + **/ +exception InvalidISBNException +{ +}; + +/** + * * This exception is raised if the book has not been rented. * **/ @@ -279,7 +288,7 @@ interface Library **/ Book* createBook(string isbn, string title, ["java:type:java.util.LinkedList<String>:java.util.List<String>"] Ice::StringSeq authors) - throws BookExistsException; + throws BookExistsException, InvalidISBNException; }; }; diff --git a/java/demo/Database/library/LibraryI.java b/java/demo/Database/library/LibraryI.java index ced08c93842..6ef3acfc363 100644 --- a/java/demo/Database/library/LibraryI.java +++ b/java/demo/Database/library/LibraryI.java @@ -198,7 +198,7 @@ class LibraryI extends _LibraryDisp public BookPrx createBook(String isbn, String title, java.util.List<String> authors, Ice.Current current) - throws BookExistsException + throws BookExistsException, InvalidISBNException { SQLRequestContext context = SQLRequestContext.getCurrentContext(); assert context != null; @@ -212,6 +212,11 @@ class LibraryI extends _LibraryDisp throw new BookExistsException(); } + if(isbn.length() > 13) + { + throw new InvalidISBNException(); + } + // // First convert the authors string to an id set. // diff --git a/java/demo/Database/library/Parser.java b/java/demo/Database/library/Parser.java index fbaa44ef3b8..fe5c9dbdf30 100644 --- a/java/demo/Database/library/Parser.java +++ b/java/demo/Database/library/Parser.java @@ -61,6 +61,10 @@ class Parser { error("the book already exists"); } + catch(InvalidISBNException ex) + { + error("invalid ISBN"); + } catch(Ice.LocalException ex) { error(ex.toString()); diff --git a/java/demo/Database/library/createTypes.sql b/java/demo/Database/library/createTypes.sql index 3d43ecbfd37..41f7c9d40d2 100644 --- a/java/demo/Database/library/createTypes.sql +++ b/java/demo/Database/library/createTypes.sql @@ -14,7 +14,7 @@ CREATE TABLE books ( id INT UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY (id), - isbn CHAR(10), + isbn CHAR(13), title VARCHAR(255), renter_id INT ) ENGINE=InnoDB; |