mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-16 15:09:00 +00:00
Rhizome Java API: narrower exceptions
This commit is contained in:
parent
a81d05b4f6
commit
57cce64b6c
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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"))
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user