Skip to content

Commit

Permalink
fix: Handles operation arguments imported as strings
Browse files Browse the repository at this point in the history
* Some Operation Arguments retrieved by jolokia are surrounded with quotes
  hence are handled internally as strings.

* Using the current mechanism only populates the arg.name parameter, leaving
  arg.type null, resulting in some ugly errors when OperationArgument is
  constructed.

* By checking whether the arg is an Object and if not parsing it mitigates
  the problem of the quotes
  • Loading branch information
phantomjinx committed Sep 11, 2023
1 parent e9d448e commit 676bea3
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/hawtio/src/plugins/shared/operations/operation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { isObject } from '@hawtiosrc/util/objects'
import { stringSorter, trimEnd } from '@hawtiosrc/util/strings'
import { IJmxOperation, IJmxOperations } from 'jolokia.js'
import { log } from '../globals'

/**
* Factory function for Operation objects.
Expand All @@ -23,13 +25,21 @@ function addOperation(
name: string,
op: IJmxOperation,
): void {
const operation = new Operation(
name,
op.args.map(arg => new OperationArgument(arg.name, arg.type, arg.desc)),
op.desc,
op.ret,
op.canInvoke,
)
const args: OperationArgument[] = []
for (const arg of op.args) {
let argObj = arg
if (!isObject(arg)) {
try {
argObj = JSON.parse(arg as string)
} catch (error) {
log.error(`Cannot parse argument ${arg} in operation ${op.desc}`, error)
continue
}
}
args.push(new OperationArgument(argObj.name, argObj.type, argObj.desc))
}

const operation = new Operation(name, args, op.desc, op.ret, op.canInvoke)
operations.push(operation)
operationMap[operation.name] = operation
}
Expand Down

0 comments on commit 676bea3

Please sign in to comment.