From 57cce64b6cdf988a3437ce2f98edc16492ae4e35 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Thu, 10 Jul 2014 05:24:03 +0930 Subject: [PATCH] Rhizome Java API: narrower exceptions --- .../servaldna/ServalDClient.java | 9 ++-- .../servaldna/rhizome/RhizomeBundleList.java | 2 +- .../servaldna/rhizome/RhizomeCommon.java | 4 +- java/org/servalproject/test/Rhizome.java | 41 +++++++------------ 4 files changed, 22 insertions(+), 34 deletions(-) diff --git a/java/org/servalproject/servaldna/ServalDClient.java b/java/org/servalproject/servaldna/ServalDClient.java index a5a89cb1..8ee84d82 100644 --- a/java/org/servalproject/servaldna/ServalDClient.java +++ b/java/org/servalproject/servaldna/ServalDClient.java @@ -43,7 +43,6 @@ import org.servalproject.servaldna.rhizome.RhizomeManifestBundle; import org.servalproject.servaldna.rhizome.RhizomePayloadRawBundle; import org.servalproject.servaldna.rhizome.RhizomePayloadBundle; import org.servalproject.servaldna.rhizome.RhizomeInsertBundle; -import org.servalproject.servaldna.rhizome.RhizomeException; import org.servalproject.servaldna.rhizome.RhizomeInvalidManifestException; import org.servalproject.servaldna.rhizome.RhizomeFakeManifestException; import org.servalproject.servaldna.rhizome.RhizomeInconsistencyException; @@ -74,24 +73,24 @@ public class ServalDClient implements ServalDHttpConnectionFactory this.restfulPassword = restfulPassword; } - public RhizomeBundleList rhizomeListBundles() throws ServalDInterfaceException, IOException, RhizomeException + public RhizomeBundleList rhizomeListBundles() throws ServalDInterfaceException, IOException { RhizomeBundleList list = new RhizomeBundleList(this); list.connect(); return list; } - public RhizomeManifestBundle rhizomeManifest(BundleId bid) throws ServalDInterfaceException, IOException, RhizomeException + public RhizomeManifestBundle rhizomeManifest(BundleId bid) throws ServalDInterfaceException, IOException { return RhizomeCommon.rhizomeManifest(this, bid); } - public RhizomePayloadRawBundle rhizomePayloadRaw(BundleId bid) throws ServalDInterfaceException, IOException, RhizomeException + public RhizomePayloadRawBundle rhizomePayloadRaw(BundleId bid) throws ServalDInterfaceException, IOException { return RhizomeCommon.rhizomePayloadRaw(this, bid); } - public RhizomePayloadBundle rhizomePayload(BundleId bid) throws ServalDInterfaceException, IOException, RhizomeException + public RhizomePayloadBundle rhizomePayload(BundleId bid) throws ServalDInterfaceException, IOException, RhizomeDecryptionException { return RhizomeCommon.rhizomePayload(this, bid); } diff --git a/java/org/servalproject/servaldna/rhizome/RhizomeBundleList.java b/java/org/servalproject/servaldna/rhizome/RhizomeBundleList.java index d1e1d6ff..47845bca 100644 --- a/java/org/servalproject/servaldna/rhizome/RhizomeBundleList.java +++ b/java/org/servalproject/servaldna/rhizome/RhizomeBundleList.java @@ -68,7 +68,7 @@ public class RhizomeBundleList { return this.json != null; } - public void connect() throws IOException, ServalDInterfaceException, RhizomeException + public void connect() throws IOException, ServalDInterfaceException { try { rowCount = 0; diff --git a/java/org/servalproject/servaldna/rhizome/RhizomeCommon.java b/java/org/servalproject/servaldna/rhizome/RhizomeCommon.java index 95f2ba5d..5f9892db 100644 --- a/java/org/servalproject/servaldna/rhizome/RhizomeCommon.java +++ b/java/org/servalproject/servaldna/rhizome/RhizomeCommon.java @@ -107,13 +107,13 @@ public class RhizomeCommon ); } - protected static JSONTokeniser receiveRestfulResponse(HttpURLConnection conn, int expected_response_code) throws IOException, ServalDInterfaceException, RhizomeException + protected static JSONTokeniser receiveRestfulResponse(HttpURLConnection conn, int expected_response_code) throws IOException, ServalDInterfaceException { int[] expected_response_codes = { expected_response_code }; return receiveRestfulResponse(conn, expected_response_codes); } - protected static JSONTokeniser receiveRestfulResponse(HttpURLConnection conn, int[] expected_response_codes) throws IOException, ServalDInterfaceException, RhizomeException + protected static JSONTokeniser receiveRestfulResponse(HttpURLConnection conn, int[] expected_response_codes) throws IOException, ServalDInterfaceException { Status status = receiveResponse(conn, expected_response_codes); if (!conn.getContentType().equals("application/json")) diff --git a/java/org/servalproject/test/Rhizome.java b/java/org/servalproject/test/Rhizome.java index 0def1887..b0255363 100644 --- a/java/org/servalproject/test/Rhizome.java +++ b/java/org/servalproject/test/Rhizome.java @@ -76,9 +76,6 @@ public class Rhizome { ); } } - catch (RhizomeException e) { - System.out.println(e.toString()); - } finally { if (list != null) list.close(); @@ -88,26 +85,21 @@ public class Rhizome { static void rhizome_manifest(BundleId bid, String dstpath) throws ServalDInterfaceException, IOException, InterruptedException { - try { - ServalDClient client = new ServerControl().getRestfulClient(); - RhizomeManifestBundle bundle = client.rhizomeManifest(bid); - if (bundle == null) - System.out.println("not found"); - else { - System.out.println( - (bundle.rowId == null ? "" : "_rowId=" + bundle.rowId + "\n") + - (bundle.insertTime == null ? "" : "_insertTime=" + bundle.insertTime + "\n") + - (bundle.author == null ? "" : "_author=" + bundle.author + "\n") + - (bundle.secret == null ? "" : "_secret=" + bundle.secret + "\n") + - manifestFields(bundle.manifest, "\n") + "\n" - ); - FileOutputStream out = new FileOutputStream(dstpath); - out.write(bundle.manifestText()); - out.close(); - } - } - catch (RhizomeException e) { - System.out.println(e.toString()); + ServalDClient client = new ServerControl().getRestfulClient(); + RhizomeManifestBundle bundle = client.rhizomeManifest(bid); + if (bundle == null) + System.out.println("not found"); + else { + System.out.println( + (bundle.rowId == null ? "" : "_rowId=" + bundle.rowId + "\n") + + (bundle.insertTime == null ? "" : "_insertTime=" + bundle.insertTime + "\n") + + (bundle.author == null ? "" : "_author=" + bundle.author + "\n") + + (bundle.secret == null ? "" : "_secret=" + bundle.secret + "\n") + + manifestFields(bundle.manifest, "\n") + "\n" + ); + FileOutputStream out = new FileOutputStream(dstpath); + out.write(bundle.manifestText()); + out.close(); } System.exit(0); } @@ -143,9 +135,6 @@ public class Rhizome { ); } } - catch (RhizomeException e) { - System.out.println(e.toString()); - } finally { if (out != null) out.close();