Skip to content

Commit

Permalink
[#1082] Fix jolokia illegal paths
Browse files Browse the repository at this point in the history
Since Apache ActiveMQ Artemis 2.39.0 the char " in the path of the
jolokia requests cause: Error 400 Suspicious Path Character,
Illegal Path Character
  • Loading branch information
brusdev committed Jan 21, 2025
1 parent 8a3b04b commit dd6f130
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions controllers/activemqartemis_controller_cert_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ var _ = Describe("artemis controller with cert manager test", Label("controller-
})

func getConnectorConfig(podName string, crName string, connectorName string, g Gomega) map[string]string {
curlUrl := "http://" + podName + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/ConnectorsAsJSON"
curlUrl := "http://" + podName + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/ConnectorsAsJSON"
command := []string{"curl", "-k", "-s", "-u", "testuser:testpassword", curlUrl}

result := ExecOnPod(podName, crName, defaultNamespace, command, g)
Expand All @@ -1119,7 +1119,7 @@ func getConnectorConfig(podName string, crName string, connectorName string, g G
}

func CheckAcceptorStarted(podName string, crName string, acceptorName string, g Gomega) {
curlUrl := "http://" + podName + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\",component=acceptors,name=\"" + acceptorName + "\"/Started"
curlUrl := "http://" + podName + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22,component=acceptors,name=%22" + acceptorName + "%22/Started"
command := []string{"curl", "-k", "-s", "-u", "testuser:testpassword", curlUrl}

result := ExecOnPod(podName, crName, defaultNamespace, command, g)
Expand Down
16 changes: 8 additions & 8 deletions controllers/activemqartemis_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10050,7 +10050,7 @@ var _ = Describe("artemis controller", func() {
By("checking pod 0 status that has properties applied")
podWithOrdinal0 := namer.CrToSS(crd.Name) + "-0"

curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/Status"
curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/Status"
curlCmd := []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal0, crd.Name+"-container", curlCmd)
Expand All @@ -10061,7 +10061,7 @@ var _ = Describe("artemis controller", func() {
g.Expect(*result).NotTo(ContainSubstring("broker-1.globalMem.properties"))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

curlUrl = "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/GlobalMaxSize"
curlUrl = "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/GlobalMaxSize"
curlCmd = []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal0, crd.Name+"-container", curlCmd)
Expand All @@ -10073,7 +10073,7 @@ var _ = Describe("artemis controller", func() {
By("checking pod 1 status that has properties applied")
podWithOrdinal1 := namer.CrToSS(crd.Name) + "-1"

curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/Status"
curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/Status"
curlCmd = []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal1, crd.Name+"-container", curlCmd)
Expand All @@ -10084,7 +10084,7 @@ var _ = Describe("artemis controller", func() {
g.Expect(*result).NotTo(ContainSubstring("broker-0.globalMem.properties"))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/GlobalMaxSize"
curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/GlobalMaxSize"
curlCmd = []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal1, crd.Name+"-container", curlCmd)
Expand Down Expand Up @@ -10155,7 +10155,7 @@ var _ = Describe("artemis controller", func() {
By("checking pod 0 status that has properties applied")
podWithOrdinal0 := namer.CrToSS(crd.Name) + "-0"

curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/Status"
curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/Status"
curlCmd := []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal0, crd.Name+"-container", curlCmd)
Expand All @@ -10166,7 +10166,7 @@ var _ = Describe("artemis controller", func() {
g.Expect(*result).NotTo(ContainSubstring("broker-1.globalMem.json"))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

curlUrl = "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/GlobalMaxSize"
curlUrl = "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/GlobalMaxSize"
curlCmd = []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal0, crd.Name+"-container", curlCmd)
Expand All @@ -10178,7 +10178,7 @@ var _ = Describe("artemis controller", func() {
By("checking pod 1 status that has properties applied")
podWithOrdinal1 := namer.CrToSS(crd.Name) + "-1"

curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/Status"
curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/Status"
curlCmd = []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal1, crd.Name+"-container", curlCmd)
Expand All @@ -10189,7 +10189,7 @@ var _ = Describe("artemis controller", func() {
g.Expect(*result).NotTo(ContainSubstring("broker-0.globalMem.json"))
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\"/GlobalMaxSize"
curlUrl = "http://" + podWithOrdinal1 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22/GlobalMaxSize"
curlCmd = []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal1, crd.Name+"-container", curlCmd)
Expand Down
2 changes: 1 addition & 1 deletion controllers/activemqartemisscaledown_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var _ = Describe("Scale down controller", func() {
// so the pod number will change from 1 to 2 and back to 1.
// checking message count on broker 0 to make sure scale down finally happens.
By("Checking messsage count on broker 0")
curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=\"amq-broker\",component=addresses,address=\"DLQ\",subcomponent=queues,routing-type=\"anycast\",queue=\"DLQ\"/MessageCount"
curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:broker=%22amq-broker%22,component=addresses,address=%22DLQ%22,subcomponent=queues,routing-type=%22anycast%22,queue=%22DLQ%22/MessageCount"
curlCmd := []string{"curl", "-s", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
result, err := RunCommandInPod(podWithOrdinal0, brokerName+"-container", curlCmd)
g.Expect(err).To(BeNil())
Expand Down
4 changes: 2 additions & 2 deletions controllers/activemqartemissecurity_broker_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ var _ = Describe("security without controller", func() {
By("verify joe cannot see address message count attribute")
podWithOrdinal0 := namer.CrToSS(crd.Name) + "-0"
originHeader := "Origin: http://" + "localhost" // value not verified but presence necessary
curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:address=\"TOMS_WORK_QUEUE\",broker=\"amq-broker\",component=addresses/MessageCount"
curlUrl := "http://" + podWithOrdinal0 + ":8161/console/jolokia/read/org.apache.activemq.artemis:address=%22TOMS_WORK_QUEUE%22,broker=%22amq-broker%22,component=addresses/MessageCount"
curlCmd := []string{"curl", "-S", "-v", "-H", originHeader, "-u", "joe:joe", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal0, crd.Name+"-container", curlCmd)
Expand All @@ -206,7 +206,7 @@ var _ = Describe("security without controller", func() {
}, existingClusterTimeout, existingClusterInterval).Should(Succeed())

By("verify admin can't call forceFailover")
curlUrl = "http://" + podWithOrdinal0 + ":8161/console/jolokia/exec/org.apache.activemq.artemis:broker=\"amq-broker\"/forceFailover"
curlUrl = "http://" + podWithOrdinal0 + ":8161/console/jolokia/exec/org.apache.activemq.artemis:broker=%22amq-broker%22/forceFailover"
curlCmd = []string{"curl", "-S", "-v", "-H", originHeader, "-u", "admin:admin", curlUrl}
Eventually(func(g Gomega) {
result, err := RunCommandInPod(podWithOrdinal0, crd.Name+"-container", curlCmd)
Expand Down
2 changes: 1 addition & 1 deletion controllers/controllermanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ var _ = Describe("tests regarding controller manager", func() {
k8sClient.Update(ctx, createdCr)
g.Expect(len(createdCr.Status.PodStatus.Ready)).Should(BeEquivalentTo(1))
By("Checking messsage count on broker 0")
curlUrl := "http://" + podWithOrdinal + ":8161/console/jolokia/read/org.apache.activemq.artemis:address=\"TEST\",broker=\"amq-broker\",component=addresses,queue=\"TEST\",routing-type=\"anycast\",subcomponent=queues/MessageCount"
curlUrl := "http://" + podWithOrdinal + ":8161/console/jolokia/read/org.apache.activemq.artemis:address=%22TEST%22,broker=%22amq-broker%22,component=addresses,queue=%22TEST%22,routing-type=%22anycast%22,subcomponent=queues/MessageCount"
queryCmd := []string{"curl", "-k", "-H", "Origin: http://localhost:8161", "-u", "user:password", curlUrl}
reply, err := RunCommandInPodWithNamespace(podWithOrdinal, restrictedNamespace, createdCr.Name+"-container", queryCmd)
g.Expect(err).To(BeNil())
Expand Down
28 changes: 14 additions & 14 deletions pkg/utils/artemis/artemis.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ func (artemis *Artemis) GetStatus() (string, error) {

func (artemis *Artemis) CreateQueue(addressName string, queueName string, routingType string) (*jolokia.ResponseData, error) {

url := "org.apache.activemq.artemis:broker=\\\"" + artemis.name + "\\\""
url := "org.apache.activemq.artemis:broker=\"" + artemis.name + "\""
routingType = strings.ToUpper(routingType)
parameters := `"` + addressName + `","` + queueName + `",` + `"` + routingType + `"`
jsonStr := `{ "type":"EXEC","mbean":"` + url + `","operation":"createQueue(java.lang.String,java.lang.String,java.lang.String)","arguments":[` + parameters + `]` + ` }`
jsonStr := `{ "type":"EXEC","mbean":"` + strings.Replace(url, "\"", "\\\"", -1) + `","operation":"createQueue(java.lang.String,java.lang.String,java.lang.String)","arguments":[` + parameters + `]` + ` }`
data, err := artemis.jolokia.Exec(url, jsonStr)

return data, err
}

func (artemis *Artemis) UpdateQueue(queueConfig string) (*jolokia.ResponseData, error) {
url := "org.apache.activemq.artemis:broker=\\\"" + artemis.name + "\\\""
url := "org.apache.activemq.artemis:broker=\"" + artemis.name + "\""
parameters := queueConfig
jsonStr := `{ "type":"EXEC","mbean":"` + url + `","operation":"updateQueue(java.lang.String)","arguments":[` + parameters + `]` + ` }`
jsonStr := `{ "type":"EXEC","mbean":"` + strings.Replace(url, "\"", "\\\"", -1) + `","operation":"updateQueue(java.lang.String)","arguments":[` + parameters + `]` + ` }`

data, err := artemis.jolokia.Exec(url, jsonStr)

Expand All @@ -126,9 +126,9 @@ func (artemis *Artemis) CreateQueueFromConfig(queueConfig string, ignoreIfExists
} else {
ignoreIfExistsValue = "false"
}
url := "org.apache.activemq.artemis:broker=\\\"" + artemis.name + "\\\""
url := "org.apache.activemq.artemis:broker=\"" + artemis.name + "\""
parameters := queueConfig + `,` + ignoreIfExistsValue
jsonStr := `{ "type":"EXEC","mbean":"` + url + `","operation":"createQueue(java.lang.String,boolean)","arguments":[` + parameters + `]` + ` }`
jsonStr := `{ "type":"EXEC","mbean":"` + strings.Replace(url, "\"", "\\\"", -1) + `","operation":"createQueue(java.lang.String,boolean)","arguments":[` + parameters + `]` + ` }`

data, err := artemis.jolokia.Exec(url, jsonStr)

Expand All @@ -137,40 +137,40 @@ func (artemis *Artemis) CreateQueueFromConfig(queueConfig string, ignoreIfExists

func (artemis *Artemis) CreateAddress(addressName string, routingType string) (*jolokia.ResponseData, error) {

url := "org.apache.activemq.artemis:broker=\\\"" + artemis.name + "\\\""
url := "org.apache.activemq.artemis:broker=\"" + artemis.name + "\""
routingType = strings.ToUpper(routingType)
parameters := `"` + addressName + `","` + routingType + `"`
jsonStr := `{ "type":"EXEC","mbean":"` + url + `","operation":"createAddress(java.lang.String,java.lang.String)","arguments":[` + parameters + `]` + ` }`
jsonStr := `{ "type":"EXEC","mbean":"` + strings.Replace(url, "\"", "\\\"", -1) + `","operation":"createAddress(java.lang.String,java.lang.String)","arguments":[` + parameters + `]` + ` }`
data, err := artemis.jolokia.Exec(url, jsonStr)

return data, err
}

func (artemis *Artemis) DeleteQueue(queueName string) (*jolokia.ResponseData, error) {

url := "org.apache.activemq.artemis:broker=\\\"" + artemis.name + "\\\""
url := "org.apache.activemq.artemis:broker=\"" + artemis.name + "\""
parameters := `"` + queueName + `"`
jsonStr := `{ "type":"EXEC","mbean":"` + url + `","operation":"destroyQueue(java.lang.String)","arguments":[` + parameters + `]` + ` }`
jsonStr := `{ "type":"EXEC","mbean":"` + strings.Replace(url, "\"", "\\\"", -1) + `","operation":"destroyQueue(java.lang.String)","arguments":[` + parameters + `]` + ` }`
data, err := artemis.jolokia.Exec(url, jsonStr)

return data, err
}

func (artemis *Artemis) ListBindingsForAddress(addressName string) (*jolokia.ResponseData, error) {

url := "org.apache.activemq.artemis:broker=\\\"" + artemis.name + "\\\""
url := "org.apache.activemq.artemis:broker=\"" + artemis.name + "\""
parameters := `"` + addressName + `"`
jsonStr := `{ "type":"EXEC","mbean":"` + url + `","operation":"listBindingsForAddress(java.lang.String)","arguments":[` + parameters + `]` + ` }`
jsonStr := `{ "type":"EXEC","mbean":"` + strings.Replace(url, "\"", "\\\"", -1) + `","operation":"listBindingsForAddress(java.lang.String)","arguments":[` + parameters + `]` + ` }`
data, err := artemis.jolokia.Exec(url, jsonStr)

return data, err
}

func (artemis *Artemis) DeleteAddress(addressName string) (*jolokia.ResponseData, error) {

url := "org.apache.activemq.artemis:broker=\\\"" + artemis.name + "\\\""
url := "org.apache.activemq.artemis:broker=\"" + artemis.name + "\""
parameters := `"` + addressName + `"`
jsonStr := `{ "type":"EXEC","mbean":"` + url + `","operation":"deleteAddress(java.lang.String)","arguments":[` + parameters + `]` + ` }`
jsonStr := `{ "type":"EXEC","mbean":"` + strings.Replace(url, "\"", "\\\"", -1) + `","operation":"deleteAddress(java.lang.String)","arguments":[` + parameters + `]` + ` }`
data, err := artemis.jolokia.Exec(url, jsonStr)

return data, err
Expand Down

0 comments on commit dd6f130

Please sign in to comment.