Merge remote-tracking branch 'upstream/master' into 4.0.0-WIP
Conflicts: spring-integration-core/src/main/java/org/springframework/integration/channel/registry/ChannelRegistry.java spring-integration-core/src/main/java/org/springframework/integration/channel/registry/LocalChannelRegistry.java spring-integration-core/src/main/java/org/springframework/integration/mapping/AbstractHeaderMapper.java spring-integration-core/src/main/java/org/springframework/integration/support/json/AbstractJacksonJsonMessageParser.java spring-integration-core/src/test/java/org/springframework/integration/channel/registry/LocalChannelRegistryTests.java spring-integration-core/src/test/java/org/springframework/integration/handler/ServiceActivatorDefaultFrameworkMethodTests.java spring-integration-jmx/src/test/java/org/springframework/integration/jmx/ServiceActivatorDefaultFrameworkMethodTests.java spring-integration-jmx/src/test/java/org/springframework/integration/jmx/config/OperationInvokingOutboundGatewayTests.java Resolved.
This commit is contained in:
@@ -34,6 +34,7 @@ import javax.management.ObjectName;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.util.ClassUtils;
|
||||
import org.springframework.jmx.support.ObjectNameManager;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
@@ -68,7 +69,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.
|
||||
@@ -134,7 +134,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++;
|
||||
@@ -151,18 +151,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.
|
||||
*/
|
||||
@@ -229,4 +240,4 @@ public class OperationInvokingMessageHandler extends AbstractReplyProducingMessa
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
@@ -33,7 +33,7 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the 'mbean-export' element of the integration JMX namespace.
|
||||
*
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
@@ -61,7 +61,8 @@ public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser {
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "object-name-static-properties");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "managed-components", "componentNamePatterns");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "shutdown-executor");
|
||||
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "object-naming-strategy", "namingStrategy");
|
||||
|
||||
builder.addPropertyValue("server", mbeanServer);
|
||||
this.registerMBeanExporterHelper(parserContext.getRegistry());
|
||||
}
|
||||
@@ -70,7 +71,7 @@ public class MBeanExporterParser extends AbstractSingleBeanDefinitionParser {
|
||||
BeanDefinitionBuilder mBeanExporterHelperBuilder = BeanDefinitionBuilder.rootBeanDefinition(MBeanExporterHelper.class);
|
||||
BeanDefinitionReaderUtils.registerWithGeneratedName(mBeanExporterHelperBuilder.getBeanDefinition(), registry);
|
||||
}
|
||||
|
||||
|
||||
private Object getMBeanServer(Element element, ParserContext parserContext) {
|
||||
String mbeanServer = element.getAttribute("server");
|
||||
if (StringUtils.hasText(mbeanServer)) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import javax.management.DynamicMBean;
|
||||
@@ -80,6 +81,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.ReflectionUtils.FieldCallback;
|
||||
import org.springframework.util.ReflectionUtils.FieldFilter;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -106,6 +109,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
* @author Helena Edelson
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@ManagedResource
|
||||
public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostProcessor, BeanFactoryAware,
|
||||
@@ -163,7 +167,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
|
||||
private final MetadataMBeanInfoAssembler assembler = new MetadataMBeanInfoAssembler(attributeSource);
|
||||
|
||||
private final MetadataNamingStrategy namingStrategy = new MetadataNamingStrategy(attributeSource);
|
||||
private final MetadataNamingStrategy defaultNamingStrategy = new MetadataNamingStrategy(attributeSource);
|
||||
|
||||
private String[] componentNamePatterns = { "*" };
|
||||
|
||||
@@ -179,7 +183,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
super();
|
||||
// Shouldn't be necessary, but to be on the safe side...
|
||||
setAutodetect(false);
|
||||
setNamingStrategy(namingStrategy);
|
||||
setNamingStrategy(defaultNamingStrategy);
|
||||
setAssembler(assembler);
|
||||
}
|
||||
|
||||
@@ -206,7 +210,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
*/
|
||||
public void setDefaultDomain(String domain) {
|
||||
this.domain = domain;
|
||||
this.namingStrategy.setDefaultDomain(domain);
|
||||
this.defaultNamingStrategy.setDefaultDomain(domain);
|
||||
}
|
||||
|
||||
public void setComponentNamePatterns(String[] componentNamePatterns) {
|
||||
@@ -217,7 +221,7 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
super.setBeanFactory(beanFactory);
|
||||
Assert.isTrue(beanFactory instanceof ListableBeanFactory, "A ListableBeanFactory is required.");
|
||||
Assert.isInstanceOf(ListableBeanFactory.class, beanFactory, "A ListableBeanFactory is required.");
|
||||
this.beanFactory = (ListableBeanFactory) beanFactory;
|
||||
}
|
||||
|
||||
@@ -246,6 +250,12 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
}
|
||||
|
||||
if (bean instanceof MessageHandler) {
|
||||
if (this.handlerInAnonymousWrapper(bean) != null) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Skipping " + beanName + " because it wraps another handler");
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
SimpleMessageHandlerMetrics monitor = new SimpleMessageHandlerMetrics((MessageHandler) bean);
|
||||
Object advised = applyHandlerInterceptor(bean, monitor, beanClassLoader);
|
||||
handlers.add(monitor);
|
||||
@@ -282,6 +292,33 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
|
||||
}
|
||||
|
||||
private MessageHandler handlerInAnonymousWrapper(final Object bean) {
|
||||
if (bean != null && bean.getClass().isAnonymousClass()) {
|
||||
final AtomicReference<MessageHandler> wrapped = new AtomicReference<MessageHandler>();
|
||||
ReflectionUtils.doWithFields(bean.getClass(), new FieldCallback() {
|
||||
|
||||
@Override
|
||||
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
|
||||
field.setAccessible(true);
|
||||
Object handler = field.get(bean);
|
||||
if (handler instanceof MessageHandler) {
|
||||
wrapped.set((MessageHandler) handler);
|
||||
}
|
||||
}
|
||||
}, new FieldFilter() {
|
||||
|
||||
@Override
|
||||
public boolean matches(Field field) {
|
||||
return wrapped.get() == null && field.getName().startsWith("val$");
|
||||
}
|
||||
});
|
||||
return wrapped.get();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy of private method in super class. Needed so we can avoid using the bean factory to extract the bean again,
|
||||
* and risk it being a proxy (which it almost certainly is by now).
|
||||
@@ -987,20 +1024,22 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
String source = "endpoint";
|
||||
Object endpoint = null;
|
||||
|
||||
MessageHandler messageHandler = monitor.getMessageHandler();
|
||||
|
||||
for (String beanName : names) {
|
||||
endpoint = beanFactory.getBean(beanName);
|
||||
Object field = null;
|
||||
try {
|
||||
field = extractTarget(getField(endpoint, "handler"));
|
||||
Object field = extractTarget(getField(endpoint, "handler"));
|
||||
if (field == messageHandler ||
|
||||
this.extractTarget(this.handlerInAnonymousWrapper(field)) == messageHandler) {
|
||||
name = beanName;
|
||||
endpointName = beanName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.trace("Could not get handler from bean = " + beanName);
|
||||
}
|
||||
if (field == monitor.getMessageHandler()) {
|
||||
name = beanName;
|
||||
endpointName = beanName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (name != null && endpoint != null && name.startsWith("_org.springframework.integration")) {
|
||||
name = getInternalComponentName(name);
|
||||
@@ -1044,11 +1083,11 @@ public class IntegrationMBeanExporter extends MBeanExporter implements BeanPostP
|
||||
}
|
||||
|
||||
if (name == null) {
|
||||
if (monitor.getMessageHandler() instanceof NamedComponent) {
|
||||
name = ((NamedComponent) monitor.getMessageHandler()).getComponentName();
|
||||
if (messageHandler instanceof NamedComponent) {
|
||||
name = ((NamedComponent) messageHandler).getComponentName();
|
||||
}
|
||||
if (name == null) {
|
||||
name = monitor.getMessageHandler().toString();
|
||||
name = messageHandler.toString();
|
||||
}
|
||||
source = "handler";
|
||||
}
|
||||
|
||||
@@ -204,6 +204,19 @@
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="object-naming-strategy" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation kind="ref">
|
||||
<tool:expected-type type="org.springframework.jmx.export.naming.ObjectNamingStrategy" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
<xsd:documentation>
|
||||
An ObjectNamingStrategy to generate the MBean's ObjectName. See the reference documentation
|
||||
for details of the default ObjectName. Also see 'object-name-static-properties'.
|
||||
</xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
|
||||
@@ -6,6 +6,6 @@ log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m
|
||||
|
||||
|
||||
log4j.category.org.springframework=WARN
|
||||
log4j.category.org.springframework.integration=DEBUG
|
||||
log4j.category.org.springframework.beans.factory=DEBUG
|
||||
#log4j.category.org.springframework.integration=DEBUG
|
||||
#log4j.category.org.springframework.beans.factory=DEBUG
|
||||
#log4j.category.org.springframework.integration.monitor=TRACE
|
||||
|
||||
@@ -27,19 +27,19 @@
|
||||
<service-activator id="replyingHandlerWithStandardMethodTestService"
|
||||
input-channel="replyingHandlerWithStandardMethodTestInputChannel"
|
||||
method="handleMessage">
|
||||
<beans:bean
|
||||
<beans:bean id="innerReplyingHandler"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestReplyingMessageHandler"/>
|
||||
</service-activator>
|
||||
|
||||
<service-activator id="replyingHandlerWithOtherMethodTestService"
|
||||
input-channel="replyingHandlerWithOtherMethodTestInputChannel"
|
||||
method="foo">
|
||||
<beans:bean
|
||||
<beans:bean id="innerReplyingHandlerFoo"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestReplyingMessageHandler"/>
|
||||
</service-activator>
|
||||
|
||||
<service-activator id="handlerTestService" input-channel="handlerTestInputChannel">
|
||||
<beans:bean
|
||||
<beans:bean id="innerHandler"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestMessageHandler"/>
|
||||
</service-activator>
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:int-jmx="http://www.springframework.org/schema/integration/jmx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
|
||||
|
||||
<context:mbean-server/>
|
||||
<int-jmx:mbean-export default-domain="test2"/>
|
||||
|
||||
<service-activator id="optimizedRefReplyingHandlerTestService1"
|
||||
input-channel="optimizedRefReplyingHandlerTestInputChannel" ref="testReplyingMessageHandler"/>
|
||||
|
||||
<service-activator id="optimizedRefReplyingHandlerTestService2"
|
||||
input-channel="optimizedRefReplyingHandlerTestInputChannel" ref="testReplyingMessageHandler"/>
|
||||
|
||||
<beans:bean id="testReplyingMessageHandler"
|
||||
class="org.springframework.integration.jmx.ServiceActivatorDefaultFrameworkMethodTests$TestReplyingMessageHandler"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -17,18 +17,26 @@
|
||||
package org.springframework.integration.jmx;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.util.StackTraceUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
@@ -92,7 +100,7 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
assertEquals("TEST", reply.getPayload());
|
||||
assertEquals("replyingHandlerTestInputChannel,replyingHandlerTestService", reply.getHeaders().get("history").toString());
|
||||
StackTraceElement[] st = (StackTraceElement[]) reply.getHeaders().get("callStack");
|
||||
assertEquals("doDispatch", st[15].getMethodName()); // close to the metal
|
||||
assertTrue(StackTraceUtils.isFrameContainingXBeforeFrameContainingY("Dispatcher", "MethodInvokerHelper", st));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +113,7 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
assertEquals("optimizedRefReplyingHandlerTestInputChannel,optimizedRefReplyingHandlerTestService",
|
||||
reply.getHeaders().get("history").toString());
|
||||
StackTraceElement[] st = (StackTraceElement[]) reply.getHeaders().get("callStack");
|
||||
assertEquals("doDispatch", st[15].getMethodName());
|
||||
assertTrue(StackTraceUtils.isFrameContainingXBeforeFrameContainingY("Dispatcher", "MethodInvokerHelper", st));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,7 +125,7 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
assertEquals("TEST", reply.getPayload());
|
||||
assertEquals("replyingHandlerWithStandardMethodTestInputChannel,replyingHandlerWithStandardMethodTestService", reply.getHeaders().get("history").toString());
|
||||
StackTraceElement[] st = (StackTraceElement[]) reply.getHeaders().get("callStack");
|
||||
assertEquals("doDispatch", st[15].getMethodName()); // close to the metal
|
||||
assertTrue(StackTraceUtils.isFrameContainingXBeforeFrameContainingY("Dispatcher", "MethodInvokerHelper", st));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,6 +159,23 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
assertEquals("processorTestInputChannel,processorTestService", reply.getHeaders().get("history").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailOnDoubleReference() {
|
||||
try {
|
||||
new ClassPathXmlApplicationContext(this.getClass().getSimpleName() + "-fail-context.xml",
|
||||
this.getClass());
|
||||
fail("Expected exception due to 2 endpoints referencing the same bean");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e, Matchers.instanceOf(BeanCreationException.class));
|
||||
assertThat(e.getCause(), Matchers.instanceOf(BeanCreationException.class));
|
||||
assertThat(e.getCause().getCause(), Matchers.instanceOf(IllegalArgumentException.class));
|
||||
assertThat(e.getCause().getCause().getMessage(),
|
||||
Matchers.containsString("An AbstractReplyProducingMessageHandler may only be referenced once"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private interface Foo {
|
||||
|
||||
public String foo(String in);
|
||||
@@ -169,6 +194,10 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
}
|
||||
|
||||
public String foo(String in) {
|
||||
Exception e = new RuntimeException();
|
||||
StackTraceElement[] st = e.getStackTrace();
|
||||
// use this to test that StackTraceUtils works as expected and returns false
|
||||
assertFalse(StackTraceUtils.isFrameContainingXBeforeFrameContainingY("Dispatcher", "MethodInvokerHelper", st));
|
||||
return "bar";
|
||||
}
|
||||
|
||||
@@ -181,7 +210,7 @@ public class ServiceActivatorDefaultFrameworkMethodTests {
|
||||
public void handleMessage(Message<?> requestMessage) {
|
||||
Exception e = new RuntimeException();
|
||||
StackTraceElement[] st = e.getStackTrace();
|
||||
assertEquals("doDispatch", st[28].getMethodName());
|
||||
assertTrue(StackTraceUtils.isFrameContainingXBeforeFrameContainingY("Dispatcher", "MethodInvokerHelper", st));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,14 @@
|
||||
<jmx:mbean-export id="integratioMbeanExporter"
|
||||
server="mbs"
|
||||
default-domain="tests.MBeanExpoerterParser"
|
||||
object-name-static-properties="appProperties"/>
|
||||
object-name-static-properties="appProperties"
|
||||
object-naming-strategy="keyNamer"/>
|
||||
|
||||
<util:properties id="appProperties">
|
||||
<prop key="foo">foo</prop>
|
||||
<prop key="bar">bar</prop>
|
||||
</util:properties>
|
||||
|
||||
<bean id="keyNamer" class="org.springframework.jmx.export.naming.KeyNamingStrategy" />
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.jmx.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Properties;
|
||||
@@ -57,6 +58,7 @@ public class MBeanExporterParserTests {
|
||||
assertTrue(properties.containsKey("foo"));
|
||||
assertTrue(properties.containsKey("bar"));
|
||||
assertEquals(server, exporter.getServer());
|
||||
assertSame(context.getBean("keyNamer"), TestUtils.getPropertyValue(exporter, "namingStrategy"));
|
||||
exporter.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/integration/jmx
|
||||
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
|
||||
|
||||
<jmx:mbean-export id="integrationMbeanExporter" server="mbs" default-domain="test.MBeanRegistration"
|
||||
object-naming-strategy="namer" />
|
||||
|
||||
<bean id="namer" class="org.springframework.integration.jmx.config.MBeanRegistrationCustomNamingTests$Namer" />
|
||||
|
||||
<context:mbean-server id="mbs" />
|
||||
|
||||
<int:channel id="testChannel" />
|
||||
|
||||
<int:service-activator id="service" input-channel="testChannel" method="get">
|
||||
<bean class="org.springframework.integration.jmx.config.MBeanRegistrationCustomNamingTests$Source"/>
|
||||
</int:service-activator>
|
||||
|
||||
<int:logging-channel-adapter id="logger" channel="testChannel"/>
|
||||
|
||||
<int:chain id="chain" input-channel="chainin">
|
||||
<int:transformer id="t1" expression="'foo'"/>
|
||||
<int:filter id="f1" expression="true"/>
|
||||
</int:chain>
|
||||
|
||||
</beans>
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright 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. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.jmx.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.management.MBeanServer;
|
||||
import javax.management.MalformedObjectNameException;
|
||||
import javax.management.ObjectName;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jmx.export.naming.KeyNamingStrategy;
|
||||
import org.springframework.jmx.export.naming.ObjectNamingStrategy;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Gary Russell
|
||||
* @since 3.0
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class MBeanRegistrationCustomNamingTests {
|
||||
|
||||
@Autowired
|
||||
private MBeanServer server;
|
||||
|
||||
@Test
|
||||
public void testHandlerMBeanRegistration() throws Exception {
|
||||
Set<ObjectName> names = server.queryNames(new ObjectName("test.MBeanRegistration:type=Integration,componentType=MessageHandler,*"), null);
|
||||
assertEquals(6, names.size());
|
||||
assertTrue(names.contains(new ObjectName("test.MBeanRegistration:type=Integration,componentType=MessageHandler,name=chain,bean=endpoint")));
|
||||
assertTrue(names.contains(new ObjectName("test.MBeanRegistration:type=Integration,componentType=MessageHandler,name=chain$child.t1,bean=handler")));
|
||||
assertTrue(names.contains(new ObjectName("test.MBeanRegistration:type=Integration,componentType=MessageHandler,name=chain$child.f1,bean=handler")));
|
||||
}
|
||||
|
||||
public static class Source {
|
||||
public String get() {
|
||||
return "foo";
|
||||
}
|
||||
}
|
||||
|
||||
public static class Namer implements ObjectNamingStrategy {
|
||||
|
||||
private final ObjectNamingStrategy realNamer = new KeyNamingStrategy();
|
||||
@Override
|
||||
public ObjectName getObjectName(Object managedBean, String beanKey) throws MalformedObjectNameException {
|
||||
String actualBeanKey = beanKey.replace("type=", "type=Integration,componentType=");
|
||||
return realNamer.getObjectName(managedBean, actualBeanKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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"/>
|
||||
|
||||
@@ -17,31 +17,40 @@
|
||||
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.handler.advice.AbstractRequestHandlerAdvice;
|
||||
import org.springframework.integration.jmx.OperationInvokingMessageHandler;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHandler;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
|
||||
import org.springframework.integration.jmx.OperationInvokingMessageHandler;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
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
|
||||
@@ -49,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
|
||||
@@ -90,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"));
|
||||
@@ -102,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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user