From b08c41e9d0b18b8c3561cd39e5cf409c4eeadd96 Mon Sep 17 00:00:00 2001 From: Tadayoshi Sato Date: Mon, 23 Oct 2023 17:08:16 +0900 Subject: [PATCH] fix(jmx): 'Copy Jolokia URL' in JMX Operations tab should provide full path including host origin --- app/craco.config.js | 4 +++- packages/hawtio/src/plugins/shared/connect-service.ts | 2 +- .../src/plugins/shared/operations/operation-service.ts | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/craco.config.js b/app/craco.config.js index ab90c945..21ee4b72 100644 --- a/app/craco.config.js +++ b/app/craco.config.js @@ -157,7 +157,9 @@ module.exports = { devServer.app.get('/hawtio/keycloak/client-config', (_, res) => res.send(JSON.stringify(keycloakClientConfig))) devServer.app.get('/hawtio/keycloak/validate-subject-matches', (_, res) => res.send('true')) - middlewares.push({ + // Hawtio backend middleware should be run before other middlewares (thus 'unshift') + // in order to handle GET requests to the proxied Jolokia endpoint. + middlewares.unshift({ name: 'hawtio-backend', path: '/hawtio/proxy', middleware: hawtioBackend({ diff --git a/packages/hawtio/src/plugins/shared/connect-service.ts b/packages/hawtio/src/plugins/shared/connect-service.ts index 670bc4a5..e291bc4f 100644 --- a/packages/hawtio/src/plugins/shared/connect-service.ts +++ b/packages/hawtio/src/plugins/shared/connect-service.ts @@ -143,7 +143,7 @@ class ConnectService implements IConnectService { connect(connection: Connection) { log.debug('Connecting with options:', toString(connection)) - const basepath = hawtio.getBasePath() || '/' + const basepath = hawtio.getBasePath() ?? '/' const url = `${basepath}?${PARAM_KEY_CONNECTION}=${connection.name}` log.debug('Opening URL:', url) window.open(url) diff --git a/packages/hawtio/src/plugins/shared/operations/operation-service.ts b/packages/hawtio/src/plugins/shared/operations/operation-service.ts index e2ba329e..0f59f5e0 100644 --- a/packages/hawtio/src/plugins/shared/operations/operation-service.ts +++ b/packages/hawtio/src/plugins/shared/operations/operation-service.ts @@ -1,3 +1,4 @@ +import { hawtio } from '@hawtiosrc/core' import { jolokiaService } from '@hawtiosrc/plugins/shared/jolokia-service' import { escapeMBean } from '@hawtiosrc/util/jolokia' import { log } from '../globals' @@ -9,9 +10,12 @@ class OperationService { } async getJolokiaUrl(mbean: string, operation: string): Promise { - //Ideally this would be provided by jolokia but it doesn't expose that API yet const mbeanName = escapeMBean(mbean) - return `${await jolokiaService.getJolokiaUrl()}/exec/${mbeanName}/${operation}` + const basePath = hawtio.getBasePath() ?? '' + const origin = window.location.origin + const jolokiaUrl = (await jolokiaService.getJolokiaUrl()) ?? '' + const jolokiaPath = jolokiaUrl.startsWith('/') ? jolokiaUrl : basePath + jolokiaUrl + return `${origin}${jolokiaPath}/exec/${mbeanName}/${operation}` } }