INT-3182 Fix JMX Operation Invoking With Primitive

Previously, methods with primitive parameters were not matched
with primitive wrapper objects.

Check, if the argument is a primitive wrapper, that the paramer type
can be the equivalent primitive.

Add test case.

INT-3182 Polishing - PR Comments

Extract PrimitiveWrapper->Primitive map to ClassUtils.

JIRA: https://jira.springsource.org/browse/INT-3182
This commit is contained in:
Gary Russell
2013-10-31 15:43:35 +02:00
committed by Artem Bilan
parent eaa28a9dbf
commit 435064453f
5 changed files with 113 additions and 12 deletions

View File

@@ -37,6 +37,7 @@ import org.springframework.integration.MessageHandlingException;
import org.springframework.integration.MessagingException;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.util.ClassUtils;
import org.springframework.jmx.support.ObjectNameManager;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -69,7 +70,6 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa
private volatile String operationName;
/**
* Provide a reference to the MBeanServer within which the MBean
* target for operation invocation has been registered.
@@ -135,7 +135,7 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa
*/
value = paramsFromMessage.get("p" + (index + 1));
}
if (value != null && value.getClass().getName().equals(paramInfo.getType())) {
if (value != null && valueTypeMatchesParameterType(value, paramInfo)) {
values[index] = value;
signature[index] = paramInfo.getType();
index++;
@@ -152,18 +152,29 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa
}
throw new MessagingException(requestMessage, "failed to find JMX operation '"
+ operationName + "' on MBean [" + objectName + "] of type [" + mbeanInfo.getClassName()
+ "] with " + paramsFromMessage.size() + " parameters: " + paramsFromMessage.keySet());
+ "] with " + paramsFromMessage.size() + " parameters: " + paramsFromMessage);
}
catch (JMException e) {
throw new MessageHandlingException(requestMessage, "failed to invoke JMX operation '" +
operationName + "' on MBean [" + objectName + "]" + " with " +
paramsFromMessage.size() + " parameters: " + paramsFromMessage.keySet(), e);
paramsFromMessage.size() + " parameters: " + paramsFromMessage, e);
}
catch (IOException e) {
throw new MessageHandlingException(requestMessage, "IOException on MBeanServerConnection", e);
}
}
private boolean valueTypeMatchesParameterType(Object value, MBeanParameterInfo paramInfo) {
Class<? extends Object> valueClass = value.getClass();
if (valueClass.getName().equals(paramInfo.getType())) {
return true;
}
else {
Class<?> primitiveType = ClassUtils.resolvePrimitiveType(valueClass);
return primitiveType != null && primitiveType.getName().equals(paramInfo.getType());
}
}
/**
* First checks if defaultObjectName is set, otherwise falls back on {@link JmxHeaders#OBJECT_NAME} header.
*/