Skip to content

Commit

Permalink
Fix #772, improve mbean to object conversion and add some helper func…
Browse files Browse the repository at this point in the history
…tions to extract the endpoint name and target context from the current selection.
  • Loading branch information
gashcrumb committed Nov 25, 2013
1 parent 1867781 commit 5a4f735
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 18 deletions.
52 changes: 51 additions & 1 deletion hawtio-web/src/main/webapp/app/camel/js/camelHelpers.ts
Expand Up @@ -186,6 +186,56 @@ module Camel {
}
}

/**
* Parse out the currently selected endpoint's name to be used when invoking on a
* context operation that wants an endpoint name
*
* @param workspace
* @returns {*} either a string that is the endpoint name or null if it couldn't be parsed
*/
export function getSelectedEndpointName(workspace:Workspace) {
var selection = workspace.selection;
if (selection && selection['objectName'] && selection['typeName'] && selection['typeName'] === 'endpoints') {
var mbean = Core.parseMBean(selection['objectName']);
if (!mbean) {
return null;
}
var attributes = mbean['attributes'];
if (!attributes) {
return null;
}

if (!('name' in attributes)) {
return null;
}

var uri = attributes['name'];
uri = uri.replace("\\?", "?");
if (uri.startsWith("\"")) {
uri = uri.last(uri.length - 1);
}
if (uri.endsWith("\"")) {
uri = uri.first(uri.length - 1);
}
return uri;
} else {
return null;
}
}

/**
* Returns the mbean for the currently selected camel context and the name of the currently
* selected endpoint for JMX operations on a context that require an endpoint name.
* @param workspace
* @returns {{uri: string, mbean: string}} either value could be null if there's a parse failure
*/
export function getContextAndTargetEndpoint(workspace:Workspace) {
return {
uri: Camel.getSelectedEndpointName(workspace),
mbean: Camel.getSelectionCamelContextMBean(workspace)
};
}

/**
* Returns the cached Camel XML route node stored in the current tree selection Folder
*/
Expand Down Expand Up @@ -1089,4 +1139,4 @@ module Camel {
}
return value;
}
}
}
14 changes: 10 additions & 4 deletions hawtio-web/src/main/webapp/app/camel/js/send.ts
Expand Up @@ -134,16 +134,22 @@ module Camel {

var callback = onSuccess(onSendCompleteFn);
if (selection.domain === "org.apache.camel") {
var uri = selection.title.replace("\\?", "?");
mbean = getSelectionCamelContextMBean(workspace);
if (mbean) {
var target = Camel.getContextAndTargetEndpoint(workspace);
var uri = target['uri'];
mbean = target['mbean'];
if (mbean && uri) {
if (headers) {
jolokia.execute(mbean, "sendBodyAndHeaders(java.lang.String, java.lang.Object, java.util.Map)", uri, body, headers, callback);
} else {
jolokia.execute(mbean, "sendStringBody(java.lang.String, java.lang.String)", uri, body, callback);
}
} else {
notification("error", "Could not find CamelContext MBean!");
if (!mbean) {
notification("error", "Could not find CamelContext MBean!");
} else {
notification("error", "Failed to determine endpoint name!");
}
log.debug("Parsed context and endpoint: ", target);
}
} else {
var user = localStorage["activemqUserName"];
Expand Down
23 changes: 10 additions & 13 deletions hawtio-web/src/main/webapp/app/core/js/coreHelpers.ts
Expand Up @@ -297,24 +297,21 @@ module Core {

export function parseMBean(mbean) {
var answer = {};

var parts = mbean.split(":");
if (parts.length === 2) {
answer['domain'] = parts[0];
if (parts.length > 1) {
answer['domain'] = parts.first();
parts = parts.exclude(parts.first());
parts = parts.join(":");
answer['attributes'] = {};

var nameValues = parts[1].split(",");
var nameValues = parts.split(",");
nameValues.forEach((str) => {
var nameValue = str.split("=");
if (nameValue.length == 2) {
answer['attributes'][nameValue[0]] = nameValue[1];
}
var nameValue = str.split('=');
var name = nameValue.first().trim();
nameValue = nameValue.exclude(nameValue.first());
answer['attributes'][name] = nameValue.join('=').trim();
});

return answer;
}

return {};
return answer;
}


Expand Down

0 comments on commit 5a4f735

Please sign in to comment.