On Tue, May 3, 2011 at 3:49 PM, Claus Straube <[email protected]> wrote:
> Hi Muhammad,
Ichsan please :D
>
> I think the error must be in your iMessageUtil class. This route works as
> you would expect:
IMHO, I think it's a bug in Camel. Please look at my testing artifacts:
Java code:
====================================================================================
import org.apache.camel.EndpointInject;
import org.apache.camel.Produce;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"/TestRoutingSlipWithJustBean.xml"})
public class TestRoutingSlipWithJustBean {
@EndpointInject(uri = "mock:result")
protected MockEndpoint resultEndpoint;
@Produce(uri = "direct:foo")
protected ProducerTemplate template;
@DirtiesContext
@Test
public void testRoutingSlip() throws Exception {
// Expected: headers contain them
resultEndpoint.expectedHeaderReceived("a", "_a");
resultEndpoint.expectedHeaderReceived("b", "_b");
// When: a message is sent
template.sendBody("Hello");
// Then: we meet the expectation
resultEndpoint.assertIsSatisfied();
}
}
while iMessageUtil methods are:
public void invokeA(Exchange x) {
x.getIn().setHeader("a", "_a");
LOGGER.debug("invokeA is called");
}
public void invokeB(Exchange x) {
x.getIn().setHeader("b", "_b");
LOGGER.debug("invokeB is called");
}
and my context file:
==================
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<bean id="iMessageUtil" class="my.EmptyImpl" />
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:foo" />
<setHeader headerName="routing">
<constant>activemq:a,activemq:b</constant>
</setHeader>
<setExchangePattern pattern="InOut" />
<routingSlip>
<header>routing</header>
</routingSlip>
<to uri="mock:result" />
</route>
<route>
<from uri="activemq:a" />
<to uri="bean:iMessageUtil?method=invokeA" />
<to uri="log:a" /> <!-- IF THIS line is removed, the
test will be failed -->
</route>
<route>
<from uri="activemq:b" />
<to uri="bean:iMessageUtil?method=invokeB" />
<to uri="log:b" /> <!-- IF THIS line is removed, the
test will be failed -->
</route>
</camelContext>
<!-- ActiveMQ component -->
<bean id="activemq" class="org.apache.camel.component.jms.JmsComponent"
p:configuration-ref="jmsConfig" />
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration"
p:connectionFactory-ref="jmsConnectionFactory"
p:transacted="false"
p:concurrentConsumers="50" />
<bean id="jmsConnectionFactory"
class="org.springframework.jms.connection.CachingConnectionFactory"
p:targetConnectionFactory-ref="nakedConnectionFactory"
p:sessionCacheSize="20" />
<bean id="nakedConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="vm://localhost?broker.persistent=false" />
</beans>
Thanks