int status = httpClient.executeMethod(method);
if (status != 200) {
try {
JSONObject result = parseResult(method);
if (result.has("message")) {
throw new OsgiClientException(result.getString("message"));
}
} catch (JSONException e) {
// ignore, fallback to status code reporting
}
throw new OsgiClientException("Method execution returned status " + status);
}
JSONObject obj = parseResult(method);
if ("OK".equals(obj.getString("status"))) {
return;
}
String errorMessage = obj.has("message") ? "Bundle deployment failed, please check the Sling logs"
: obj.getString("message");
throw new OsgiClientException(errorMessage);
} catch (IOException e) {
throw new OsgiClientException(e);
} catch (JSONException e) {
throw new OsgiClientException(
"Response is not valid JSON. The InstallServlet is probably not installed at the expected location",
e);
} finally {
method.releaseConnection();
}