public String execOperation(String mbeanName, String opName, Object... args) throws MalformedObjectNameException, J4pException { J4pExecRequest exec; String result = null; exec = new J4pExecRequest(mbeanName, opName, args); J4pExecResponse execResp = j4pClient.execute(exec); if (execResp.getValue() != null) { result = execResp.getValue().toString(); } else { result = opName + " executed"; } return result; }
public static String execCustomToJSON(J4pClient j4p, String mbeanUrl, String operation, Object ... args) { try { J4pExecRequest request = createCustomExecRequest(mbeanUrl, operation, args); J4pExecResponse response = j4p.execute(request); return response.getValue().toString(); } catch (Exception e) { throw new RuntimeException("Failed to call " + operation + " with args: " + args, e); } }
public static <T extends Object> T exec(J4pClient j4p, String operation, Object ... args) { try { J4pExecRequest request = createExecRequest(operation, args); J4pExecResponse response = j4p.execute(request); //System.out.println(response.getValue().toString()); return response.getValue(); } catch (Exception e) { throw new RuntimeException("Failed to call " + operation + " with args: " + args, e); } }
@Override public String getRouteModelAsXml(String routeId, String camelContextName) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } ObjectName found = lookupCamelContext(camelContextName); if (found != null) { String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); ObjectName on = ObjectName.getInstance(pattern); J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "dumpRouteAsXml()")); if (response != null) { String xml = response.getValue(); return xml; } } return null; }
@Override public String getRestApiDocAsJson(String camelContextName) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } ObjectName found = lookupCamelContext(camelContextName); if (found != null) { String pattern = String.format("%s:context=%s,type=services,name=DefaultRestRegistry", found.getDomain(), found.getKeyProperty("context")); ObjectName on = ObjectName.getInstance(pattern); J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "apiDocAsJson()")); if (response != null) { String json = response.getValue(); return json; } } return null; }
/** * executes an operation and returns the json result value * * @param j4p * @param operation * @param args * @return */ public static String execToJSON(J4pClient j4p, String operation, Object ... args) { try { J4pExecRequest request = createExecRequest(operation, args); J4pExecResponse response = j4p.execute(request); return response.getValue().toString(); } catch (Exception e) { throw new RuntimeException("Failed to call " + operation + " with args: " + args, e); } }
@Override public String getRouteStatsAsXml(String routeId, String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } ObjectName found = lookupCamelContext(camelContextName); if (found != null) { String pattern = String.format("%s:context=%s,type=routes,name=\"%s\"", found.getDomain(), found.getKeyProperty("context"), routeId); ObjectName on = ObjectName.getInstance(pattern); J4pExecResponse response = jolokia.execute(new J4pExecRequest(on, "dumpRouteStatsAsXml(boolean,boolean)", fullStats, includeProcessors)); if (response != null) { String xml = response.getValue(); return xml; } } return null; }
@SuppressWarnings("unchecked") private static <T extends Object> T getFieldValue(J4pClient j4p, String operation, String versionId, String id, String field) { T rc = null; try { J4pExecRequest request = Helpers.createExecRequest(operation, versionId, id, Helpers.toList(field)); J4pExecResponse response = j4p.execute(request); Map<String, Object> value = response.getValue(); rc = (T)value.get(field); } catch (MalformedObjectNameException e) { throw new RuntimeException("Failed to get container field", e); } catch (J4pException e) { throw new RuntimeException("Failed to get container field", e); } return rc; }
@Override public String getCamelContextStatsAsXml(String camelContextName, boolean fullStats, boolean includeProcessors) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } ObjectName found = lookupCamelContext(camelContextName); if (found != null) { J4pExecResponse er = jolokia.execute(new J4pExecRequest(found, "dumpRoutesStatsAsXml(boolean,boolean)", fullStats, includeProcessors)); if (er != null) { String xml = er.getValue(); return xml; } } return null; }
@Override public String explainEndpointAsJSon(String camelContextName, String uri, boolean allOptions) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } ObjectName found = lookupCamelContext(camelContextName); if (found != null) { J4pExecResponse response = jolokia.execute(new J4pExecRequest(found, "explainEndpointJson(java.lang.String,boolean)", uri, allOptions)); if (response != null) { String json = response.getValue(); return json; } } return null; }
@Override public Container[] getContainers() { List<Container> containers = new ArrayList<Container>(); try { J4pExecRequest request = Helpers.createExecRequest("containers(java.util.List)", toList("id")); J4pExecResponse response = getJolokiaClient().execute(request); List<Map<String, Object>> values = response.getValue(); for (Map<String, Object> value : values) { containers.add(new ContainerFacade(this, getJolokiaClient(), (String)value.get("id"))); } } catch (Exception e) { throw new RuntimeException ("Failed to fetch container list", e); } return containers.toArray(new Container[containers.size()]); }
@Override public String getRestModelAsXml(String camelContextName) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } ObjectName found = lookupCamelContext(camelContextName); if (found != null) { J4pExecResponse response = jolokia.execute(new J4pExecRequest(found, "dumpRestsAsXml()")); if (response != null) { String xml = response.getValue(); return xml; } } return null; }
@Override public String explainEipAsJSon(String camelContextName, String nameOrId, boolean allOptions) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } ObjectName found = lookupCamelContext(camelContextName); if (found != null) { J4pExecResponse response = jolokia.execute(new J4pExecRequest(found, "explainEipJson(java.lang.String,boolean)", nameOrId, allOptions)); if (response != null) { String json = response.getValue(); return json; } } return null; }
@Override public List<Map<String, Object>> browseInflightExchanges(String camelContextName, String route, int limit, boolean sortByLongestDuration) throws Exception { if (jolokia == null) { throw new IllegalStateException("Need to connect to remote jolokia first"); } List<Map<String, Object>> answer = new ArrayList<>(); ObjectName found = lookupCamelContext(camelContextName); if (found != null) { String pattern = String.format("%s:context=%s,type=services,name=DefaultInflightRepository", found.getDomain(), found.getKeyProperty("context")); ObjectName on = ObjectName.getInstance(pattern); J4pExecResponse er = jolokia.execute(new J4pExecRequest(on, "browse(String,int,boolean)", route, limit, sortByLongestDuration)); if (er != null) { JSONObject data = er.getValue(); if (data != null) { for (Object obj : data.values()) { JSONObject inflight = (JSONObject) obj; Map<String, Object> row = new LinkedHashMap<>(); row.put("exchangeId", asString(inflight.get("exchangeId"))); row.put("fromRouteId", asString(inflight.get("fromRouteId"))); row.put("routeId", asString(inflight.get("routeId"))); row.put("nodeId", asString(inflight.get("nodeId"))); row.put("elapsed", asString(inflight.get("elapsed"))); row.put("duration", asString(inflight.get("duration"))); answer.add(row); } } } } return answer; }
JSONObject data = response.getValue(); if (data != null) { for (Object obj : data.values()) {
JSONObject data = response.getValue(); if (data != null) { for (Object obj : data.values()) {
JSONObject data = response.getValue(); for (Object obj : data.values()) { JSONObject data2 = (JSONObject) obj;
J4pExecResponse response = jolokia.execute(new J4pExecRequest(found, "listComponents()")); if (response != null) { JSONObject data = response.getValue(); for (Object obj : data.values()) { JSONObject component = (JSONObject) obj;
JSONObject data = response.getValue(); if (data != null) { for (Object obj : data.values()) {
response = resp.getValue().toString();