Fix MeshMS Java API when MeshMS disabled

If the MeshMS REST API is disabled, then the JSON response omits the
MeshMS status code, so the Java client API now handles this case.
This commit is contained in:
Andrew Bettison 2015-06-29 15:00:14 +09:30
parent 4891348684
commit 8ac156376d
2 changed files with 20 additions and 11 deletions

View File

@ -80,15 +80,18 @@ public class MeshMSCommon
json.consume("http_status_message");
json.consume(JSONTokeniser.Token.COLON);
status.http_status_message = json.consume(String.class);
json.consume(JSONTokeniser.Token.COMMA);
json.consume("meshms_status_code");
json.consume(JSONTokeniser.Token.COLON);
status.meshms_status_code = MeshMSStatus.fromCode(json.consume(Integer.class));
json.consume(JSONTokeniser.Token.COMMA);
json.consume("meshms_status_message");
json.consume(JSONTokeniser.Token.COLON);
status.meshms_status_message = json.consume(String.class);
json.consume(JSONTokeniser.Token.END_OBJECT);
Object tok = json.nextToken();
if (tok == JSONTokeniser.Token.COMMA) {
json.consume("meshms_status_code");
json.consume(JSONTokeniser.Token.COLON);
status.meshms_status_code = MeshMSStatus.fromCode(json.consume(Integer.class));
json.consume(JSONTokeniser.Token.COMMA);
json.consume("meshms_status_message");
json.consume(JSONTokeniser.Token.COLON);
status.meshms_status_message = json.consume(String.class);
tok = json.nextToken();
}
json.match(tok, JSONTokeniser.Token.END_OBJECT);
json.consume(JSONTokeniser.Token.EOF);
return status;
}
@ -99,6 +102,9 @@ public class MeshMSCommon
protected static void throwRestfulResponseExceptions(Status status, URL url) throws MeshMSException, ServalDFailureException
{
if (status.meshms_status_code == null) {
throw new ServalDFailureException("missing meshms_status_code from " + url);
}
switch (status.meshms_status_code) {
case OK:
case UPDATED:

View File

@ -49,14 +49,17 @@ set_extra_config() {
:
}
doc_MeshmsDisabled="Java API failure when rhizome is disabled"
doc_MeshmsDisabled="Java API fails when rhizome is disabled"
setup_MeshmsDisabled() {
setup
executeOk_servald config set rhizome.enable off sync
}
test_MeshmsDisabled() {
executeJavaOk org.servalproject.test.Meshms meshms-list-conversations $SIDA1
executeJava org.servalproject.test.Meshms meshms-list-conversations $SIDA1
tfw_cat --stdout --stderr
assertExitStatus != 0
assertStderrGrep ServalDFailureException
assertStderrGrep --ignore-case 'missing meshms_status_code'
}
doc_MeshmsListConversations="Java API list MeshMS conversations"