Artemis jolokia rest api returns 没有真实数据 (Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher)

Artemis jolokia rest api returns no real data (Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher)

当我从浏览器控制台执行请求时,我得到一个 JSON 这样的结果:

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

当我从我的代码执行相同的请求时,我得到了非常不同的结果:

{
    "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 接缝很奇怪。但是在搜索这个名字时,我真的找不到任何有用的东西。我在 Artemis 日志中也找不到任何有用的信息。

这是我的代码:

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();

我需要配置什么才能让它工作吗?

您的代码使用的是 HTTP GET,但它使用的是固定的 URL(即 http://localhost:8161/console/jolokia/?maxDepth=7&maxCollectionSize=50000&ignoreErrors=true&canonicalNaming=false 和有效负载(即 {"type":"exec","mbean":"org.apache.activemq.artemis:broker="MyBroker","operation":"getQueueNames(java.lang.String)","arguments":["ANYCAST"]}")。此 不符合Jolokia protocol

如果您使用 HTTP GET,那么一切都应该在 URL 本身中,就像它是您的浏览器控制台一样。例如,使用这个:

http://localhost:8161/console/jolokia/exec/org.apache.activemq.artemis:broker="MyBroker"/getQueueNames/ANYCAST

Jolokia 请求可以通过两种方式发送:作为 HTTP GET 请求,在这种情况下,请求参数在 URL 中完全编码。或者作为 POST 请求,其中请求被放入 HTTP 请求正文中的 JSON 负载中。有关详细信息,请参阅 Jolokia Protocol

当 Jolokia 服务没有收到任何请求时,它会回复服务信息,即:

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

使用 HTTP GET 请求请求队列名称

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

使用 HTTP POST 请求请求队列名称

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"]}'