Skip to content

Commit

Permalink
fix(jmx): Handle MBeanInfo in Jolokia list() when there was error fet…
Browse files Browse the repository at this point in the history
…ching the info (fixes #902)

Signed-off-by: Grzegorz Grzybek <gr.grzybek@gmail.com>
(cherry picked from commit 4a4fcf5)
  • Loading branch information
grgrzybek committed May 8, 2024
1 parent 3cb41ec commit 18e68d7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
19 changes: 19 additions & 0 deletions packages/hawtio/src/plugins/shared/jolokia-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,23 @@ describe('JolokiaService', () => {
expect(options.maxDepth).toEqual(3)
expect(options.maxCollectionSize).toEqual(10000)
})

test('problematic JSON response from case hawtio/hawtio#3401', async () => {
const response = {
value: {
'java.util.logging': {
'type=Logging': {
class: 'sun.management.ManagementFactoryHelper$PlatformLoggingImpl',
desc: 'Information on the management interface of the MBean',
},
},
'my-domain-with-vanishing-mbeans': {
'type=Bean1': {
error: 'javax.management.InstanceNotFoundException: Bean1',
},
},
},
}
jolokiaService.unwindListResponse(response.value)
})
})
2 changes: 1 addition & 1 deletion packages/hawtio/src/plugins/shared/jolokia-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ class JolokiaService implements IJolokiaService {
* @param response response value from Jolokia LIST
* @param path optional path information to restore the response to {@link OptimisedJmxDomains}
*/
private unwindListResponse(response: unknown, path?: string[]): OptimisedJmxDomains {
unwindListResponse(response: unknown, path?: string[]): OptimisedJmxDomains {
if (isOptimisedListResponse(response)) {
// Post process cached MBean info
const { cache, domains } = response
Expand Down
14 changes: 13 additions & 1 deletion packages/hawtio/src/plugins/shared/tree/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ export function isJmxDomains(value: unknown): value is OptimisedJmxDomains {

export type OptimisedJmxDomain = Record<string, OptimisedMBeanInfo>

function isMBeanInfoOrError(value: unknown): boolean {
return isMBeanInfo(value) || isMBeanInfoError(value)
}

export function isJmxDomain(value: unknown): value is OptimisedJmxDomain {
return is(value, record(string(), define('MBeanInfo', isMBeanInfo)))
return is(value, record(string(), define('MBeanInfo', isMBeanInfoOrError)))
}

export interface OptimisedMBeanInfo extends Omit<MBeanInfo, 'attr' | 'op'> {
Expand All @@ -47,6 +51,14 @@ export function isMBeanInfo(value: unknown): value is OptimisedMBeanInfo {
)
}

export interface ErrorMBeanInfo {
error: string
}

export function isMBeanInfoError(value: unknown): value is ErrorMBeanInfo {
return is(value, type({ error: string() }))
}

export interface OptimisedMBeanAttribute extends MBeanAttribute {
canInvoke?: boolean
}
Expand Down

0 comments on commit 18e68d7

Please sign in to comment.