diff --git a/packages/hawtio/src/plugins/shared/__mocks__/jolokia-service.ts b/packages/hawtio/src/plugins/shared/__mocks__/jolokia-service.ts index 492d2f796..d06e3467a 100644 --- a/packages/hawtio/src/plugins/shared/__mocks__/jolokia-service.ts +++ b/packages/hawtio/src/plugins/shared/__mocks__/jolokia-service.ts @@ -28,7 +28,11 @@ class MockJolokiaService implements IJolokiaService { return '' } - async list(options: ListRequestOptions): Promise { + async list(options?: ListRequestOptions): Promise { + return jmxCamelResponse + } + + async sublist(path: string, options?: ListRequestOptions): Promise { return jmxCamelResponse } diff --git a/packages/hawtio/src/plugins/shared/jolokia-service.ts b/packages/hawtio/src/plugins/shared/jolokia-service.ts index d36631da9..162a86723 100644 --- a/packages/hawtio/src/plugins/shared/jolokia-service.ts +++ b/packages/hawtio/src/plugins/shared/jolokia-service.ts @@ -88,7 +88,8 @@ export interface IJolokiaService { getJolokia(): Promise getListMethod(): Promise getFullJolokiaUrl(): Promise - list(options: ListRequestOptions): Promise + list(options?: ListRequestOptions): Promise + sublist(path: string, options?: ListRequestOptions): Promise readAttributes(mbean: string): Promise readAttribute(mbean: string, attribute: string): Promise execute(mbean: string, operation: string, args?: unknown[]): Promise @@ -414,14 +415,34 @@ class JolokiaService implements IJolokiaService { return this.config.method } - async list(options: ListRequestOptions): Promise { + list(options: ListRequestOptions = {}): Promise { + return this.doList(null, options) + } + + sublist(path: string, options?: ListRequestOptions): Promise { + return this.doList(path, options) + } + + private async doList(path: string | null, options: ListRequestOptions = {}): Promise { const jolokia = await this.getJolokia() const { method, mbean } = this.config const { success, error: errorFn, ajaxError } = options return new Promise((resolve, reject) => { - options.ajaxError = (xhr: JQueryXHR, text: string, error: string) => { + const listOptions = onListSuccessAndError( + value => { + success?.(value) + resolve(value) + }, + error => { + errorFn?.(error) + reject(error) + }, + options, + ) + // Override ajaxError to make sure it terminates in case of ajax error + listOptions.ajaxError = (xhr, text, error) => { ajaxError?.(xhr, text, error) reject(error) } @@ -429,42 +450,25 @@ class JolokiaService implements IJolokiaService { case JolokiaListMethod.OPTIMISED: log.debug('Invoke Jolokia list MBean in optimised mode') // Overwrite max depth as listing MBeans requires some constant depth to work - options.maxDepth = OPTIMISED_JOLOKIA_LIST_MAX_DEPTH - jolokia.execute( - mbean, - 'list()', - // This is execute operation but ListRequestOptions is compatible with - // ExecuteRequestOptions for list(), so this is intentional. - onListSuccessAndError( - value => { - success?.(value) - resolve(value) - }, - error => { - errorFn?.(error) - reject(error) - }, - options, - ), - ) + // TODO: Is this needed? + listOptions.maxDepth = OPTIMISED_JOLOKIA_LIST_MAX_DEPTH + // This is execute operation but ListRequestOptions is compatible with + // ExecuteRequestOptions for list(), so this usage is intentional. + if (path === null) { + jolokia.execute(mbean, 'list()', listOptions) + } else { + jolokia.execute(mbean, 'list(java.lang.String)', path, listOptions) + } break case JolokiaListMethod.DEFAULT: case JolokiaListMethod.UNDETERMINED: default: log.debug('Invoke Jolokia list MBean in default mode') - jolokia.list( - onListSuccessAndError( - value => { - success?.(value) - resolve(value) - }, - error => { - errorFn?.(error) - reject(error) - }, - options, - ), - ) + if (path === null) { + jolokia.list(listOptions) + } else { + jolokia.list(path, listOptions) + } } }) }