I use camel 2.8.0 with servicemix4.3. I set up a dynamic router by 
camel-context.xml. as follows: 
<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xsi:schemaLocation=" 
       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd";>

    <classpath>
        <library>osgi:org.apache.camel.camel-spring</library>
        <library>osgi:com.hongbo.cobweb.utils</library>
        <library>osgi:com.hongbo.cobweb.store.api</library>
        <library>osgi:com.hongbo.cobweb.store.entity</library>
        <library>osgi:com.hongbo.cobweb.nmr.api</library>
        <library>osgi:com.hongbo.cobweb.resource.manager</library>
        <library>osgi:com.mongodb</library>
    </classpath>

    <bean id="bizTypeDR" 
class="com.hongbo.cobweb.master.router.BizTypeDynamicRouter" init-method="init">
        <property name="gatewayUri" 
value="jbi:service:http://cobweb.hongbo.net.cn/default/master/gateway"; />
        <property name="storeUri" 
value="jbi:service:http://cobweb.hongbo.net.cn/default/master/store"; />
        <property name="storeFactoryName" value="MongoMessageStore" />
    </bean>
        
    <camelContext id="camelContext" 
xmlns="http://camel.apache.org/schema/spring";>
        <route>
            <from 
uri="jbi:service:http://cobweb.hongbo.net.cn/default/master/camel?mep=in-out"; />
            <dynamicRouter>
                <method ref="bizTypeDR" method="route"/>
            </dynamicRouter>
        </route>
    </camelContext>
</beans>

bizTypeDR bean: 
    @DynamicRouter(ignoreInvalidEndpoints=true) 
    public String route(@Header(MessageHeader.CW_MSG_BIZ_TYPE) String bizType, 
Exchange exchange) { 
        // query a database to find the best match of the endpoint based on the 
input parameteres 
        // return the next endpoint uri, where to go. Return null to indicate 
the end. 
        if (started.get()) { 
            if (exchange.hasOut()) { 
                return null; 
            } 
            if (types != null && types.size() > 0 && bizType != null) { 
                WrapperMessageBizType mbt = types.get(bizType); 
                if (mbt != null && mbt.getSaIds() != null && 
mbt.getSaIds().size() > 0) { 
                    
exchange.getIn().setHeader(MessageHeader.CW_INNER_MSG_BIZ_URI, mbt.getUri()); 
                    return gatewayUri; 
                } 
            } 
        } 
        return storeUri; 
    } 

It finish selecting one approach(gatewayUri or storeUri) 

But I debug the camel-su. When (gatewayUri or storeUri) downflow components 
return an exchange with out message(it contains body and headers), camel ignore 
headers and think the body is next uri in BeanExpress. Is it a bug?? Camel 
should return the exchange to upflow component(http) in servicemix. 

BeanExpress code: 
org.apache.camel.language.bean.BeanExpression 
line 161-163 
                resultExchange.setPattern(ExchangePattern.InOut); 
                processor.process(resultExchange); 
                result = resultExchange.getOut().getBody(); 
In line 163, resultExchange is ok. It contains In Message and Out Message 
returned by downflow components in servicemix. The out Message has headers and 
body. but 163, camel bean expression only cares about the body of out message 
and ignore headers of out message. 

How can I use dynamic router in camel. It can return entirely exchange from 
downflow components to upflow component. 

                                                   thank you very much! 


Reply via email to