[PATCH] Http Server: jolokia API should return 404 when there is no jvm

68 views
Skip to first unread message

Amnon Heiman

unread,
Oct 2, 2014, 4:24:14 AM10/2/14
to osv...@googlegroups.com
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

Commit Bot

unread,
Oct 2, 2014, 8:09:45 AM10/2/14
to osv...@googlegroups.com
From: Amnon Heiman <am...@cloudius-systems.com>

Http Server: jolokia API should return 404 when there is no jvm

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>
Signed-off-by: Pekka Enberg <pen...@cloudius-systems.com>

---
diff --git a/java/jni_helpers.hh b/java/jni_helpers.hh
--- 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
Reply all
Reply to author
Forward
0 new messages