protected String[] createSignature(MBeanOperationInfo info) { MBeanParameterInfo[] params = info.getSignature(); String[] answer = new String[params.length]; for (int i = 0; i < params.length; i++) { answer[i] = params[i].getType(); } return answer; }
/** * Description of the operation. * * @param operation the operation to describe * @return pretty-printed description */ protected String describeOperation(MBeanOperationInfo operation) { StringBuilder buf = new StringBuilder(); buf.append(operation.getReturnType()) .append(" ") .append(operation.getName()) .append("("); MBeanParameterInfo[] params = operation.getSignature(); for (int j = 0; j < params.length; j++) { MBeanParameterInfo param = params[j]; if (j != 0) { buf.append(", "); } buf.append(param.getType()) .append(" ") .append(param.getName()); } buf.append(")"); return buf.toString(); }
result.append("\n"); for (int i = 0; i < operations.length; i++) { MBeanParameterInfo[] params = operations[i].getSignature(); StringBuffer paramsStrBuffer = new StringBuffer(); if (params != null) {
public String invoke(ObjectName bean, String operation, String... params) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException, MBeanException { MBeanInfo mbinfo = mserver.getMBeanInfo(bean); MBeanOperationInfo op = null; for(MBeanOperationInfo oi: mbinfo.getOperations()) { if (oi.getName().equalsIgnoreCase(operation) && oi.getSignature().length == params.length) { if (op != null) { throw new IllegalArgumentException("Ambiguous " + operation + "/" + params.length + " operatition signature for " + bean); } op = oi; } } if (op == null) { throw new IllegalArgumentException("Operation " + operation + "/" + params.length + " not found for " + bean); } Object[] args = new Object[params.length]; String[] sig = new String[params.length]; for(int i = 0; i != params.length; ++i) { args[i] = convert(params[i], op.getSignature()[i].getType()); sig[i] = op.getSignature()[i].getType(); } return format(mserver.invoke(bean, op.getName(), args, sig), op.getReturnType()); }
this.allowedOperations = new HashMap<>(operationInfo.length); for (MBeanOperationInfo infoEle : operationInfo) { Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader); this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);
/** * Gets method by operation info. * * @param op MBean operation info. * @return Method. * @throws ClassNotFoundException Thrown if parameter type is unknown. * @throws SecurityException Thrown if method access is not allowed. */ private Method getMethod(MBeanOperationInfo op) throws ClassNotFoundException, SecurityException { String methodName = op.getName(); MBeanParameterInfo[] signature = op.getSignature(); Class<?>[] params = new Class<?>[signature.length]; for (int i = 0; i < signature.length; i++) { // Parameter type is either a primitive type or class. Try both. Class<?> type = primCls.get(signature[i].getType().toLowerCase()); if (type == null) type = Class.forName(signature[i].getType()); params[i] = type; } return findMethod(getMBeanInterface(), methodName, params); }
sb.append(" (O) "); sb.append(oi.getName()).append("("); for(MBeanParameterInfo pi: oi.getSignature()) { String name = pi.getName(); String type = toPrintableType(pi.getType()); sb.append(type).append(' ').append(name).append(", "); if (oi.getSignature().length > 0) { sb.setLength(sb.length() - 2);
log.info(" ** NAME: \t" + opInfo[i].getName()); log.info(" DESCR: \t" + opInfo[i].getDescription()); log.info(" PARAM: \t" + opInfo[i].getSignature().length + " parameter(s)");
this.allowedOperations = new HashMap<>(operationInfo.length); for (MBeanOperationInfo infoEle : operationInfo) { Class<?>[] paramTypes = JmxUtils.parameterInfoToTypes(infoEle.getSignature(), this.beanClassLoader); this.allowedOperations.put(new MethodCacheKey(infoEle.getName(), paramTypes), infoEle);
/** * Extracts the Method from the MBeanOperationInfo * * @param op * * @return a Method */ private Method getMethod(MBeanOperationInfo op) { final MBeanParameterInfo[] params = op.getSignature(); final String[] paramTypes = new String[params.length]; for (int i = 0; i < params.length; i++) paramTypes[i] = params[i].getType(); return getMethod(getMBeanInterface(), op.getName(), paramTypes); }
result = "Operation " + parse.getCmd() + " not found."; } else { MBeanParameterInfo[] paraminfos = op.getSignature(); int paraminfosLength = (paraminfos == null) ? 0 : paraminfos.length; int objsLength = (parse.getArgs() == null) ? 0 : parse.getArgs().length;
@Test public void testSetNameParameterIsNamed() throws Exception { ModelMBeanInfo info = getMBeanInfoFromAssembler(); MBeanOperationInfo operationSetAge = info.getOperation("setName"); assertEquals("name", operationSetAge.getSignature()[0].getName()); }
assert opInfo.getSignature().length == 2; else { assert opInfo.getDescription().equals("MBeanSuperOperation.") == true; assert opInfo.getSignature().length == 1; for (MBeanParameterInfo paramInfo : info.getOperations()[0].getSignature()) { if (paramInfo.getName().equals("ignored")) assert paramInfo.getDescription().equals("MBeanOperationParameter1.") == true;
private OperationMapInfo(MBeanOperationInfo pInfo, boolean pRetTypeMapped) { retTypeMapped = pRetTypeMapped; origTypes = new String[pInfo.getSignature().length]; openMBeanTypes = new OpenType[pInfo.getSignature().length]; signature = new String[pInfo.getSignature().length]; idx = 0; paramMapped = false; }
/** * Extract a list of operation signatures which match a certain operation name. The returned list * can contain multiple signature in case of overloaded JMX operations. * * @param pServer server from where to fetch the MBean info for a given request's object name * @param pRequest the JMX request * @param pOperation the operation whose signature should be extracted * @return a list of signature. If the operation is overloaded, this contains mutliple entries, * otherwise only a single entry is contained */ private List<MBeanParameterInfo[]> extractMBeanParameterInfos(MBeanServerConnection pServer, JmxExecRequest pRequest, String pOperation) throws InstanceNotFoundException, ReflectionException, IOException { try { MBeanInfo mBeanInfo = pServer.getMBeanInfo(pRequest.getObjectName()); List<MBeanParameterInfo[]> paramInfos = new ArrayList<MBeanParameterInfo[]>(); for (MBeanOperationInfo opInfo : mBeanInfo.getOperations()) { if (opInfo.getName().equals(pOperation)) { paramInfos.add(opInfo.getSignature()); } } if (paramInfos.size() == 0) { throw new IllegalArgumentException("No operation " + pOperation + " found on MBean " + pRequest.getObjectNameAsString()); } return paramInfos; } catch (IntrospectionException e) { throw new IllegalStateException("Cannot extract MBeanInfo for " + pRequest.getObjectNameAsString(),e); } }
private Object invokeOperation(Message<?> requestMessage, ObjectName objectName, String operation, Map<String, Object> paramsFromMessage) throws JMException, IOException { MBeanInfo mbeanInfo = this.server.getMBeanInfo(objectName); MBeanOperationInfo[] opInfoArray = mbeanInfo.getOperations(); boolean hasNoArgOption = false; for (MBeanOperationInfo opInfo : opInfoArray) { if (operation.equals(opInfo.getName())) { MBeanParameterInfo[] paramInfoArray = opInfo.getSignature(); if (paramInfoArray.length == 0) { hasNoArgOption = true; } if (paramInfoArray.length == paramsFromMessage.size()) { Object[] values = new Object[paramInfoArray.length]; String[] signature = new String[paramInfoArray.length]; int index = populateValuesAndSignature(paramsFromMessage, paramInfoArray, values, signature); if (index == paramInfoArray.length) { return this.server.invoke(objectName, operation, values, signature); } } } } if (hasNoArgOption) { return this.server.invoke(objectName, operation, null, null); } else { throw new MessagingException(requestMessage, "failed to find JMX operation '" + operation + "' on MBean [" + objectName + "] of type [" + mbeanInfo.getClassName() + "] with " + paramsFromMessage.size() + " parameters: " + paramsFromMessage); } }
JSONObject map = new JSONObject(); JSONArray argList = new JSONArray(); for (MBeanParameterInfo paramInfo : opInfo.getSignature()) { JSONObject args = new JSONObject(); args.put(DESCRIPTION.getKey(), paramInfo.getDescription());
private MBeanParameterInfo[] getWrappedParameterInfo(MBeanOperationInfo pOInfo, OperationMapInfo pMapInfo) { MBeanParameterInfo origParamInfo[] = pOInfo.getSignature(); MBeanParameterInfo paramInfo[] = new MBeanParameterInfo[origParamInfo.length]; for (int j = 0; j < origParamInfo.length; j++) { MBeanParameterInfo pInfo = origParamInfo[j]; String pType; if (isDirectlySupported(pInfo.getType())) { pType = pInfo.getType(); pMapInfo.pushParamTypes(pType, null, null); } else { pType = STRING_TYPE; if (pInfo instanceof OpenMBeanParameterInfo) { pMapInfo.pushParamTypes(STRING_TYPE, pInfo.getType(), ((OpenMBeanParameterInfo) pInfo).getOpenType()); } else { pMapInfo.pushParamTypes(STRING_TYPE, pInfo.getType(), null); } } paramInfo[j] = new MBeanParameterInfo( pInfo.getName(), pType, pInfo.getDescription(), pInfo.getDescriptor() ); } return paramInfo; }
overflow(Overflow.HIDDEN). rightCellPadding(1); MBeanParameterInfo[] parameterInfos = operationInfo.getSignature(); for (MBeanParameterInfo parameterInfo : parameterInfos) { signature.row(parameterInfo.getName(), parameterInfo.getType(), parameterInfo.getDescription());
public static void checkMBeanOperationParameterNaming(ObjectName objectName) throws Exception { MBeanServer mBeanServer = PerThreadMBeanServerLookup.getThreadMBeanServer(); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName); for(MBeanOperationInfo op : mBeanInfo.getOperations()) { for(MBeanParameterInfo param : op.getSignature()) { assertFalse(param.getName().matches("p[0-9]+")); } } }