use of javax.management.MBeanOperationInfo in project jdk8u_jdk by JetBrains.
the class MXBeanIntrospector method getMBeanOperationInfo.
@Override
MBeanOperationInfo getMBeanOperationInfo(String operationName, ConvertingMethod operation) {
final Method method = operation.getMethod();
final String description = operationName;
/* Ideally this would be an empty string, but
OMBOperationInfo constructor forbids that. Also, we
could consult an annotation to get a useful
description. */
final int impact = MBeanOperationInfo.UNKNOWN;
final OpenType<?> returnType = operation.getOpenReturnType();
final Type originalReturnType = operation.getGenericReturnType();
final OpenType<?>[] paramTypes = operation.getOpenParameterTypes();
final Type[] originalParamTypes = operation.getGenericParameterTypes();
final MBeanParameterInfo[] params = new MBeanParameterInfo[paramTypes.length];
boolean openReturnType = canUseOpenInfo(originalReturnType);
boolean openParameterTypes = true;
Annotation[][] annots = method.getParameterAnnotations();
for (int i = 0; i < paramTypes.length; i++) {
final String paramName = "p" + i;
final String paramDescription = paramName;
final OpenType<?> openType = paramTypes[i];
final Type originalType = originalParamTypes[i];
Descriptor descriptor = typeDescriptor(openType, originalType);
descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForAnnotations(annots[i]));
final MBeanParameterInfo pi;
if (canUseOpenInfo(originalType)) {
pi = new OpenMBeanParameterInfoSupport(paramName, paramDescription, openType, descriptor);
} else {
openParameterTypes = false;
pi = new MBeanParameterInfo(paramName, originalTypeString(originalType), paramDescription, descriptor);
}
params[i] = pi;
}
Descriptor descriptor = typeDescriptor(returnType, originalReturnType);
descriptor = ImmutableDescriptor.union(descriptor, Introspector.descriptorForElement(method));
final MBeanOperationInfo oi;
if (openReturnType && openParameterTypes) {
/* If the return value and all the parameters can be faithfully
* represented as OpenType then we return an OpenMBeanOperationInfo.
* If any of them is a primitive type, we can't. Compatibility
* with JSR 174 means that we must return an MBean*Info where
* the getType() is the primitive type, not its wrapped type as
* we would get with an OpenMBean*Info. The OpenType is available
* in the Descriptor in either case.
*/
final OpenMBeanParameterInfo[] oparams = new OpenMBeanParameterInfo[params.length];
System.arraycopy(params, 0, oparams, 0, params.length);
oi = new OpenMBeanOperationInfoSupport(operationName, description, oparams, returnType, impact, descriptor);
} else {
oi = new MBeanOperationInfo(operationName, description, params, openReturnType ? returnType.getClassName() : originalTypeString(originalReturnType), impact, descriptor);
}
return oi;
}
use of javax.management.MBeanOperationInfo in project felix by apache.
the class MBeanProxyFactory method getSignatures.
/**
* Internal method for generating the signatures of the mbeans.
* @param objectName
* @return
* @throws IOException
* @throws ReflectionException
* @throws IntrospectionException
* @throws InstanceNotFoundException
*/
private List<Signature> getSignatures(ObjectName objectName) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
List<Signature> methods = new ArrayList<Signature>();
MBeanInfo minfo;
MBeanAttributeInfo[] attributes = null;
minfo = mbeanServer.getMBeanInfo(objectName);
attributes = minfo.getAttributes();
for (MBeanAttributeInfo info : attributes) {
String name = info.getName().substring(0, 1).toUpperCase() + info.getName().substring(1);
if (info.isReadable()) {
// when it is being used on the remote side)
if (info.isIs()) {
methods.add(new Signature("is" + name, Type.BOOLEAN_TYPE, new Type[0]));
} else {
try {
methods.add(new Signature("get" + name, getType(info.getType()), new Type[0]));
} catch (ClassNotFoundException cnfe) {
System.out.println("JMXINTROSPECTOR WARNING: " + info.getType() + " could not be found. Attribute will not be added to proxy.");
continue;
}
}
}
// Same with each writable att, but with setters.
if (info.isWritable()) {
try {
Type[] params = new Type[] { getType(info.getType()) };
Signature s = new Signature("set" + name, Type.VOID_TYPE, params);
methods.add(s);
} catch (ClassNotFoundException cnfe) {
System.out.println("JMXINTROSPECTOR WARNING: " + info.getType() + " could not be found. Attribute will not be added to proxy.");
continue;
}
}
}
// same for each operation
for (MBeanOperationInfo info : minfo.getOperations()) {
try {
Type[] params = new Type[info.getSignature().length];
for (int i = 0; i < params.length; i++) {
params[i] = getType(info.getSignature()[i].getType());
}
Signature s = new Signature(info.getName(), getType(info.getReturnType()), params);
methods.add(s);
} catch (ClassNotFoundException cnfe) {
System.out.println("JMXINTROSPECTOR WARNING: " + info.toString() + " could not be created. Operation will not be added to proxy.");
continue;
}
}
return methods;
}
use of javax.management.MBeanOperationInfo in project felix by apache.
the class InvokeOperationCommandProcessor method executeRequest.
public Document executeRequest(HttpInputStream in) throws IOException, JMException {
Document document = builder.newDocument();
Element root = document.createElement("MBeanOperation");
document.appendChild(root);
Element operationElement = document.createElement("Operation");
operationElement.setAttribute("operation", "invoke");
root.appendChild(operationElement);
String objectVariable = in.getVariable("objectname");
String operationVariable = in.getVariable("operation");
if (objectVariable == null || objectVariable.equals("") || operationVariable == null || operationVariable.equals("")) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Incorrect parameters in the request");
return document;
}
operationElement.setAttribute("objectname", objectVariable);
List types = new ArrayList();
List values = new ArrayList();
int i = 0;
boolean unmatchedParameters = false;
boolean valid = false;
do {
String parameterType = in.getVariable("type" + i);
String parameterValue = in.getVariable("value" + i);
valid = (parameterType != null && parameterValue != null);
if (valid) {
types.add(parameterType);
Object value = null;
try {
value = CommandProcessorUtil.createParameterValue(parameterType, parameterValue);
} catch (Exception e) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Parameter " + i + ": " + parameterValue + " cannot be converted to type " + parameterType);
return document;
}
if (value != null) {
values.add(value);
}
}
if (parameterType == null ^ parameterValue == null) {
unmatchedParameters = true;
break;
}
i++;
} while (valid);
if (objectVariable == null || objectVariable.equals("") || operationVariable == null || operationVariable.equals("")) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Incorrect parameters in the request");
return document;
}
if (unmatchedParameters) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "count of parameter types doesn't match count of parameter values");
return document;
}
ObjectName name = null;
try {
name = new ObjectName(objectVariable);
} catch (MalformedObjectNameException e) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Malformed object name");
return document;
}
if (server.isRegistered(name)) {
MBeanInfo info = server.getMBeanInfo(name);
MBeanOperationInfo[] operations = info.getOperations();
boolean match = false;
if (operations != null) {
for (int j = 0; j < operations.length; j++) {
if (operations[j].getName().equals(operationVariable)) {
MBeanParameterInfo[] parameters = operations[j].getSignature();
if (parameters.length != types.size()) {
continue;
}
Iterator k = types.iterator();
boolean signatureMatch = true;
for (int p = 0; p < types.size(); p++) {
if (!parameters[p].getType().equals(k.next())) {
signatureMatch = false;
break;
}
}
match = signatureMatch;
}
if (match) {
break;
}
}
}
if (!match) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", "Operation singature has no match in the MBean");
} else {
try {
Object[] params = values.toArray();
String[] signature = new String[types.size()];
types.toArray(signature);
Object returnValue = server.invoke(name, operationVariable, params, signature);
operationElement.setAttribute("result", "success");
if (returnValue != null) {
operationElement.setAttribute("returnclass", returnValue.getClass().getName());
operationElement.setAttribute("return", returnValue.toString());
} else {
operationElement.setAttribute("returnclass", null);
operationElement.setAttribute("return", null);
}
} catch (Exception e) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", e.getMessage());
}
}
} else {
if (name != null) {
operationElement.setAttribute("result", "error");
operationElement.setAttribute("errorMsg", new StringBuffer("MBean ").append(name).append(" not registered").toString());
}
}
return document;
}
use of javax.management.MBeanOperationInfo in project Payara by payara.
the class AMXTest method checkReturnTypes.
/**
* Verify:
* <ul>
* <li>that all return types are suitable for the API</li>
* </ul>
*/
public void checkReturnTypes(final ObjectName objectName) throws Exception {
final AMX proxy = getProxyFactory().getProxy(objectName, AMX.class);
final MBeanInfo info = Util.getExtra(proxy).getMBeanInfo();
final MBeanOperationInfo[] operations = info.getOperations();
boolean emittedName = false;
for (int i = 0; i < operations.length; ++i) {
final MBeanOperationInfo opInfo = operations[i];
final String returnType = opInfo.getReturnType();
if (!isSuitableReturnTypeForAPI(returnType)) {
if (!emittedName) {
emittedName = true;
trace("\n" + objectName);
}
trace("WARNING: unsuitable return type in API: " + returnType + " " + opInfo.getName() + "(...)");
}
}
}
use of javax.management.MBeanOperationInfo in project Payara by payara.
the class AMXTest method checkCreateRemoveGet.
/**
* Verify:
* <ul>
* <li>each create() or createAbc() method ends in "Config" if it returns an AMXConfig subclass</li>
* <li>each remove() or removeAbc() method ends in "Config"</li>
* </ul>
*/
public void checkCreateRemoveGet(final ObjectName objectName) throws Exception {
final AMX proxy = getProxyFactory().getProxy(objectName, AMX.class);
if (proxy instanceof Container) {
final Method[] methods = getInterfaceClass(proxy).getMethods();
final MBeanInfo mbeanInfo = Util.getExtra(proxy).getMBeanInfo();
final MBeanOperationInfo[] operations = mbeanInfo.getOperations();
for (int methodIdx = 0; methodIdx < methods.length; ++methodIdx) {
final Method method = methods[methodIdx];
final String methodName = method.getName();
if (methodName.startsWith("create") && !methodName.endsWith("Config")) {
if (AMXConfig.class.isAssignableFrom(method.getReturnType()) && (!(proxy instanceof SecurityMapConfig))) {
trace("WARNING: method " + methodName + " does not end in 'Config': " + objectName);
}
} else if (methodName.startsWith("remove") && !methodName.endsWith("Config") && proxy instanceof AMXConfig) {
if (// method.getReturnType() == Void.class &&
method.getParameterTypes().length == 1 && method.getParameterTypes()[0] == String.class && !method.getName().equals("removeProperty") && !method.getName().equals("removeSystemProperty") && (!(proxy instanceof SecurityMapConfig))) {
trace("WARNING: method " + methodName + " does not end in 'Config': " + methodName);
}
}
}
}
}
Aggregations