Search code examples
activemq-artemisjolokia

Artemis jolokia rest api returns no real data (Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher)


  • I've an Artemis Broker (2.17) running on my dev machine for local testing.
  • From the web-console I've extractet the request to get the names of all queues.

When I execute the request from the browser console i get a JSON result like this:

{
    "request": {
        "mbean": "org.apache.activemq.artemis:broker=\"MyBroker\"",
        "arguments": [
            "ANYCAST"
        ],
        "type": "exec",
        "operation": "getQueueNames(java.lang.String)"
    },
    "value": [
        "DLQ",
        "ExpiryQueue"
    ],
    "timestamp": 1624274952,
    "status": 200
}

When I execute the same request from my code I get a very different result:

{
    "request": {
        "type": "version"
    },
    "value": {
        "agent": "1.6.2",
        "protocol": "7.2",
        "config": {
            "listenForHttpService": "true",
            "authIgnoreCerts": "false",
            "agentId": "192.168.1.41-30064-15b82644-servlet",
            "debug": "false",
            "agentType": "servlet",
            "policyLocation": "file:/C:/Artemis/MyBroker/etc//jolokia-access.xml",
            "agentContext": "/jolokia",
            "serializeException": "false",
            "mimeType": "text/plain",
            "dispatcherClasses": "org.jolokia.http.Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher",
            "authMode": "basic",
            "authMatch": "any",
            "streaming": "true",
            "canonicalNaming": "true",
            "historyMaxEntries": "10",
            "allowErrorDetails": "false",
            "allowDnsReverseLookup": "true",
            "realm": "jolokia",
            "includeStackTrace": "false",
            "mbeanQualifier": "qualifier=hawtio",
            "useRestrictorService": "false",
            "debugMaxEntries": "100"
        },
        "info": {
            "product": "jetty",
            "vendor": "Eclipse",
            "version": "9.4.27.v20200227"
        }
    },
    "timestamp": 1624274809,
    "status": 200
}

Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher seams very strange. But when searching for this name I couldn't realy find anything usefull. Also I cannot find any usefull information in the Artemis logs.

Here is my code:

using System;
using System.Net.Http;
using System.Text;
using System.Threading;

const String username = "admin";
const String password = "password";
var encoded = Convert.ToBase64String( Encoding.GetEncoding( "ISO-8859-1" )
                                              .GetBytes( username + ":" + password ) );
var url = "http://localhost:8161/console/jolokia/?maxDepth=7&maxCollectionSize=50000&ignoreErrors=true&canonicalNaming=false";
var http = new HttpClient();
http.BaseAddress = new("http://localhost:8161/");
http.DefaultRequestHeaders.Add( "Authorization", "Basic " + encoded );
http.DefaultRequestHeaders.Add( "Origin", "http://localhost:8161/" );
var request = new HttpRequestMessage
{
    Method = HttpMethod.Get,
    RequestUri = new(url),
    Content = new StringContent( "{\"type\":\"exec\",\"mbean\":\"org.apache.activemq.artemis:broker=\\\"MyBroker\\\"\",\"operation\":\"getQueueNames(java.lang.String)\",\"arguments\":[\"ANYCAST\"]}" )
};
request.Content.Headers.ContentType = new("text/json");
var response = await http.SendAsync( request, HttpCompletionOption.ResponseHeadersRead, CancellationToken.None );
if ( response.IsSuccessStatusCode )
{
    var content = await response.Content.ReadAsStringAsync();
    Console.WriteLine( content );
}
else
    Console.WriteLine( "Request failed...." );

Console.ReadLine();
  • In the bootstrap.xml the binding is set to 0.0.0.0 which should be ok.
  • jolokia-access.xml contained <allow-origin>*://localhost*</allow-origin> which should be fine but just to be sure I've replaced it with <allow-origin>*</allow-origin>

Is there something I need to configure to make this work?


Solution

  • Jolokia requests can be sent in two ways: Either as a HTTP GET request, in which case the request parameters are encoded completely in the URL. Or as a POST request where the request is put into a JSON payload in the HTTP request's body. See the Jolokia Protocol for further details.

    When the Jolokia service doesn't get any request it will answer with service information, ie:

    {
        "request": {
            "type": "version"
        },
        "value": {
    ...
    

    To request the queue names using an HTTP GET request

    curl -H "Origin:http://localhost:8161" -u admin:admin http://localhost:8161/console/jolokia/exec/org.apache.activemq.artemis:broker=\"MyBroker\"/getQueueNames/ANYCAST
    

    To request the queue names using an HTTP POST request

    curl -X POST -H "Content-Type: application/json" -H "Origin:http://localhost:8161" -u admin:admin http://localhost:8161/console/jolokia -d '{"type" : "EXEC", "mbean" : "org.apache.activemq.artemis:broker=\"MyBroker\"", "operation" : "getQueueNames", "arguments" : ["ANYCAST"]}'