Bad request error with Jolokia client

classic Classic list List threaded Threaded
10 messages Options
Marc Marc
Reply | Threaded
Open this post in threaded view
|

Bad request error with Jolokia client

I am using the Jolokia JS client to get the value of a JMX mbean.

Here is a partial source code:
"
var jolokia = new Jolokia("http://localhost:8080/jolokia");
var jdbcConnexionsCount = jolokia.getAttribute("metrics:name=repositories.jdbc!/connections.count", "Value");
"

I get a Bad request HTTP error (400) when this executes. The wireshark logs the following requests:
"
GET /jolokia/read/metrics%3Aname%3Drepositories.jdbc!%2Fconnections.count/Value HTTP/1.1
"

I noticed that if I copy/paste this request inside a web browser but first replace the "!%2F" sequence by "!/" then this GET HTTP request works fine.

Question:
1) Is that normal the sequence "!/" is converted into "!%2F" ?
2) Can I disable this ?
3) My Jolokia client version 1.3.1

Thanks,
Rgds
roland roland
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

The %2F escaping comes from the fact, that the MBean name itself contains a name with a '/' which is used as separator between the different request parts, too.

Each part is separately URL encoded and then joined with '/', so it is expected behaviour. I could exclude the slash probably, but before I have some questions:

* What server are you using ? (tomcat, jboss, ...)
* Which Jolokia agent are you using ? (war, jvm, ...)

In the meantime there is an easy solution: Use POST instead of GET for the requests, which is safer encoding wise anyways. For this use a `method: "post"` when constructing the Javascript client. See https://jolokia.org/reference/html/clients.html#client-javascript for details.

In retrospective I should have chosen POST as default, but changing defaults afterwards is always hard ;-(
... roland
Marc Marc
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

Thanks for your quick support. Hereafter are my answers:

* What server are you using ? (tomcat, jboss, ...)
=> Tomcat 7

* Which Jolokia agent are you using ? (war, jvm, ...)
=> the War version

Is there any log files i can use to check the Jolojia agent installed on my Tomcat server?

I will try the POST instead of GET and I 'll let you know...
Marc Marc
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

I have tested using the POST method instead of the GET, I now get response from the Jolokia Agent but saying:
"javax.management.InstanceNotFoundException : metrics:name=repositories.jdbc!/connections.count"

Despite I am quite 100% sure this mbean name (object name) is correct?!
What could lead to this error except the mbean name error?
Marc Marc
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

Furthermore, the following JavaScript line to get the HeapMemory used works fine:
"
var jolokia = new Jolokia("http://localhost:8080/jolokia");
var req2 = { type: "read", mbean: "java.lang:type=Memory", attribute:"HeapMemoryUsage", path:"used" };
var response = jolokia.request(req2, {method: "post"});
"
Marc Marc
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

Finally, the POST methods runs successfully when I use the mbean name "metrics:name=repositories.jdbc\/connections.count" instead of "metrics:name=repositories.jdbc!/connections.count".

The character "\" seems better to escape the "/" instead of the character "!".

Question:

I use the simplified API "jolokia.getAttribute" that causes the problem. Is it possible to specify this API to use a POST method instead of the GET?

"
jolokia.getAttribute("metrics:name=repositories.jdbc!/connections.count", "Value");
"

roland roland
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

I think you can even remove the backslash when using a post request.
... roland
roland roland
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

In reply to this post by Marc
The best way to check the installed Jolokia agent is to point your browser to http://localhost:8080/jolokia (the jolokia URL)
... roland
Marc Marc
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

Ok, Thank you Roland to help us figure out my problem.
roland roland
Reply | Threaded
Open this post in threaded view
|

Re: Bad request error with Jolokia client

In reply to this post by Marc
I don't know it by heart, but the individual components of a request get URI escaped, so it could be easily possible that there is an issue (although %2F is indeed a valid encoding for '/' so I wonder why the server barfs. Probably for some security reasons).

What you can always do is to switch to a POST request (method = 'post' in the constructor, see the documentation). That is generally considered to be more stable with respect to encoding and such.

But could you please open an issue at https://github.com/rhuss/jolokia/issues/ so that we can try to fix this ?

thanks (and sorry for the late reply) ...
... roland
... roland