Artemis jolokia rest api不返回实际数据(Jsr160ProxyNotEnabledByDefau


  • 我有一个Artemis Broker(2.17(在我的开发机器上运行,用于本地测试
  • 从web控制台中,我提取了获取所有队列名称的请求

当我从浏览器控制台执行请求时,我会得到如下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接缝非常奇怪。但在搜索这个名字时,我真的找不到任何有用的东西。此外,我在阿尔忒弥斯的日志中找不到任何有用的信息。

这是我的代码:

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();
  • bootstrap.xml中,绑定被设置为0.0.0.0,这应该是可以的
  • jolokia-access.xml包含<allow-origin>*://localhost*</allow-origin>,这应该很好,但只是为了确保我已经用<allow-origin>*</allow-origin>替换了它

我需要配置一些东西来实现这一点吗?

Jolokia请求可以通过两种方式发送:要么作为HTTPGET请求,在这种情况下,请求参数完全编码在URL中。或者作为POST请求,将请求放入HTTP请求体中的JSON有效负载中。有关更多详细信息,请参阅Jolokia协议。

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

您的代码使用的是HTTPGET,但它使用的是固定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协议。

如果您使用HTTPGET,那么所有内容都应该在URL本身中,大概就像它是您的浏览器控制台一样。例如,使用以下内容:

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

相关内容

  • 没有找到相关文章

最新更新