Similiar to the jvm API, the jolokia API should return 404 if no jvm is
available and not server error.
This adds a check that the jvm is available before attempting to use it
and if not throw a 404 not found exception.
Signed-off-by: Amnon Heiman <
am...@cloudius-systems.com>
---
java/jni_helpers.hh | 3 +++
modules/httpserver/api/jolokia.cc | 7 +++++++
2 files changed, 10 insertions(+)
diff --git a/java/jni_helpers.hh b/java/jni_helpers.hh
index 07e893e..2ebc70d 100644
--- a/java/jni_helpers.hh
+++ b/java/jni_helpers.hh
@@ -39,6 +39,9 @@ public:
}
static void set_jvm(JavaVM *);
+ static bool is_jvm_running() {
+ return global_jvm != nullptr;
+ }
private:
std::lock_guard<rwlock_for_read>
_guard;
diff --git a/modules/httpserver/api/jolokia.cc b/modules/httpserver/api/jolokia.cc
index fafca5e..0cc038d 100644
--- a/modules/httpserver/api/jolokia.cc
+++ b/modules/httpserver/api/jolokia.cc
@@ -15,10 +15,16 @@
#include <memory>
#include <regex>
#include <java/jni_helpers.hh>
+#include "exception.hh"
using namespace httpserver::json;
using namespace httpserver::json::jolokia_json;
+static void verify_jvm() {
+ if (!jvm_getter::is_jvm_running()) {
+ throw httpserver::not_found_exception("JVM not running");
+ }
+}
/**
* Initialize the routes object with specific routes mapping
* @param routes - the routes object to fill
@@ -88,6 +94,7 @@ void httpserver::api::jolokia::init(routes & routes)
const http::server::request& req, http::server::reply& rep)
override
{
+ verify_jvm();
attached_env aenv;
_clz->init();
--
1.9.3