INT-3565 ClassCastException with Proxy and DEBUG
JIRA: https://jira.spring.io/browse/INT-3565 Cast to `IntegrationObjectSupport` fails if the handler is already proxied in `AbstractSimpleMessageHandlerFactoryBean`. INT-3565 Polishing - Fix test. - enhance test to show that directly bound message handler beans are not advised if already proxied.
This commit is contained in:
committed by
Artem Bilan
parent
266af04bb6
commit
224eef3149
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2002-2014 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.monitor;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
*/
|
||||
public class TransformerContextTests {
|
||||
|
||||
private static volatile int adviceCalled;
|
||||
|
||||
private static volatile int bazCalled;
|
||||
|
||||
@Test
|
||||
public void methodInvokingTransformer() {
|
||||
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"transformerContextTests.xml", this.getClass());
|
||||
MessageChannel input = context.getBean("input", MessageChannel.class);
|
||||
PollableChannel output = context.getBean("output", PollableChannel.class);
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
Message<?> reply = output.receive(0);
|
||||
assertEquals("FOO", reply.getPayload());
|
||||
assertEquals(1, adviceCalled);
|
||||
|
||||
input = context.getBean("direct", MessageChannel.class);
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
reply = output.receive(0);
|
||||
assertEquals("FOO", reply.getPayload());
|
||||
|
||||
input = context.getBean("directRef", MessageChannel.class);
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
reply = output.receive(0);
|
||||
assertEquals("FOO", reply.getPayload());
|
||||
assertEquals(2, adviceCalled);
|
||||
|
||||
input = context.getBean("service", MessageChannel.class);
|
||||
input.send(new GenericMessage<String>("foo"));
|
||||
assertEquals(1, bazCalled);
|
||||
assertEquals(3, adviceCalled);
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
||||
public static class FooAdvice extends AbstractRequestHandlerAdvice {
|
||||
|
||||
@Override
|
||||
protected Object doInvoke(ExecutionCallback callback, Object target, Message<?> message) throws Exception {
|
||||
adviceCalled++;
|
||||
return callback.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Bar extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
@Override
|
||||
protected Object handleRequestMessage(Message<?> requestMessage) {
|
||||
Exception e = new RuntimeException();
|
||||
StackTraceElement[] st = e.getStackTrace();
|
||||
return MessageBuilder.withPayload(requestMessage.getPayload().toString().toUpperCase())
|
||||
.setHeader("callStack", st);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class BazService {
|
||||
|
||||
public void qux() {
|
||||
bazCalled++;
|
||||
}
|
||||
|
||||
public String upperCase(String input) {
|
||||
return input.toUpperCase();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?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:int-jmx="http://www.springframework.org/schema/integration/jmx"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
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/jmx http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">
|
||||
|
||||
<context:mbean-server/>
|
||||
|
||||
<int-jmx:mbean-export default-domain="transformers" />
|
||||
|
||||
<channel id="input"/>
|
||||
|
||||
<recipient-list-router input-channel="input"> <!-- INT-3565 ClassCastException with DEBUG -->
|
||||
<recipient channel="input1" selector-expression="true" />
|
||||
</recipient-list-router>
|
||||
|
||||
<channel id="output">
|
||||
<queue capacity="50"/>
|
||||
</channel>
|
||||
|
||||
<transformer input-channel="input1" ref="testBean" method="upperCase" output-channel="output">
|
||||
<request-handler-advice-chain>
|
||||
<beans:bean class="org.springframework.integration.monitor.TransformerContextTests$FooAdvice" />
|
||||
</request-handler-advice-chain>
|
||||
</transformer>
|
||||
|
||||
<beans:bean id="testBean" class="org.springframework.integration.monitor.TransformerContextTests$BazService"/>
|
||||
|
||||
<transformer input-channel="direct" output-channel="output">
|
||||
<beans:bean class="org.springframework.integration.monitor.TransformerContextTests$Bar"/>
|
||||
</transformer>
|
||||
|
||||
<transformer input-channel="directRef" output-channel="output" ref="trans" method="handleMessage">
|
||||
<request-handler-advice-chain>
|
||||
<beans:bean class="org.springframework.integration.monitor.TransformerContextTests$FooAdvice" />
|
||||
</request-handler-advice-chain>
|
||||
</transformer>
|
||||
|
||||
<beans:bean id="trans" class="org.springframework.integration.monitor.TransformerContextTests$Bar"/>
|
||||
|
||||
<service-activator input-channel="service" method="qux">
|
||||
<beans:bean class="org.springframework.integration.monitor.TransformerContextTests$BazService" />
|
||||
<request-handler-advice-chain>
|
||||
<beans:bean class="org.springframework.integration.monitor.TransformerContextTests$FooAdvice" />
|
||||
</request-handler-advice-chain>
|
||||
</service-activator>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user