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

@@ -33,6 +33,14 @@
</jmx:request-handler-advice-chain>
</jmx:operation-invoking-outbound-gateway>
<si:channel id="primitiveChannel"/>
<jmx:operation-invoking-outbound-gateway request-channel="primitiveChannel"
reply-channel="withReplyChannelOutput"
object-name="org.springframework.integration.jmx.config:type=TestBean,name=testBeanGateway"
operation-name="testPrimitiveArgs"
requires-reply="false" />
<si:chain id="operationInvokingWithinChain" input-channel="jmxOutboundGatewayInsideChain" output-channel="withReplyChannelOutput">
<jmx:operation-invoking-outbound-gateway operation-name="testWithReturn" requires-reply="true"
object-name="org.springframework.integration.jmx.config:type=TestBean,name=testBeanGateway"/>

View File

@@ -17,17 +17,25 @@
package org.springframework.integration.jmx.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.MessagingException;
import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.core.PollableChannel;
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
@@ -38,9 +46,11 @@ import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Gary Russell
*
*/
@ContextConfiguration
@@ -48,15 +58,15 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
public class OperationInvokingOutboundGatewayTests {
@Autowired
@Qualifier("withReplyChannel")
private MessageChannel withReplyChannel;
@Autowired
@Qualifier("withReplyChannelOutput")
private MessageChannel primitiveChannel;
@Autowired
private PollableChannel withReplyChannelOutput;
@Autowired
@Qualifier("withNoReplyChannel")
private MessageChannel withNoReplyChannel;
@Autowired
@@ -89,6 +99,42 @@ public class OperationInvokingOutboundGatewayTests {
assertEquals(3, adviceCalled);
}
@Test
public void gatewayWithPrimitiveArgs() throws Exception {
primitiveChannel.send(new GenericMessage<Object[]>(new Object[] { true, 0L, 1 }));
assertEquals(1, testBean.messages.size());
List<Object> argList = new ArrayList<Object>();
argList.add(false);
argList.add(123L);
argList.add(42);
primitiveChannel.send(new GenericMessage<List<Object>>(argList));
assertEquals(2, testBean.messages.size());
Map<String, Object> argMap = new HashMap<String, Object>();
argMap.put("p1", true);
argMap.put("p2", 0L);
argMap.put("p3", 42);
primitiveChannel.send(new GenericMessage<Map<String, Object>>(argMap));
assertEquals(3, testBean.messages.size());
argMap.put("p2", true);
argMap.put("p1", 0L);
argMap.put("p3", 42);
try {
primitiveChannel.send(new GenericMessage<Map<String, Object>>(argMap));
fail("Expected Exception");
}
catch (Exception e) {
assertThat(e, Matchers.instanceOf(MessagingException.class));
assertThat(e.getMessage(), Matchers.containsString("failed to find JMX operation"));
}
// TODO: Uncomment when Spring Framework minimum is 3.2.3
// argMap = new HashMap<String, Object>();
// argMap.put("bool", true);
// argMap.put("time", 0L);
// argMap.put("foo", 42);
// primitiveChannel.send(new GenericMessage<Map<String, Object>>(argMap));
// assertEquals(4, testBean.messages.size());
}
@Test
public void gatewayWithNoReplyChannel() throws Exception {
withNoReplyChannel.send(new GenericMessage<String>("1"));
@@ -101,7 +147,7 @@ public class OperationInvokingOutboundGatewayTests {
@Test //INT-1029, INT-2822
public void testOutboundGatewayInsideChain() throws Exception {
List handlers = TestUtils.getPropertyValue(this.operationInvokingWithinChain, "handlers", List.class);
List<?> handlers = TestUtils.getPropertyValue(this.operationInvokingWithinChain, "handlers", List.class);
assertEquals(1, handlers.size());
Object handler = handlers.get(0);
assertTrue(handler instanceof OperationInvokingMessageHandler);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@ import org.springframework.jmx.export.annotation.ManagedResource;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gary Russell
* @since 2.0
*/
@ManagedResource
@@ -42,11 +43,16 @@ public class TestBean {
public void test(String text) {
this.messages.add(text);
}
@ManagedOperation
public List<String> testWithReturn(String text) {
this.messages.add(text);
return messages;
}
@ManagedOperation
public void testPrimitiveArgs(boolean bool, long time, int foo) {
this.messages.add(bool + " " + time + " " + foo);
}
}